diff --git a/package.json b/package.json index bcd37561..a288857e 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "lint:css": "stylelint **/*.{css,vue}", "test": "cross-env TZ=Etc/UTC vitest --coverage", "prepare": "husky", - "release": "pnpm release:check && pnpm release:version && pnpm -r publish", + "release": "pnpm release:check && pnpm release:version && pnpm -r publish && pnpm release:sync", "release:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "release:check": "pnpm lint && pnpm build", + "release:sync": "node scripts/mirror-sync.mjs", "release:version": "bumpp package.json plugins/*/package.json theme/package.json cli/package.json --execute=\"pnpm release:changelog\" --commit \"build: publish v%s\" --all --tag --push" }, "devDependencies": { @@ -44,6 +45,7 @@ "@pengzhanbo/eslint-config-vue": "^1.18.1", "@pengzhanbo/stylelint-config": "^1.18.1", "@types/lodash.merge": "^4.6.9", + "@types/minimist": "^1.2.5", "@types/node": "20.12.10", "@types/webpack-env": "^1.18.5", "@vitest/coverage-istanbul": "^2.1.2", @@ -58,6 +60,7 @@ "lint-staged": "^15.2.10", "markdown-it": "^14.1.0", "memfs": "^4.14.0", + "minimist": "^1.2.8", "rimraf": "^6.0.1", "stylelint": "^16.10.0", "tsconfig-vuepress": "^5.2.0", diff --git a/plugins/plugin-content-update/tsup.config.ts b/plugins/plugin-content-update/tsup.config.ts index 54e96623..ba6b00b2 100644 --- a/plugins/plugin-content-update/tsup.config.ts +++ b/plugins/plugin-content-update/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig, type Options } from 'tsup' +import { argv } from '../../scripts/tsup-args.js' const clientExternal: (string | RegExp)[] = [ /.*\.vue$/, @@ -12,42 +13,49 @@ export default defineConfig(() => { splitting: false, format: 'esm', } - return [ - // node - { + + const options: Options[] = [] + + if (argv.node) { + options.push({ ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', target: 'node18', - }, - // client/composables/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/composables/index.ts'], - outDir: './lib/client/composables', - external: clientExternal, - }, - // client/components/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/components/Content.ts'], - outDir: './lib/client/components', - external: [...clientExternal, '../composables/index.js'], - }, - // client/config.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/config.ts'], - outDir: './lib/client', - dts: false, - external: [...clientExternal, './components/Content.js'], - }, - // client/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/index.ts'], - outDir: './lib/client', - external: [...clientExternal, './components/Content.js', './composables/index.js'], - }, - ] + }) + } + if (argv.client) { + options.push(...[ + // client/composables/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/composables/index.ts'], + outDir: './lib/client/composables', + external: clientExternal, + }, + // client/components/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/components/Content.ts'], + outDir: './lib/client/components', + external: [...clientExternal, '../composables/index.js'], + }, + // client/config.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/config.ts'], + outDir: './lib/client', + dts: false, + external: [...clientExternal, './components/Content.js'], + }, + // client/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/index.ts'], + outDir: './lib/client', + external: [...clientExternal, './components/Content.js', './composables/index.js'], + }, + ]) + } + return options }) diff --git a/plugins/plugin-fonts/tsup.config.ts b/plugins/plugin-fonts/tsup.config.ts index 8391a704..7f1800a0 100644 --- a/plugins/plugin-fonts/tsup.config.ts +++ b/plugins/plugin-fonts/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig, type Options } from 'tsup' +import { argv } from '../../scripts/tsup-args.js' const clientExternal: (string | RegExp)[] = [ /.*\.vue$/, @@ -12,21 +13,28 @@ export default defineConfig(() => { splitting: false, format: 'esm', } - return [ - // node - { + const options: Options[] = [] + + if (argv.node) { + options.push({ ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', target: 'node18', - }, - // client/config.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/config.ts'], - outDir: './lib/client', - dts: false, - external: clientExternal, - }, - ] + }) + } + + if (argv.client) { + options.push(...[ + // client/config.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/config.ts'], + outDir: './lib/client', + dts: false, + external: clientExternal, + }, + ]) + } + return options }) diff --git a/plugins/plugin-md-power/tsup.config.ts b/plugins/plugin-md-power/tsup.config.ts index 76748ca5..1cdc24d6 100644 --- a/plugins/plugin-md-power/tsup.config.ts +++ b/plugins/plugin-md-power/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig, type Options } from 'tsup' +import { argv } from '../../scripts/tsup-args.js' const config = [ { dir: 'composables', files: ['codeRepl.ts', 'pdf.ts', 'rustRepl.ts', 'size.ts'] }, @@ -20,27 +21,32 @@ export default defineConfig(() => { splitting: false, format: 'esm', } - return [ - // shared - { - ...DEFAULT_OPTIONS, - entry: ['./src/shared/index.ts'], - outDir: './lib/shared', - }, - // node - { + const options: Options[] = [] + + // shared + options.push({ + ...DEFAULT_OPTIONS, + entry: ['./src/shared/index.ts'], + outDir: './lib/shared', + }) + + if (argv.node) { + options.push({ ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', target: 'node18', external: ['markdown-it', /^@?vuepress/], - }, - // client - ...config.map(({ dir, files }) => ({ + }) + } + + if (argv.client) { + options.push(...config.map(({ dir, files }) => ({ ...DEFAULT_OPTIONS, entry: files.map(file => `./src/client/${dir}/${file}`), outDir: `./lib/client/${dir}`, external: clientExternal, - }) as Options), - ] + }) as Options)) + } + return options }) diff --git a/plugins/plugin-search/tsup.config.ts b/plugins/plugin-search/tsup.config.ts index 4966b594..fbe82069 100644 --- a/plugins/plugin-search/tsup.config.ts +++ b/plugins/plugin-search/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig, type Options } from 'tsup' +import { argv } from '../../scripts/tsup-args.js' const sharedExternal: (string | RegExp)[] = [ /.*\/shared\/index\.js$/, @@ -18,52 +19,62 @@ export default defineConfig(() => { splitting: false, format: 'esm', } - return [ - // shared - { - ...DEFAULT_OPTIONS, - entry: ['./src/shared/index.ts'], - outDir: './lib/shared', - }, - // node - { + + const options: Options[] = [] + + // shared + options.push({ + ...DEFAULT_OPTIONS, + entry: ['./src/shared/index.ts'], + outDir: './lib/shared', + }) + + if (argv.node) { + options.push({ ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', external: sharedExternal, target: 'node18', - }, - // client/utils/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/utils/index.ts'], - outDir: './lib/client/utils', - external: clientExternal, - }, - // client/composables/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/composables/index.ts'], - outDir: './lib/client/composables', - external: clientExternal, - }, - // client/config.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/config.ts'], - outDir: './lib/client', - external: clientExternal, - dts: false, - }, - // client/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/index.ts'], - outDir: './lib/client', - external: [ - ...clientExternal, - './composables/index.js', - ], - }, - ] + }) + } + + if (argv.client) { + options.push(...[ + // client/utils/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/utils/index.ts'], + outDir: './lib/client/utils', + external: clientExternal, + }, + // client/composables/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/composables/index.ts'], + outDir: './lib/client/composables', + external: clientExternal, + }, + // client/config.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/config.ts'], + outDir: './lib/client', + external: clientExternal, + dts: false, + }, + // client/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/index.ts'], + outDir: './lib/client', + external: [ + ...clientExternal, + './composables/index.js', + ], + }, + ]) + } + + return options }) diff --git a/plugins/plugin-shikiji/tsup.config.ts b/plugins/plugin-shikiji/tsup.config.ts index 2612fbe4..51ab0dbb 100644 --- a/plugins/plugin-shikiji/tsup.config.ts +++ b/plugins/plugin-shikiji/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig, type Options } from 'tsup' +import { argv } from '../../scripts/tsup-args.js' export default defineConfig(() => { const DEFAULT_OPTIONS: Options = { @@ -7,24 +8,31 @@ export default defineConfig(() => { splitting: false, format: 'esm', } - return [ - // node - { + + const options: Options[] = [] + + if (argv.node) { + options.push({ ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', target: 'node18', - }, - // client/composables/ - { - ...DEFAULT_OPTIONS, - entry: [ - 'copy-code.ts', - 'twoslash.ts', - 'collapsed-lines.ts', - ].map(file => `./src/client/composables/${file}`), - outDir: './lib/client/composables', - external: [/.*\.css$/], - }, - ] + }) + } + if (argv.client) { + options.push(...[ + // client/composables/ + { + ...DEFAULT_OPTIONS, + entry: [ + 'copy-code.ts', + 'twoslash.ts', + 'collapsed-lines.ts', + ].map(file => `./src/client/composables/${file}`), + outDir: './lib/client/composables', + external: [/.*\.css$/], + }, + ]) + } + return options }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5144781..67d0d5a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: '@types/lodash.merge': specifier: ^4.6.9 version: 4.6.9 + '@types/minimist': + specifier: ^1.2.5 + version: 1.2.5 '@types/node': specifier: 20.12.10 version: 20.12.10 @@ -68,6 +71,9 @@ importers: memfs: specifier: ^4.14.0 version: 4.14.0 + minimist: + specifier: ^1.2.8 + version: 1.2.8 rimraf: specifier: ^6.0.1 version: 6.0.1 @@ -477,6 +483,9 @@ packages: peerDependencies: '@algolia/client-search': '>= 4.9.1 < 6' algoliasearch: '>= 4.9.1 < 6' + peerDependenciesMeta: + '@algolia/client-search': + optional: true '@algolia/cache-browser-local-storage@4.24.0': resolution: {integrity: sha512-t63W9BnoXVrGy9iYHBgObNXqYXM3tYXCjDSHeNwnsc324r4o5UiVKUiAB4THQ5z9U5hTj6qUvwg/Ez43ZD85ww==} @@ -1737,6 +1746,9 @@ packages: '@types/mime@1.3.5': resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==} + '@types/minimist@1.2.5': + resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} + '@types/ms@0.7.34': resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==} @@ -6204,8 +6216,9 @@ snapshots: '@algolia/autocomplete-shared@1.9.3(@algolia/client-search@4.24.0)(algoliasearch@4.24.0)': dependencies: - '@algolia/client-search': 4.24.0 algoliasearch: 4.24.0 + optionalDependencies: + '@algolia/client-search': 4.24.0 '@algolia/cache-browser-local-storage@4.24.0': dependencies: @@ -7446,6 +7459,8 @@ snapshots: '@types/mime@1.3.5': {} + '@types/minimist@1.2.5': {} + '@types/ms@0.7.34': {} '@types/node@17.0.45': {} diff --git a/scripts/mirror-sync.mjs b/scripts/mirror-sync.mjs new file mode 100644 index 00000000..f48b8a36 --- /dev/null +++ b/scripts/mirror-sync.mjs @@ -0,0 +1,52 @@ +import fs from 'node:fs' +import { request } from 'node:https' +import path from 'node:path' +import process from 'node:process' +import { URL } from 'node:url' + +const pluginsDir = path.resolve(process.cwd(), 'plugins') +const plugins = fs.readdirSync(pluginsDir) + +async function npmMirrorSync() { + const packages = [ + 'create-vuepress-theme-plume', + 'vuepress-theme-plume', + ] + for (const plugin of plugins) { + if (fs.statSync(path.resolve(pluginsDir, plugin)).isDirectory()) { + const { name } = JSON.parse(fs.readFileSync(path.resolve(pluginsDir, plugin, 'package.json'), 'utf-8')) + packages.push(name) + } + } + return Promise.all(packages.map(async (pkg) => { + const url = new URL(`https://registry-direct.npmmirror.com/${pkg}/sync?sync_upstream=true`) + return new Promise((resolve, reject) => { + const req = request(url, { + method: 'PUT', + headers: { + 'Content-Length': 0, + }, + }) + req.write('') + + req.on('close', () => { + resolve() + }) + + req.on('error', (error) => { + reject(error) + }) + + req.end() + }) + })) +} + +try { + await npmMirrorSync() + console.log('npm mirror sync success !') +} +catch (error) { + console.error(error) + process.exit(1) +} diff --git a/scripts/tsup-args.ts b/scripts/tsup-args.ts new file mode 100644 index 00000000..89100fad --- /dev/null +++ b/scripts/tsup-args.ts @@ -0,0 +1,30 @@ +import process from 'node:process' +import minimist from 'minimist' + +interface ArgvOptions { + client: boolean + node: boolean +} + +const rawArgv = process.argv.slice(2) +const tsupArgv = rawArgv.includes('--') ? rawArgv.slice(rawArgv.indexOf('--') + 1) : [] + +const parsed = tsupArgv.length + ? minimist(tsupArgv, { + boolean: ['client', 'node', 'all'], + alias: { + client: 'c', + node: 'n', + all: 'a', + }, + }) + : { + client: true, + node: true, + all: true, + } + +export const argv: ArgvOptions = { + client: parsed.client || parsed.all, + node: parsed.node || parsed.all, +} diff --git a/theme/package.json b/theme/package.json index 37bdd0e4..c95a3f78 100644 --- a/theme/package.json +++ b/theme/package.json @@ -59,7 +59,7 @@ "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png,woff2}\" lib", "copy:watch": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png,woff2}\" lib -w", "tsup": "tsup --config tsup.config.ts", - "tsup:watch": "tsup --config tsup.config.ts --watch" + "tsup:watch": "tsup --config tsup.config.ts --watch -- -c -s" }, "peerDependencies": { "@iconify/json": "^2", diff --git a/theme/tsup.config.ts b/theme/tsup.config.ts index e35a6663..4bd0551b 100644 --- a/theme/tsup.config.ts +++ b/theme/tsup.config.ts @@ -2,6 +2,7 @@ import fs from 'node:fs' import path from 'node:path' import process from 'node:process' import { defineConfig, type Options } from 'tsup' +import { argv } from '../scripts/tsup-args.js' const sharedExternal: (string | RegExp)[] = [ /.*\/shared\/index\.js$/, @@ -28,74 +29,81 @@ export default defineConfig((cli) => { format: 'esm', silent: !!cli.watch, } - return [ - // shared - { - ...DEFAULT_OPTIONS, - entry: ['./src/shared/index.ts'], - outDir: './lib/shared', - dts: true, - }, - // node - { + const options: Options[] = [] + + // shared + options.push({ + ...DEFAULT_OPTIONS, + entry: ['./src/shared/index.ts'], + outDir: './lib/shared', + dts: true, + }) + + if (argv.node) { + options.push({ ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', external: sharedExternal, target: 'node18', watch: false, - }, - // client/utils/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/utils/index.ts'], - outDir: './lib/client/utils', - external: clientExternal, - }, - // client/composables/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/composables/index.ts'], - outDir: './lib/client/composables', - external: [ - ...clientExternal, - '../utils/index.js', - ], - }, - // client/config.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/config.ts'], - outDir: './lib/client', - dts: false, - external: [ - ...clientExternal, - './composables/index.js', - './utils/index.js', - ], - }, - // client/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/index.ts'], - outDir: './lib/client', - external: [ - ...clientExternal, - './composables/index.js', - './utils/index.js', - './config.js', - ], - }, - ...featuresComposables.map(file => ({ - ...DEFAULT_OPTIONS, - entry: [`./src/client/features/composables/${file}`], - outDir: `./lib/client/features/composables/`, - external: [ - ...clientExternal, - '../../composables/index.js', - '../../utils/index.js', - ...featuresComposables.map(file => `./${file.replace('.ts', '.js')}`), - ], - })), - ] + }) + } + if (argv.client) { + options.push(...[ + // client/utils/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/utils/index.ts'], + outDir: './lib/client/utils', + external: clientExternal, + }, + // client/composables/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/composables/index.ts'], + outDir: './lib/client/composables', + external: [ + ...clientExternal, + '../utils/index.js', + ], + }, + // client/config.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/config.ts'], + outDir: './lib/client', + dts: false, + external: [ + ...clientExternal, + './composables/index.js', + './utils/index.js', + ], + }, + // client/index.js + { + ...DEFAULT_OPTIONS, + entry: ['./src/client/index.ts'], + outDir: './lib/client', + external: [ + ...clientExternal, + './composables/index.js', + './utils/index.js', + './config.js', + ], + }, + ...featuresComposables.map(file => ({ + ...DEFAULT_OPTIONS, + entry: [`./src/client/features/composables/${file}`], + outDir: `./lib/client/features/composables/`, + external: [ + ...clientExternal, + '../../composables/index.js', + '../../utils/index.js', + ...featuresComposables.map(file => `./${file.replace('.ts', '.js')}`), + ], + })), + ]) + } + return options })