From 8f49ccee8c96075763619788f09f49e4859f5412 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Wed, 28 Feb 2024 14:06:27 +0800 Subject: [PATCH] feat: support handle pkg-plugin-dev (#635) --- packages/create-pkg/CHANGELOG.md | 4 +++ packages/create-pkg/package.json | 3 +- packages/create-pkg/src/index.mts | 19 +++++++++++ pnpm-lock.yaml | 52 +++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/packages/create-pkg/CHANGELOG.md b/packages/create-pkg/CHANGELOG.md index cc0ec91e..bfc16ecc 100644 --- a/packages/create-pkg/CHANGELOG.md +++ b/packages/create-pkg/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.3.3 + +- feat: support handle pkg-plugin-dev + ## 1.3.2 ### Patch Changes diff --git a/packages/create-pkg/package.json b/packages/create-pkg/package.json index f725e907..df9480f5 100644 --- a/packages/create-pkg/package.json +++ b/packages/create-pkg/package.json @@ -1,6 +1,6 @@ { "name": "@ice/create-pkg", - "version": "1.3.2", + "version": "1.3.3", "description": "npm init @ice/pkg", "type": "module", "exports": "./lib/index.mjs", @@ -36,6 +36,7 @@ "cac": "^6.7.12", "consola": "^2.15.3", "fs-extra": "^10.0.0", + "globby": "^14.0.1", "ice-npm-utils": "^3.0.2", "inquirer": "^8.2.1", "os-locale": "^6.0.2", diff --git a/packages/create-pkg/src/index.mts b/packages/create-pkg/src/index.mts index 593f817d..364f4853 100644 --- a/packages/create-pkg/src/index.mts +++ b/packages/create-pkg/src/index.mts @@ -1,6 +1,8 @@ #!/usr/bin/env node import { fileURLToPath } from 'url'; +import { checkAliInternal } from 'ice-npm-utils'; +import { globby } from 'globby'; import consola from 'consola'; import { cac } from 'cac'; import fs from 'fs-extra'; @@ -55,6 +57,8 @@ interface CliOptions { async function create(dirPath: string, dirname: string, options: CliOptions): Promise { const info = await getInfo(); + const isInternal = await checkAliInternal(); + await fs.ensureDir(dirPath); const empty = await checkEmpty(dirPath); @@ -85,6 +89,7 @@ async function create(dirPath: string, dirname: string, options: CliOptions): Pr npmName, // @ts-expect-error generateMaterial should support index signature. workspace: options.workspace, + internal: isInternal, }, materialTemplateDir: tempDir, materialType: 'component', @@ -97,6 +102,20 @@ async function create(dirPath: string, dirname: string, options: CliOptions): Pr await removeFilesAndContent(dirPath); } + if (isInternal) { + const docsDirectories = await globby('**/docs', { + cwd: dirPath, + onlyFiles: false, + }); + await Promise.all(docsDirectories.map((doc) => fs.remove(path.join(dirPath, doc)))); + } else { + const devDirectories = await globby('**/dev', { + cwd: dirPath, + onlyFiles: false, + }); + await Promise.all(devDirectories.map((dev) => fs.remove(path.join(dirPath, dev)))); + } + console.log(); console.log(info.initSuccess); console.log(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e12203a2..429e4ae2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -289,6 +289,9 @@ importers: fs-extra: specifier: ^10.0.0 version: 10.1.0 + globby: + specifier: ^14.0.1 + version: 14.0.1 ice-npm-utils: specifier: ^3.0.2 version: link:../ice-npm-utils @@ -6744,6 +6747,11 @@ packages: resolution: {integrity: sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==} engines: {node: '>=6'} + /@sindresorhus/merge-streams@2.3.0: + resolution: {integrity: sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==} + engines: {node: '>=18'} + dev: false + /@sinonjs/commons@1.8.6: resolution: {integrity: sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==} dependencies: @@ -9367,6 +9375,7 @@ packages: loose-envify: 1.4.0 object-assign: 4.1.1 dev: false + bundledDependencies: false /create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} @@ -11077,6 +11086,17 @@ packages: merge2: 1.4.1 micromatch: 4.0.5 + /fast-glob@3.3.2: + resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} + engines: {node: '>=8.6.0'} + dependencies: + '@nodelib/fs.stat': 2.0.5 + '@nodelib/fs.walk': 1.2.8 + glob-parent: 5.1.2 + merge2: 1.4.1 + micromatch: 4.0.5 + dev: false + /fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -11643,6 +11663,18 @@ packages: merge2: 1.4.1 slash: 4.0.0 + /globby@14.0.1: + resolution: {integrity: sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==} + engines: {node: '>=18'} + dependencies: + '@sindresorhus/merge-streams': 2.3.0 + fast-glob: 3.3.2 + ignore: 5.3.1 + path-type: 5.0.0 + slash: 5.1.0 + unicorn-magic: 0.1.0 + dev: false + /globjoin@0.1.4: resolution: {integrity: sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==} dev: true @@ -12120,6 +12152,11 @@ packages: resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==} engines: {node: '>= 4'} + /ignore@5.3.1: + resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==} + engines: {node: '>= 4'} + dev: false + /image-size@0.5.5: resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==} engines: {node: '>=0.10.0'} @@ -15458,6 +15495,11 @@ packages: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} + /path-type@5.0.0: + resolution: {integrity: sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==} + engines: {node: '>=12'} + dev: false + /pathe@1.1.0: resolution: {integrity: sha512-ODbEPR0KKHqECXW1GoxdDb+AZvULmXjVPy4rt+pGo2+TnjJTIPJQSVS6N63n8T2Ip+syHhbn52OewKicV0373w==} @@ -17796,6 +17838,11 @@ packages: resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} engines: {node: '>=12'} + /slash@5.1.0: + resolution: {integrity: sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==} + engines: {node: '>=14.16'} + dev: false + /slice-ansi@4.0.0: resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} engines: {node: '>=10'} @@ -18869,6 +18916,11 @@ packages: resolution: {integrity: sha512-5Zfuy9q/DFr4tfO7ZPeVXb1aPoeQSdeFMLpYuFebehDAhbuevLs5yxSZmIFN1tP5F9Wl4IpJrYojg85/zgyZHQ==} engines: {node: '>=4'} + /unicorn-magic@0.1.0: + resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} + engines: {node: '>=18'} + dev: false + /unified@10.1.2: resolution: {integrity: sha512-pUSWAi/RAnVy1Pif2kAoeWNBa3JVrx0MId2LASj8G+7AiHWoKZNTomq6LG326T68U7/e263X6fTdcXIy7XnF7Q==} dependencies: