From b4f37fb6dc09a9a2eaf45865f6c050ac642dc8b8 Mon Sep 17 00:00:00 2001 From: terwer Date: Thu, 30 Mar 2023 16:05:34 +0800 Subject: [PATCH] feat: Download project template from zhi-ts-template --- package.json | 3 +- packages/zhi-cli/package.json | 2 +- packages/zhi-cli/src/lib/init/commnd.ts | 14 +-- packages/zhi-cli/src/lib/init/download.ts | 13 +-- packages/zhi-cli/src/lib/init/modify.ts | 12 +-- packages/zhi-cli/vite.config.ts | 2 +- pnpm-lock.yaml | 118 ++-------------------- 7 files changed, 31 insertions(+), 133 deletions(-) diff --git a/package.json b/package.json index f120fae8..c3fafea1 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "git-clone": "^0.2.0", "handlebars": "^4.7.7", "loglevel": "^1.8.1", - "loglevel-plugin-prefix": "^0.8.4", - "ora": "^6.1.2" + "loglevel-plugin-prefix": "^0.8.4" } } diff --git a/packages/zhi-cli/package.json b/packages/zhi-cli/package.json index c20ecb6b..236918c0 100644 --- a/packages/zhi-cli/package.json +++ b/packages/zhi-cli/package.json @@ -1,6 +1,6 @@ { "name": "zhi-cli", - "version": "1.2.1", + "version": "1.2.2", "type": "module", "description": "a tool for generating zhi framework related projects", "repository": "terwer/zhi", diff --git a/packages/zhi-cli/src/lib/init/commnd.ts b/packages/zhi-cli/src/lib/init/commnd.ts index b7ebcc88..5862ff70 100644 --- a/packages/zhi-cli/src/lib/init/commnd.ts +++ b/packages/zhi-cli/src/lib/init/commnd.ts @@ -28,8 +28,8 @@ import { printVerboseHook } from "../utils" import LogFactory, { LogLevelEnum } from "zhi-log" import fs from "fs-extra" import path from "path" -// import { downloadTemplate } from "./download" -// import { modifyPackageJson } from "./modify" +import { downloadTemplate } from "./download" +import { modifyPackageJson } from "./modify" import { prompt } from "enquirer" import Select from "enquirer/lib/prompts/select" @@ -58,16 +58,18 @@ export const initCommand = () => { logger.info("start init zhi project:", name) logger.info("using template:", branch) + const description = "please input project description" + const author = "please input author" const projectOptions = await prompt([ { type: "input", name: "description", - message: "please input project description", + message: description, }, { type: "input", name: "author", - message: "please input author", + message: author, }, ]) @@ -82,8 +84,8 @@ export const initCommand = () => { } // 系在仓库并替换参数 - // await downloadTemplate(templateGitUrl, downloadPath, branch) - // modifyPackageJson(downloadPath, { name, ...initOptions }) + await downloadTemplate(templateGitUrl, downloadPath, branch) + modifyPackageJson(downloadPath, { name, description, author }) // 删除git信息 fs.removeSync(path.join(downloadPath, ".git")) diff --git a/packages/zhi-cli/src/lib/init/download.ts b/packages/zhi-cli/src/lib/init/download.ts index 6c12ce39..6421b70e 100644 --- a/packages/zhi-cli/src/lib/init/download.ts +++ b/packages/zhi-cli/src/lib/init/download.ts @@ -1,31 +1,26 @@ import gitclone from "git-clone/promise" -import ora from "ora" import LogFactory, { LogLevelEnum } from "zhi-log" const logger = LogFactory.customLogFactory(LogLevelEnum.LOG_LEVEL_INFO, "zhi-cli").getLogger("init:download") export const downloadTemplate = (templateGitUrl: string, downloadPath: string, branch: string) => { - const loading = ora("download template") + logger.info("download template") return new Promise((resolve, reject) => { logger.info("prepare to checkout templateGitUrl=>", templateGitUrl) logger.info("prepare to checkout downloadPath=>", downloadPath) logger.info("prepare to checkout branch=>", branch) - loading.start("start download template") + logger.info("start download template ...") gitclone(templateGitUrl, downloadPath, { checkout: branch, shallow: false, }) .then((r: any) => { - loading.succeed("download success") - loading.stop() - + logger.info("download success") resolve("download success") }) .catch((error: any) => { - loading.stop() - loading.fail("download fail") - + logger.error("download fail") reject(error) }) }) diff --git a/packages/zhi-cli/src/lib/init/modify.ts b/packages/zhi-cli/src/lib/init/modify.ts index 4cafc7a8..be4d7d6b 100644 --- a/packages/zhi-cli/src/lib/init/modify.ts +++ b/packages/zhi-cli/src/lib/init/modify.ts @@ -1,13 +1,13 @@ import fs from "fs-extra" import path from "path" import handlebars from "handlebars" -import ora from "ora" +import LogFactory, { LogLevelEnum } from "zhi-log" -const log = ora("modify") +const logger = LogFactory.customLogFactory(LogLevelEnum.LOG_LEVEL_INFO, "zhi-cli").getLogger("init:modify") export const modifyPackageJson = function (downloadPath: string, options: any) { const packagePath = path.join(downloadPath, "package.json") - log.start("start modifying package.json") + logger.info("start modifying package.json ...") if (fs.existsSync(packagePath)) { const content = fs.readFileSync(packagePath).toString() const template = handlebars.compile(content) @@ -20,11 +20,9 @@ export const modifyPackageJson = function (downloadPath: string, options: any) { const result = template(param) fs.writeFileSync(packagePath, result) - log.stop() - log.succeed("modify package.json complate") + logger.info("modify package.json complete") } else { - log.stop() - log.fail("modify package.json fail") + logger.error("modify package.json fail") throw new Error("no package.json") } } diff --git a/packages/zhi-cli/vite.config.ts b/packages/zhi-cli/vite.config.ts index 715660ac..c3be15a8 100644 --- a/packages/zhi-cli/vite.config.ts +++ b/packages/zhi-cli/vite.config.ts @@ -53,7 +53,7 @@ export default defineConfig({ }, rollupOptions: { // External packages that should not be bundled into your library. - external: ["fs", "path", "process", "events", "assert", "readline"], + external: ["fs", "path", "process", "events", "assert", "readline", "child_process"], output: { banner: "#!/usr/bin/env node", }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f63d01ef..48d04bd5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,9 +22,6 @@ dependencies: loglevel-plugin-prefix: specifier: ^0.8.4 version: 0.8.4 - ora: - specifier: ^6.1.2 - version: 6.3.0 devDependencies: '@nrwl/eslint-plugin-nx': @@ -2403,11 +2400,6 @@ packages: engines: {node: '>=8'} dev: true - /ansi-regex@6.0.1: - resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} - engines: {node: '>=12'} - dev: false - /ansi-styles@3.2.1: resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} engines: {node: '>=4'} @@ -2551,6 +2543,7 @@ packages: /base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: true /binary-extensions@2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} @@ -2565,14 +2558,6 @@ packages: readable-stream: 3.6.2 dev: true - /bl@5.1.0: - resolution: {integrity: sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==} - dependencies: - buffer: 6.0.3 - inherits: 2.0.4 - readable-stream: 3.6.2 - dev: false - /brace-expansion@1.1.11: resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} dependencies: @@ -2615,13 +2600,6 @@ packages: ieee754: 1.2.1 dev: true - /buffer@6.0.3: - resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} - dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 - dev: false - /builtin-modules@3.3.0: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} engines: {node: '>=6'} @@ -2698,11 +2676,6 @@ packages: supports-color: 7.2.0 dev: true - /chalk@5.2.0: - resolution: {integrity: sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==} - engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - dev: false - /check-error@1.0.2: resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==} dev: true @@ -2734,16 +2707,10 @@ packages: restore-cursor: 3.1.0 dev: true - /cli-cursor@4.0.0: - resolution: {integrity: sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - restore-cursor: 4.0.0 - dev: false - /cli-spinners@2.6.1: resolution: {integrity: sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==} engines: {node: '>=6'} + dev: true /cliui@7.0.4: resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} @@ -2762,11 +2729,6 @@ packages: wrap-ansi: 7.0.0 dev: true - /clone@1.0.4: - resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==} - engines: {node: '>=0.8'} - dev: false - /code-block-writer@11.0.3: resolution: {integrity: sha512-NiujjUFB4SwScJq2bwbYUtXbZhBSlY6vYzm++3Q6oC+U+injTqfPYFK8wS9COOmb2lueqp0ZRB4nK1VYeHgNyw==} dev: true @@ -2910,12 +2872,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /defaults@1.0.4: - resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} - dependencies: - clone: 1.0.4 - dev: false - /define-lazy-prop@2.0.0: resolution: {integrity: sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==} engines: {node: '>=8'} @@ -3528,6 +3484,7 @@ packages: /ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: true /ignore@5.2.4: resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} @@ -3561,6 +3518,7 @@ packages: /inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + dev: true /is-arrayish@0.2.1: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} @@ -3609,11 +3567,6 @@ packages: is-extglob: 2.1.1 dev: true - /is-interactive@2.0.0: - resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} - engines: {node: '>=12'} - dev: false - /is-module@1.0.0: resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} dev: true @@ -3627,11 +3580,6 @@ packages: resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} dev: true - /is-unicode-supported@1.3.0: - resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} - engines: {node: '>=12'} - dev: false - /is-wsl@2.2.0: resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} engines: {node: '>=8'} @@ -3848,14 +3796,6 @@ packages: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: true - /log-symbols@5.1.0: - resolution: {integrity: sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==} - engines: {node: '>=12'} - dependencies: - chalk: 5.2.0 - is-unicode-supported: 1.3.0 - dev: false - /loglevel-plugin-prefix@0.8.4: resolution: {integrity: sha512-WpG9CcFAOjz/FtNht+QJeGpvVl/cdR6P0z6OcXSkr8wFJOsV2GRj2j10JLfjuA4aYkcKCNIEqRGCyTife9R8/g==} dev: false @@ -3919,6 +3859,7 @@ packages: /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} + dev: true /minimatch@3.0.5: resolution: {integrity: sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==} @@ -4096,6 +4037,7 @@ packages: engines: {node: '>=6'} dependencies: mimic-fn: 2.1.0 + dev: true /open@8.4.2: resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==} @@ -4130,21 +4072,6 @@ packages: word-wrap: 1.2.3 dev: true - /ora@6.3.0: - resolution: {integrity: sha512-1/D8uRFY0ay2kgBpmAwmSA404w4OoPVhHMqRqtjvrcK/dnzcEZxMJ+V4DUbyICu8IIVRclHcOf5wlD1tMY4GUQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - chalk: 5.2.0 - cli-cursor: 4.0.0 - cli-spinners: 2.6.1 - is-interactive: 2.0.0 - is-unicode-supported: 1.3.0 - log-symbols: 5.1.0 - stdin-discarder: 0.1.0 - strip-ansi: 7.0.1 - wcwidth: 1.0.1 - dev: false - /p-limit@3.1.0: resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} engines: {node: '>=10'} @@ -4276,6 +4203,7 @@ packages: inherits: 2.0.4 string_decoder: 1.3.0 util-deprecate: 1.0.2 + dev: true /readdirp@3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} @@ -4367,14 +4295,6 @@ packages: signal-exit: 3.0.7 dev: true - /restore-cursor@4.0.0: - resolution: {integrity: sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - onetime: 5.1.2 - signal-exit: 3.0.7 - dev: false - /reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -4418,6 +4338,7 @@ packages: /safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: true /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -4465,6 +4386,7 @@ packages: /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + dev: true /sirv@2.0.2: resolution: {integrity: sha512-4Qog6aE29nIjAOKe/wowFTxOdmbEZKb+3tsLljaBRzJwtqto0BChD2zzH0LhgCSXiI+V7X+Y45v14wBZQ1TK3w==} @@ -4500,13 +4422,6 @@ packages: resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==} dev: true - /stdin-discarder@0.1.0: - resolution: {integrity: sha512-xhV7w8S+bUwlPTb4bAOUQhv8/cSS5offJuX8GQGq32ONF0ZtDWKfkdomM3HMRA+LhX6um/FZ0COqlwsjD53LeQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - bl: 5.1.0 - dev: false - /string-argv@0.3.1: resolution: {integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==} engines: {node: '>=0.6.19'} @@ -4525,6 +4440,7 @@ packages: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} dependencies: safe-buffer: 5.2.1 + dev: true /strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} @@ -4533,13 +4449,6 @@ packages: ansi-regex: 5.0.1 dev: true - /strip-ansi@7.0.1: - resolution: {integrity: sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==} - engines: {node: '>=12'} - dependencies: - ansi-regex: 6.0.1 - dev: false - /strip-bom@3.0.0: resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==} engines: {node: '>=4'} @@ -4844,6 +4753,7 @@ packages: /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + dev: true /v8-compile-cache@2.3.0: resolution: {integrity: sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==} @@ -5015,12 +4925,6 @@ packages: xml-name-validator: 4.0.0 dev: true - /wcwidth@1.0.1: - resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} - dependencies: - defaults: 1.0.4 - dev: false - /webidl-conversions@7.0.0: resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==} engines: {node: '>=12'}