-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(publish): update release and build scripts to make them work…
…space-friendly (#251)
- Loading branch information
Showing
17 changed files
with
2,864 additions
and
5,629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
src | ||
templates | ||
scripts | ||
node_modules | ||
|
||
tsconfig.* | ||
|
||
dist/*.ts | ||
!dist/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
src | ||
templates | ||
scripts | ||
node_modules | ||
|
||
tsconfig.* | ||
|
||
dist/*.ts | ||
!dist/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,35 @@ | ||
/* eslint-disable no-console */ | ||
import glob from "fast-glob"; | ||
import { exec } from "node:child_process"; | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { promisify } from "node:util"; | ||
import { createMainPackage, createNPMRC } from "../../../scripts/utils"; | ||
import { createModulePackages, getFileMeta } from "../../../scripts/utils"; | ||
|
||
const execCmd = promisify(exec); | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const { dirname } = getFileMeta(import.meta.url); | ||
|
||
const packageDir = path.resolve(__dirname, ".."); | ||
const packageDir = path.resolve(dirname, ".."); | ||
const distPath = path.join(packageDir, "dist"); | ||
|
||
const moduleDirectories = glob | ||
.sync(path.join(distPath, "**/index.js")) | ||
.map(p => path.dirname(p)); | ||
|
||
const doesFileExist = async (filePath: string) => { | ||
try { | ||
await fs.stat(filePath); | ||
|
||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
const transpile = async () => { | ||
console.log("> transpiling..."); | ||
|
||
const configPath = path.resolve(packageDir, "tsconfig.build.json"); | ||
const tsconfigPath = path.resolve(packageDir, "tsconfig.build.json"); | ||
|
||
await execCmd(["shx", "rm", "-rf", distPath].join(" ")); | ||
|
||
const { stderr, stdout } = await execCmd( | ||
["tsc", "--project", configPath].join(" "), | ||
["tsc", "--project", tsconfigPath].join(" "), | ||
); | ||
|
||
if (stdout) console.log(stdout); | ||
if (stderr) console.error(stderr); | ||
}; | ||
|
||
const createModulePackages = async () => { | ||
console.log("> creating module packages..."); | ||
for (const moduleDirectory of moduleDirectories) { | ||
const typesPath = path.join(moduleDirectory, "index.d.ts"); | ||
const typesExist = await doesFileExist(typesPath); | ||
|
||
const packageJsonPath = path.join(moduleDirectory, "package.json"); | ||
|
||
await fs.writeFile( | ||
packageJsonPath, | ||
JSON.stringify( | ||
{ | ||
sideEffects: false, | ||
types: typesExist ? "./index.d.ts" : undefined, | ||
main: "./index.js", | ||
}, | ||
null, | ||
2, | ||
), | ||
); | ||
} | ||
}; | ||
|
||
void (async () => { | ||
console.time("build"); | ||
await transpile(); | ||
await createModulePackages(); | ||
await createMainPackage(packageDir, distPath); | ||
await createNPMRC(distPath); | ||
await createModulePackages(distPath); | ||
console.timeEnd("build"); | ||
})(); | ||
/* eslint-enable no-console */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.