Skip to content

Commit 3f42c38

Browse files
committed
🔧 chore: fix scripts
1 parent ba63623 commit 3f42c38

File tree

4 files changed

+152
-17
lines changed

4 files changed

+152
-17
lines changed

rollup.config.cli.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import fs from 'node:fs/promises'
1111

1212
const externals = new Set([
1313
...builtinExternalSet,
14+
'@guanghechen/cli',
1415
'@guanghechen/chalk',
1516
'@guanghechen/chalk/node',
17+
'@guanghechen/exec',
1618
'@guanghechen/fs',
1719
'@guanghechen/file-split',
1820
'@guanghechen/filepart',

script/deps.mts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import url from 'node:url'
4+
5+
const __dirname: string = path.dirname(url.fileURLToPath(import.meta.url))
6+
const WORKSPACE_ROOT: string = path.resolve(__dirname, '..')
7+
8+
const tsconfig = await import(path.resolve(WORKSPACE_ROOT, 'tsconfig.json'), {
9+
assert: { type: 'json' },
10+
}).then(md => md.default)
11+
const internals: Set<string> = new Set<string>(Object.keys(tsconfig.compilerOptions.paths))
12+
13+
const packageJsonFilePaths: string[] = fs
14+
.readdirSync(path.resolve(WORKSPACE_ROOT, 'packages'))
15+
.map(p => path.resolve(WORKSPACE_ROOT, 'packages', p, 'package.json'))
16+
.filter(p => fs.existsSync(p) && fs.statSync(p).isFile())
17+
18+
const dependencies: Set<string> = new Set<string>()
19+
const devDependencies: Set<string> = new Set<string>()
20+
21+
for (const packageJsonFilePath of packageJsonFilePaths) {
22+
const packageJson = await import(packageJsonFilePath, { assert: { type: 'json' } }).then(
23+
md => md.default,
24+
)
25+
const rawDependencies: Record<string, string> = packageJson.dependencies ?? {}
26+
for (const [key, value] of Object.entries(rawDependencies)) {
27+
if (internals.has(key)) continue
28+
dependencies.add(key + '@' + value)
29+
}
30+
31+
const rawDevDependencies: Record<string, string> = packageJson.devDependencies ?? {}
32+
for (const [key, value] of Object.entries(rawDevDependencies)) {
33+
if (internals.has(key)) continue
34+
devDependencies.add(key + '@' + value)
35+
}
36+
}
37+
38+
console.log('dependencies:', Array.from(dependencies).sort())
39+
console.log('devDependencies:', Array.from(devDependencies).sort())

script/projects.mts

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import url from 'node:url'
4+
5+
const __dirname: string = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..')
6+
7+
const workspaceNames: string[] = ['packages']
8+
for (const workspaceName of workspaceNames) {
9+
const packagesDir: string = path.resolve(__dirname, workspaceName)
10+
if (!fs.existsSync(packagesDir) || !fs.statSync(packagesDir).isDirectory()) continue
11+
12+
const packageNames: string[] = fs.readdirSync(packagesDir)
13+
for (const packageName of packageNames) {
14+
const projectPath: string = path.resolve(packagesDir, packageName, 'project.json')
15+
if (fs.existsSync(projectPath) && !fs.statSync(projectPath).isFile()) continue
16+
17+
const testsPath: string = path.resolve(packagesDir, packageName, '__test__')
18+
const hasTests: boolean = fs.existsSync(testsPath) && fs.statSync(testsPath).isDirectory()
19+
20+
const isTool: boolean = /^tool-|-tool$/.test(packageName)
21+
const content: string = genProjectJSON({ workspaceName, packageName, hasTests, isTool })
22+
fs.writeFileSync(projectPath, content, 'utf8')
23+
}
24+
}
25+
26+
function genProjectJSON(data: {
27+
workspaceName: string
28+
packageName: string
29+
hasTests: boolean
30+
isTool: boolean
31+
}): string {
32+
const { workspaceName, packageName, hasTests, isTool } = data
33+
const rollupConfigFilename: string = isTool ? 'rollup.config.cli.mjs' : 'rollup.config.mjs'
34+
const cwd: string = `${workspaceName}/${packageName}`
35+
const sourceRoot: string = `${cwd}/src`
36+
37+
const json = {
38+
$schema: '../../node_modules/nx/schemas/project-schema.json',
39+
name: packageName,
40+
sourceRoot,
41+
projectType: 'library',
42+
tags: [],
43+
targets: {
44+
clean: {
45+
executor: 'nx:run-commands',
46+
options: {
47+
cwd,
48+
parallel: false,
49+
commands: ['rimraf lib'],
50+
},
51+
},
52+
build: {
53+
executor: 'nx:run-commands',
54+
dependsOn: ['clean', '^build'],
55+
options: {
56+
cwd,
57+
parallel: false,
58+
commands: [`rollup -c ../../${rollupConfigFilename}`],
59+
env: {
60+
NODE_ENV: 'production',
61+
ROLLUP_SHOULD_SOURCEMAP: 'true',
62+
},
63+
},
64+
configurations: {
65+
production: {
66+
env: {
67+
NODE_ENV: 'production',
68+
ROLLUP_SHOULD_SOURCEMAP: 'false',
69+
},
70+
},
71+
},
72+
},
73+
watch: {
74+
executor: 'nx:run-commands',
75+
options: {
76+
cwd,
77+
parallel: false,
78+
commands: [`rollup -c ../../${rollupConfigFilename} -w`],
79+
env: {
80+
NODE_ENV: 'development',
81+
ROLLUP_SHOULD_SOURCEMAP: 'true',
82+
},
83+
},
84+
},
85+
test: hasTests
86+
? {
87+
executor: 'nx:run-commands',
88+
options: {
89+
cwd,
90+
commands: [
91+
'node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir .',
92+
],
93+
},
94+
configurations: {
95+
coverage: {
96+
commands: [
97+
'node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir . --coverage',
98+
],
99+
},
100+
update: {
101+
commands: [
102+
'node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir . -u',
103+
],
104+
},
105+
},
106+
}
107+
: undefined,
108+
},
109+
}
110+
return JSON.stringify(json, null, 2)
111+
}

script/sync-project.mjs

-17
This file was deleted.

0 commit comments

Comments
 (0)