@ontology-platform/yc-cli 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ontology-platform/yc-cli
2
2
 
3
+ ## 1.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: 发布时改为构建后产物
8
+
9
+ ## 1.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: 修改基础框架镜像地址
14
+
3
15
  ## 1.1.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(require("url"),require("path"),require("module"),require("commander"),require("update-notifier"),require("chalk"),require("log-symbols"),require("fs-extra"),require("download"),require("ora"),require("inquirer"),require("handlebars")):typeof define=="function"&&define.amd?define(["url","path","module","commander","update-notifier","chalk","log-symbols","fs-extra","download","ora","inquirer","handlebars"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.url,r.path,r.module,r.commander,r.updateNotifier,r.chalk,r.symbols,r.fse,r.download,r.ora,r.inquirer,r.handlebars))})(this,function(r,n,$,s,b,t,u,i,P,w,R,C){"use strict";var l=typeof document<"u"?document.currentScript:null;Object.defineProperty(global,"require",{get(){return e=>$.createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:l&&l.src||new URL("index.cjs",document.baseURI).href)(e)},enumerable:!0,configurable:!1}),Object.defineProperty(global,"__filename",{get(){return r.fileURLToPath(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:l&&l.src||new URL("index.cjs",document.baseURI).href)},enumerable:!0,configurable:!1}),Object.defineProperty(global,"__dirname",{get(){return n.dirname(r.fileURLToPath(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:l&&l.src||new URL("index.cjs",document.baseURI).href))},enumerable:!0,configurable:!1});const U=global.require("../package.json"),f=b({pkg:U,updateCheckInterval:1e3});function L(){f.update?(console.log(`新版本可用: ${t.cyan(f.update.latest)}, 建议您在使用前更新.`),f.notify()):console.log("没有新版本.")}const T={name:"yc-cli",mirror:"http://114.242.25.123:3000/gitea/DP-FRONT-BG/template-vue3/archive/main.zip"},F=n.resolve(global.__dirname,"../mirrorConfig.json");async function x(){try{await i.outputJson(F,T)}catch(e){console.error(e),process.exit()}}const m=n.resolve(global.__dirname,"../mirrorConfig.json");async function S(e){await i.pathExists(m)||await x(),_(e)}async function _(e){try{const o=await i.readJson(m);o.mirror=e,await i.writeJson(m,o),console.log(u.success,`Set the mirror successful. ${e}`)}catch(o){console.log(u.error,t.red(`Set the mirror failed. ${o}`)),process.exit()}}const q=n.resolve(global.__dirname,"../mirrorConfig.json"),I=n.resolve(global.__dirname,"../template");async function v(){await i.pathExists(q)?await j():(await x(),await j())}async function j(){try{await i.remove(I)}catch(c){console.error(c),process.exit()}const e=await i.readJson(q),o=e.mirror.lastIndexOf(".");(o===-1||e.mirror.substring(o)!==".zip")&&(console.log(t.red("模板镜像链接必须为.zip结尾,如:https://github/yc-cli/marster.zip。请使用<yc-cli mirror url>命令设置模板镜像链接")),process.exit());const a=w(t.cyan("正在下载模板..."));a.start();try{await P(e.mirror,n.resolve(__dirname,"../template/"),{extract:!0,strip:1})}catch(c){a.text=t.red(`下载模板失败。 ${c}`),a.fail(),process.exit()}a.text="下载模板成功。",a.succeed()}async function O(e){try{await i.pathExists(e)?console.log(u.error,t.red("项目已经存在。")):R.prompt([{type:"checkbox",name:"modules",message:"请选择要使用的模块",choices:["权限管理(rbac)","动态本体","数据集管理"]}]).then(async a=>{const c=w(t.cyan("初始化项目..."));c.start();const E=n.resolve(global.__dirname,"../template/"),J=process.cwd(),g=e.toLowerCase(),y=`${J}/${g}`;await v();try{await i.copy(E,y)}catch(d){console.log(u.error,t.red(`复制模板失败。 ${d}`)),process.exit()}const M={project_name:g},h=[`${y}/package.json`,`${y}/.env`];for(var p=0;p<h.length;p++)try{const d=await i.readFile(h[p],"utf8"),A=await C.compile(d)(M);await i.outputFile(h[p],A)}catch(d){c.text=t.red(`初始化项目失败。 ${d}`),c.fail(),process.exit()}c.text="初始化项目成功。",c.succeed(),console.log(`
