diff --git a/package.json b/package.json index b5fe330..9798f7d 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "docs:serve": "vitepress serve docs", "ci:version": "changeset version && pnpm install --no-frozen-lockfile && git add .", "ci:publish": "pnpm build:all && pnpm changeset publish", - "postinstall": "ts-node -P scripts/tsconfig.script.json scripts/postinstall.ts" + "remind": "ts-node -P scripts/tsconfig.script.json scripts/postinstall-reminder.ts", + "postinstall": "ts-node -P scripts/tsconfig.script.json scripts/cli.ts cache && pnpm remind" }, "repository": { "type": "git", diff --git a/scripts/cache-package.ts b/scripts/cache-package.ts new file mode 100644 index 0000000..7733c97 --- /dev/null +++ b/scripts/cache-package.ts @@ -0,0 +1,37 @@ +import { CAC } from 'cac'; +import fs from 'fs-extra'; +import enquirer from 'enquirer'; + +import chalk from 'chalk'; +import { CLIUtils } from './utils'; +import consola from 'consola'; + +export default function useCachePackage(cli: CAC) { + cli + .command('cache', 'cache current workspace packages to cache directory') + .action(async () => { + fs.ensureDirSync(CLIUtils.resolvedPackageRootDir); + const existPackages = CLIUtils.existPackages; + + for (const p of existPackages) { + const projectSrcPath = CLIUtils.resolvePackageDir(p); + + const projectDestPath = CLIUtils.resolveCachePackageDir(p); + + if (fs.existsSync(projectDestPath)) continue; + + fs.copySync(projectSrcPath, projectDestPath, { + recursive: true, + filter: (src, dest) => { + const filtered = ['node_modules', 'dist', 'tmp'].every( + (pattern) => !src.includes(pattern) + ); + + return filtered; + }, + }); + + consola.success(`Package ${chalk.green(p)} cached.`); + } + }); +} diff --git a/scripts/cli.ts b/scripts/cli.ts index d5bdd8e..3d03e8c 100644 --- a/scripts/cli.ts +++ b/scripts/cli.ts @@ -7,6 +7,7 @@ import useInitWorkspaceAfterInstall from './init-workspace'; import useResetWorkspacePackages from './reset-workspace'; import useCreateSimplePackage from './create-package'; import useCopyPackage from './copy-package'; +import useCachePackage from './cache-package'; const cli = cac('LinbuduLab-Starter'); @@ -18,6 +19,7 @@ useInitWorkspaceAfterInstall(cli); useResetWorkspacePackages(cli); useCreateSimplePackage(cli); useCopyPackage(cli); +useCachePackage(cli); cli.help(); cli.parse(); diff --git a/scripts/hooks.ts b/scripts/hooks.ts index 2a7a175..4cbb2c1 100644 --- a/scripts/hooks.ts +++ b/scripts/hooks.ts @@ -1,30 +1,5 @@ -import fs from 'fs-extra'; -import path from 'path'; - -import { CLIUtils, Constants } from './utils'; - export class CLIHooks { - public static pre() { - fs.ensureDirSync(CLIUtils.resolvedPackageRootDir); - const existPackages = CLIUtils.existPackages; - - for (const p of existPackages.slice(0)) { - const projectSrcPath = CLIUtils.resolvePackageDir(p); - - const projectDestPath = CLIUtils.resolveCachePackageDir(p); - - if (fs.existsSync(projectDestPath)) continue; - - fs.copySync(projectSrcPath, projectDestPath, { - recursive: true, - filter: (src, dest) => { - const filtered = ['node_modules', 'dist', 'tmp'].every( - (pattern) => !src.includes(pattern) - ); + public static pre() {} - return filtered; - }, - }); - } - } + public static post() {} } diff --git a/scripts/postinstall.ts b/scripts/postinstall-reminder.ts similarity index 71% rename from scripts/postinstall.ts rename to scripts/postinstall-reminder.ts index addc112..e0554d7 100644 --- a/scripts/postinstall.ts +++ b/scripts/postinstall-reminder.ts @@ -4,6 +4,6 @@ import consola from 'consola'; console.log(''); consola.success( `Your workspace has been successfully created, now run ${chalk.bold.cyan( - '\n\npnpm cli init\n\n' - )}to initialize workspace projects!` + '>>> pnpm cli init <<<' + )} to initialize workspace projects!` );