2
+ 开始吧:
3
+ cd ${t.yellow(g)}
4
+ 下载依赖:${t.yellow("npm install")} or ${t.yellow("yarn install")}
5
+ 启动项目:${t.yellow("npm run dev")} or ${t.yellow("yarn run dev")}
6
+ `)}).catch(a=>{a.isTtyError?console.log(u.error,t.red("提示符无法在当前环境中呈现。")):console.log(u.error,t.red(a))})}catch(o){console.error(o),process.exit()}}const z=global.require("../package.json");s.program.version(`当前yc-cli版本为:${z.version}`,"-v, --version"),s.program.command("upgrade").description("检查yc-cli脚手架版本").action(()=>{L()}),s.program.command("mirror <mirror_link>").description("设置镜像链接").action(e=>{S(e)}),s.program.command("template").description("从镜像链接下载模板。").action(()=>{v()}),s.program.name("yc-cli").usage("<commands> [options]").command("create <project_name>").description("创建一个javascript插件项目").action(e=>{O(e)}),s.program.parse(process.argv)});
package/dist/index.js ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+ import w from "url";
3
+ import s from "path";
4
+ import { createRequire as k } from "module";
5
+ import { program as c } from "commander";
6
+ import q from "update-notifier";
7
+ import r from "chalk";
8
+ import n from "log-symbols";
9
+ import o from "fs-extra";
10
+ import F from "download";
11
+ import b from "ora";
12
+ import O from "inquirer";
13
+ import R from "handlebars";
14
+ Object.defineProperty(global, "require", {
15
+ get() {
16
+ return (e) => k(import.meta.url)(e);
17
+ },
18
+ enumerable: !0,
19
+ configurable: !1
20
+ // writable: false,
21
+ });
22
+ Object.defineProperty(global, "__filename", {
23
+ get() {
24
+ return w.fileURLToPath(import.meta.url);
25
+ },
26
+ enumerable: !0,
27
+ configurable: !1
28
+ // writable: false,
29
+ });
30
+ Object.defineProperty(global, "__dirname", {
31
+ get() {
32
+ return s.dirname(w.fileURLToPath(import.meta.url));
33
+ },
34
+ enumerable: !0,
35
+ configurable: !1
36
+ // writable: false,
37
+ });
38
+ const T = global.require("../package.json"), d = q({
39
+ // 从 package.json 获取 name 和 version 进行查询
40
+ pkg: T,
41
+ // 设定检查更新周期,默认为 1000 * 60 * 60 * 24(1 天)
42
+ // 这里设定为 1000 毫秒(1秒)
43
+ updateCheckInterval: 1e3
44
+ });
45
+ function z() {
46
+ d.update ? (console.log(`新版本可用: ${r.cyan(d.update.latest)}, 建议您在使用前更新.`), d.notify()) : console.log("没有新版本.");
47
+ }
48
+ const E = {
49
+ name: "yc-cli",
50
+ mirror: "http://114.242.25.123:3000/gitea/DP-FRONT-BG/template-vue3/archive/main.zip"
51
+ }, J = s.resolve(global.__dirname, "../mirrorConfig.json");
52
+ async function x() {
53
+ try {
54
+ await o.outputJson(J, E);
55
+ } catch (e) {
56
+ console.error(e), process.exit();
57
+ }
58
+ }
59
+ const g = s.resolve(global.__dirname, "../mirrorConfig.json");
60
+ async function L(e) {
61
+ await o.pathExists(g) || await x(), y(e);
62
+ }
63
+ async function y(e) {
64
+ try {
65
+ const t = await o.readJson(g);
66
+ t.mirror = e, await o.writeJson(g, t), console.log(n.success, `Set the mirror successful. ${e}`);
67
+ } catch (t) {
68
+ console.log(n.error, r.red(`Set the mirror failed. ${t}`)), process.exit();
69
+ }
70
+ }
71
+ const v = s.resolve(global.__dirname, "../mirrorConfig.json"), S = s.resolve(global.__dirname, "../template");
72
+ async function _() {
73
+ await o.pathExists(v) ? await h() : (await x(), await h());
74
+ }
75
+ async function h() {
76
+ try {
77
+ await o.remove(S);
78
+ } catch (i) {
79
+ console.error(i), process.exit();
80
+ }
81
+ const e = await o.readJson(v), t = e.mirror.lastIndexOf(".");
82
+ (t === -1 || e.mirror.substring(t) !== ".zip") && (console.log(
83
+ r.red(
84
+ "模板镜像链接必须为.zip结尾,如:https://github/yc-cli/marster.zip。请使用<yc-cli mirror url>命令设置模板镜像链接"
85
+ )
86
+ ), process.exit());
87
+ const a = b(r.cyan("正在下载模板..."));
88
+ a.start();
89
+ try {
90
+ await F(e.mirror, s.resolve(__dirname, "../template/"), { extract: !0, strip: 1 });
91
+ } catch (i) {
92
+ a.text = r.red(`下载模板失败。 ${i}`), a.fail(), process.exit();
93
+ }
94
+ a.text = "下载模板成功。", a.succeed();
95
+ }
96
+ async function M(e) {
97
+ try {
98
+ await o.pathExists(e) ? console.log(n.error, r.red("项目已经存在。")) : O.prompt([
99
+ {
100
+ type: "checkbox",
101
+ name: "modules",
102
+ message: "请选择要使用的模块",
103
+ choices: ["权限管理(rbac)", "动态本体", "数据集管理"]
104
+ }
105
+ ]).then(async (a) => {
106
+ const i = b(r.cyan("初始化项目..."));
107
+ i.start();
108
+ const $ = s.resolve(global.__dirname, "../template/"), j = process.cwd(), p = e.toLowerCase(), u = `${j}/${p}`;
109
+ await _();
110
+ try {
111
+ await o.copy($, u);
112
+ } catch (l) {
113
+ console.log(n.error, r.red(`复制模板失败。 ${l}`)), process.exit();
114
+ }
115
+ const P = {
116
+ project_name: p
117
+ }, f = [`${u}/package.json`, `${u}/.env`];
118
+ for (var m = 0; m < f.length; m++)
119
+ try {
120
+ const l = await o.readFile(f[m], "utf8"), C = await R.compile(l)(P);
121
+ await o.outputFile(f[m], C);
122
+ } catch (l) {
123
+ i.text = r.red(`初始化项目失败。 ${l}`), i.fail(), process.exit();
124
+ }
125
+ i.text = "初始化项目成功。", i.succeed(), console.log(`
126
+ 开始吧:
127
+ cd ${r.yellow(p)}
128
+ 下载依赖:${r.yellow("npm install")} or ${r.yellow("yarn install")}
129
+ 启动项目:${r.yellow("npm run dev")} or ${r.yellow("yarn run dev")}
130
+ `);
131
+ }).catch((a) => {
132
+ a.isTtyError ? console.log(n.error, r.red("提示符无法在当前环境中呈现。")) : console.log(n.error, r.red(a));
133
+ });
134
+ } catch (t) {
135
+ console.error(t), process.exit();
136
+ }
137
+ }
138
+ const A = global.require("../package.json");
139
+ c.version(`当前yc-cli版本为:${A.version}`, "-v, --version");
140
+ c.command("upgrade").description("检查yc-cli脚手架版本").action(() => {
141
+ z();
142
+ });
143
+ c.command("mirror <mirror_link>").description("设置镜像链接").action((e) => {
144
+ L(e);
145
+ });
146
+ c.command("template").description("从镜像链接下载模板。").action(() => {
147
+ _();
148
+ });
149
+ c.name("yc-cli").usage("<commands> [options]").command("create <project_name>").description("创建一个javascript插件项目").action((e) => {
150
+ M(e);
151
+ });
152
+ c.parse(process.argv);
package/package.json CHANGED
@@ -1,13 +1,22 @@
1
1
  {
2
2
  "name": "@ontology-platform/yc-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "前端项目脚手架",
5
5
  "author": "志刚",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "main": "./bind/index.js",
9
- "bin": {
10
- "yc-cli": "./bin/index.js"
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "CHANGELOG.md"
12
+ ],
13
+ "module": "./dist/index.js",
14
+ "main": "./dist/index.cjs",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
19
+ }
11
20
  },
12
21
  "keywords": [
13
22
  "yc-cli",
@@ -26,6 +35,7 @@
26
35
  "update-notifier": "^6.0.2"
27
36
  },
28
37
  "scripts": {
29
- "test": "echo \"Error: no test specified\" && exit 1"
38
+ "test": "echo \"Error: no test specified\" && exit 1",
39
+ "build": "vite build"
30
40
  }
31
41
  }
package/bin/index.js DELETED
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // 添加全局变量global
4
- import '../utils/expandGlobal.js';
5
- // 引入 commander 库
6
- import { program } from 'commander';
7
- // 引入 upgrade 命令执行文件
8
- import updateChk from '../lib/update.js';
9
- // 引入 mirror 命令执行文件
10
- import setMirror from '../lib/mirror.js';
11
- // 引入 template 命令执行文件
12
- import dlTemplate from '../lib/download.js';
13
- // 引入 create 命令执行文件
14
- import createProject from '../lib/create.js';
15
- // 引入package.json对象
16
- const pkg = global.require('../package.json');
17
-
18
- // 查看版本命令 从 package.json 文件中请求 version 字段的值,-v和--version是参数
19
- program.version(`当前yc-cli版本为:${pkg.version}`, '-v, --version');
20
-
21
- // upgrade 检测更新命令
22
- program
23
- // 声明的命令
24
- .command('upgrade')
25
- // 描述信息,在帮助信息时显示
26
- .description('检查yc-cli脚手架版本')
27
- .action(() => {
28
- // 执行 lib/update.js 里面的操作
29
- updateChk();
30
- });
31
-
32
- // mirror 设置镜像链接
33
- program
34
- .command('mirror <mirror_link>')
35
- .description('设置镜像链接')
36
- .action((link) => {
37
- setMirror(link);
38
- });
39
-
40
- // template 下载/更新模板
41
- program
42
- .command('template')
43
- .description('从镜像链接下载模板。')
44
- .action(() => {
45
- dlTemplate();
46
- });
47
-
48
- // create 创建项目
49
- program
50
- .name('yc-cli')
51
- .usage('<commands> [options]')
52
- .command('create <project_name>')
53
- .description('创建一个javascript插件项目')
54
- .action((project) => {
55
- createProject(project);
56
- });
57
-
58
- // 解析命令行参数
59
- program.parse(process.argv);
package/lib/create.js DELETED
@@ -1,113 +0,0 @@
1
- /**
2
- * 创建项目
3
- */
4
- // 请求 fs-extra 库,用于文件操作
5
- import fse from 'fs-extra';
6
- // 请求 ora 库,用于初始化项目时等待动画
7
- import ora from 'ora';
8
- // 请求 chalk 库
9
- import chalk from 'chalk';
10
- // 请求 log-symbols 库
11
- import symbols from 'log-symbols';
12
- // 请求 inquirer 库,用于控制台交互
13
- import inquirer from 'inquirer';
14
- // 请求 handlebars 库,用于替换模板字符
15
- import handlebars from 'handlebars';
16
- import path from 'path';
17
-
18
- // 请求 download.js 文件,模板不在本地时执行该操作
19
- import dlTemplate from './download.js';
20
-
21
- // 创建项目函数
22
- async function createProject(projectName) {
23
- try {
24
- const exists = await fse.pathExists(projectName);
25
- if (exists) {
26
- // 项目重名时提醒用户
27
- console.log(symbols.error, chalk.red('项目已经存在。'));
28
- } else {
29
- // 执行控制台交互
30
- inquirer
31
- // 控制台交互
32
- .prompt([
33
- {
34
- type: 'checkbox',
35
- name: 'modules',
36
- message: '请选择要使用的模块',
37
- choices: ['权限管理(rbac)', '动态本体', '数据集管理'],
38
- },
39
- ])
40
- .then(async (answers) => {
41
- // Spinner 初始设置
42
- const initSpinner = ora(chalk.cyan('初始化项目...'));
43
- // 开始执行等待动画
44
- initSpinner.start();
45
- // 拼接 template 文件夹路径
46
- const templatePath = path.resolve(global.__dirname, '../template/');
47
- // 返回 Node.js 进程的当前工作目录
48
- const processPath = process.cwd();
49
- // 把项目名转小写
50
- const LCProjectName = projectName.toLowerCase();
51
- // 拼接项目完整路径
52
- const targetPath = `${processPath}/${LCProjectName}`;
53
- // 下载模板,下载完再执行下面的语句
54
- await dlTemplate();
55
- // 等待复制好模板文件到对应路径去
56
- try {
57
- await fse.copy(templatePath, targetPath);
58
- } catch (err) {
59
- console.log(symbols.error, chalk.red(`复制模板失败。 ${err}`));
60
- process.exit();
61
- }
62
- // 把要替换的模板字符准备好
63
- const multiMeta = {
64
- project_name: LCProjectName,
65
- };
66
- // 把要替换的文件准备好
67
- const multiFiles = [`${targetPath}/package.json`, `${targetPath}/.env`];
68
- // 用条件循环把模板字符替换到文件去
69
- for (var i = 0; i < multiFiles.length; i++) {
70
- // 这里记得 try {} catch {} 哦,以便出错时可以终止掉 Spinner
71
- try {
72
- // 等待读取文件
73
- const multiFilesContent = await fse.readFile(multiFiles[i], 'utf8');
74
- // 等待替换文件,handlebars.compile(原文件内容)(模板字符)
75
- const multiFilesResult = await handlebars.compile(multiFilesContent)(multiMeta);
76
- // 等待输出文件
77
- await fse.outputFile(multiFiles[i], multiFilesResult);
78
- } catch (err) {
79
- // 如果出错,Spinner 就改变文字信息
80
- initSpinner.text = chalk.red(`初始化项目失败。 ${err}`);
81
- // 终止等待动画并显示 X 标志
82
- initSpinner.fail();
83
- // 退出进程
84
- process.exit();
85
- }
86
- }
87
- // 如果成功,Spinner 就改变文字信息
88
- initSpinner.text = '初始化项目成功。';
89
- // 终止等待动画并显示 ✔ 标志
90
- initSpinner.succeed();
91
- console.log(`
92
- 开始吧:
93
- cd ${chalk.yellow(LCProjectName)}
94
- 下载依赖:${chalk.yellow('npm install')} or ${chalk.yellow('yarn install')}
95
- 启动项目:${chalk.yellow('npm run dev')} or ${chalk.yellow('yarn run dev')}
96
- `);
97
- })
98
- .catch((error) => {
99
- if (error.isTtyError) {
100
- console.log(symbols.error, chalk.red('提示符无法在当前环境中呈现。'));
101
- } else {
102
- console.log(symbols.error, chalk.red(error));
103
- }
104
- });
105
- }
106
- } catch (err) {
107
- console.error(err);
108
- process.exit();
109
- }
110
- }
111
-
112
- // 将上面的 createProject(projectName) 方法导出
113
- export default createProject;
package/lib/download.js DELETED
@@ -1,79 +0,0 @@
1
- /**
2
- * 下载/更新模板
3
- */
4
- // 请求 download 库,用于下载模板
5
- import download from 'download';
6
- // 请求 ora 库,用于实现等待动画
7
- import ora from 'ora';
8
- // 请求 chalk 库,用于实现控制台字符样式
9
- import chalk from 'chalk';
10
- // 请求 fs-extra 库,用于文件操作
11
- import fse from 'fs-extra';
12
- // 创建镜像链接配置文件
13
- import createMirrorConfig from '../utils/createMirrorConfig.js';
14
- import path from 'path';
15
-
16
- // 拼接 mirrorConfig.json 完整路径
17
- const cfgPath = path.resolve(global.__dirname, '../mirrorConfig.json');
18
- // 拼接 template 模板文件夹完整路径
19
- const tplPath = path.resolve(global.__dirname, '../template');
20
-
21
- async function dlTemplate() {
22
- // 参考上方 mirror.js 主代码注释
23
- const exists = await fse.pathExists(cfgPath);
24
- if (exists) {
25
- // 这里记得加 await,在 init.js 调用时使用 async/await 生效
26
- await dlAction();
27
- } else {
28
- await createMirrorConfig();
29
- // 同上
30
- await dlAction();
31
- }
32
- }
33
-
34
- async function dlAction() {
35
- // 清空模板文件夹的相关内容,用法见 fs-extra 的 README.md
36
- try {
37
- await fse.remove(tplPath);
38
- } catch (err) {
39
- console.error(err);
40
- process.exit();
41
- }
42
- // 读取配置,用于获取镜像链接
43
- const jsonConfig = await fse.readJson(cfgPath);
44
- const index = jsonConfig.mirror.lastIndexOf('.');
45
- // 判断镜像地址必须为zip格式
46
- if (index === -1 || jsonConfig.mirror.substring(index) !== '.zip') {
47
- console.log(
48
- chalk.red(
49
- `模板镜像链接必须为.zip结尾,如:https://github/yc-cli/marster.zip。请使用<yc-cli mirror url>命令设置模板镜像链接`,
50
- ),
51
- );
52
- process.exit();
53
- }
54
- // Spinner 初始设置
55
- const dlSpinner = ora(chalk.cyan('正在下载模板...'));
56
- // 开始执行等待动画
57
- dlSpinner.start();
58
- try {
59
- /**
60
- * 下载模板后解压
61
- * extract: true 类型是boolean,默认值是false。如果设置为true的话,会尝试使用decompress来解压缩
62
- * strip: 1 默认值是0,从解压缩的文件中移除前面的目录组件
63
- */
64
- await download(jsonConfig.mirror, path.resolve(__dirname, '../template/'), { extract: true, strip: 1 });
65
- } catch (err) {
66
- // 下载失败时提示
67
- dlSpinner.text = chalk.red(`下载模板失败。 ${err}`);
68
- // 终止等待动画并显示 X 标志
69
- dlSpinner.fail();
70
- process.exit();
71
- }
72
- // 下载成功时提示
73
- dlSpinner.text = '下载模板成功。';
74
- // 终止等待动画并显示 ✔ 标志
75
- dlSpinner.succeed();
76
- }
77
-
78
- // 将上面的 dlTemplate() 方法导出
79
- export default dlTemplate;
package/lib/mirror.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * 设置镜像链接地址
3
- */
4
- // 引入 终端图标、加载动画库
5
- import symbols from 'log-symbols';
6
- // 引入 文件读写增强库
7
- import fse from 'fs-extra';
8
- // 引用 chalk 库,用于控制台字符样式
9
- import chalk from 'chalk';
10
- // 创建镜像链接配置文件
11
- import createMirrorConfig from '../utils/createMirrorConfig.js';
12
- import path from 'path';
13
- // 拼接 mirrorConfig.json 完整路径
14
- const cfgPath = path.resolve(global.__dirname, '../mirrorConfig.json');
15
- // 生成镜像链接配置及设置镜像链接地址
16
- async function setMirror(link) {
17
- // 判断 config.json 文件是否存在
18
- const exists = await fse.pathExists(cfgPath);
19
- if (exists) {
20
- // 存在时直接写入配置
21
- mirrorAction(link);
22
- } else {
23
- // 不存在时先初始化配置,然后再写入配置
24
- await createMirrorConfig();
25
- mirrorAction(link);
26
- }
27
- }
28
-
29
- // 设置 镜像链接地址
30
- async function mirrorAction(link) {
31
- try {
32
- // 读取 config.json 文件
33
- const jsonConfig = await fse.readJson(cfgPath);
34
- // 将传进来的参数 link 写入 config.json 文件
35
- jsonConfig.mirror = link;
36
- // 再写入 config.json 文件
37
- await fse.writeJson(cfgPath, jsonConfig);
38
- // 等待写入后再提示配置成功
39
- console.log(symbols.success, `Set the mirror successful. ${link}`);
40
- } catch (err) {
41
- // 如果出错,提示报错信息
42
- console.log(symbols.error, chalk.red(`Set the mirror failed. ${err}`));
43
- process.exit();
44
- }
45
- }
46
-
47
- // 将上面的 setMirror(link) 方法导出
48
- export default setMirror;
package/lib/update.js DELETED
@@ -1,29 +0,0 @@
1
- // 引用 update-notifier 库,用于检查更新
2
- import updateNotifier from 'update-notifier';
3
- // 引用 chalk 库,用于控制台字符样式
4
- import chalk from 'chalk';
5
- // 引入package.json对象
6
- const pkg = global.require('../package.json');
7
-
8
- // updateNotifier 是 update-notifier 的方法,其他方法可到 npmjs 查看
9
- const notifier = updateNotifier({
10
- // 从 package.json 获取 name 和 version 进行查询
11
- pkg,
12
- // 设定检查更新周期,默认为 1000 * 60 * 60 * 24(1 天)
13
- // 这里设定为 1000 毫秒(1秒)
14
- updateCheckInterval: 1000,
15
- });
16
-
17
- function updateChk() {
18
- // 当检测到版本时,notifier.update 会返回 Object
19
- // 此时可以用 notifier.update.latest 获取最新版本号
20
- if (notifier.update) {
21
- console.log(`新版本可用: ${chalk.cyan(notifier.update.latest)}, 建议您在使用前更新.`);
22
- notifier.notify();
23
- } else {
24
- console.log('没有新版本.');
25
- }
26
- }
27
-
28
- // 将上面的 updateChk() 方法导出
29
- export default updateChk;
@@ -1,26 +0,0 @@
1
- /**
2
- * 创建镜像链接配置文件
3
- */
4
- // 引入 文件读写增强库
5
- import fse from 'fs-extra';
6
- import path from 'path';
7
-
8
- // 声明配置文件内容
9
- const jsonConfig = {
10
- name: 'yc-cli',
11
- mirror: 'http://114.242.25.123:3000/DP-FRONT-BG/template-vue3/archive/main.zip',
12
- };
13
- // 拼接 config.json 完整路径
14
- const configPath = path.resolve(global.__dirname, '../mirrorConfig.json');
15
- async function createMirrorConfig() {
16
- try {
17
- // 利用 fs-extra 封装的方法,将 jsonConfig 内容保存成 json 文件
18
- await fse.outputJson(configPath, jsonConfig);
19
- } catch (err) {
20
- console.error(err);
21
- process.exit();
22
- }
23
- }
24
-
25
- // 将上面的 createMirrorConfig() 方法导出
26
- export default createMirrorConfig;
@@ -1,36 +0,0 @@
1
- /**
2
- * 添加全局变量global,增加__filename、__direname变量及CommonJS的require方法
3
- */
4
- import url from 'url';
5
- import path from 'path';
6
- import { createRequire } from 'module';
7
-
8
- Object.defineProperty(global, 'require', {
9
- get() {
10
- return (filepath) => {
11
- const require = createRequire(import.meta.url);
12
- return require(filepath);
13
- };
14
- },
15
- enumerable: true,
16
- configurable: false,
17
- // writable: false,
18
- });
19
-
20
- Object.defineProperty(global, '__filename', {
21
- get() {
22
- return url.fileURLToPath(import.meta.url);
23
- },
24
- enumerable: true,
25
- configurable: false,
26
- // writable: false,
27
- });
28
-
29
- Object.defineProperty(global, '__dirname', {
30
- get() {
31
- return path.dirname(url.fileURLToPath(import.meta.url));
32
- },
33
- enumerable: true,
34
- configurable: false,
35
- // writable: false,
36
- });