quan-cli 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -0,0 +1,15 @@
1
+ 一个简易的可以用于下载软件包的脚手架 (目前只写了下载功能)
2
+ #### 安装
3
+ npm install -g quan-cli
4
+ #### 本地运行
5
+ npm run dev 注意:如果要加参数后面要加--, 例:npm run dev -- init --debug
6
+ #### 打包
7
+ cnpm run build
8
+ #### 使用
9
+ quan-cli -h,--help 查看帮助
10
+ quan-cli -v,--version 查看版本
11
+ quan-cli init 创建项目
12
+ quan-cli init --debug,-d 创建项目并切打印信息
13
+ quan-cli init -p,--packagePath <dir> 创建项目到目录内
14
+ quan-cli init -f,--force 强制清空目录并且创建项目到目录内
15
+ quan-cli init -p,--packagePath <dir> -f,--force -d,--debug
@@ -1,17 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./initAction"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./initAction"), exports);
@@ -1,123 +1,123 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.InitAction = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- //@ts-ignore
10
- const userhome_1 = __importDefault(require("userhome"));
11
- const inquirer_1 = __importDefault(require("inquirer"));
12
- const fs_extra_1 = __importDefault(require("fs-extra"));
13
- const axios_1 = __importDefault(require("axios"));
14
- //@ts-ignore
15
- const npminstall_1 = __importDefault(require("npminstall"));
16
- const utils_1 = require("../utils");
17
- const config_1 = require("../config");
18
- class InitAction {
19
- constructor(option) {
20
- this.cwdPath = process.cwd();
21
- this.homePath = (0, userhome_1.default)();
22
- this.basePath = option.packagePath || this.cwdPath;
23
- this.force = option.force || false;
24
- this.origin = option.origin || utils_1.NpmUtil.getNpmRegistry(true);
25
- this.initAction();
26
- }
27
- //初始化
28
- async initAction() {
29
- utils_1.log.debug('homePath', this.homePath);
30
- utils_1.log.debug('工作路径', this.cwdPath);
31
- utils_1.log.debug('要创建的目录', this.basePath);
32
- //路径不存在
33
- this.checkPath();
34
- this.checkForce();
35
- await this.checkPrompt();
36
- await this.getTemplate();
37
- await this.selectTemplate();
38
- await this.getTemplateVersion();
39
- await this.install();
40
- }
41
- //检查路径是否可用
42
- checkPath() {
43
- if (!fs_1.default.existsSync(this.basePath)) {
44
- utils_1.log.error('error', '路径不存在,请重试!');
45
- process.exit(1);
46
- }
47
- }
48
- //force清空目录
49
- checkForce() {
50
- const isEmpty = utils_1.FileUtil.isEmptyDir(this.basePath);
51
- if (!isEmpty && this.force) {
52
- fs_extra_1.default.emptyDirSync(this.basePath);
53
- }
54
- }
55
- //checkPrompt 清空目录
56
- async checkPrompt() {
57
- const isEmpty = utils_1.FileUtil.isEmptyDir(this.basePath);
58
- if (!isEmpty) {
59
- const isDelDir = await this.getDelPrompt();
60
- if (!isDelDir) {
61
- process.exit(1);
62
- }
63
- else {
64
- fs_extra_1.default.emptyDirSync(this.basePath);
65
- }
66
- }
67
- }
68
- async getDelPrompt() {
69
- const { isDelDir } = await inquirer_1.default.prompt([
70
- {
71
- type: 'confirm',
72
- name: 'isDelDir',
73
- message: `是否清空${this.basePath}。注意(文件无法恢复,请谨慎操作)`,
74
- },
75
- ]);
76
- return isDelDir;
77
- }
78
- async getTemplateVersion() {
79
- return await utils_1.NpmUtil.getLatestVersion(this.template.store, this.origin);
80
- }
81
- async install() {
82
- const version = await this.getTemplateVersion();
83
- utils_1.log.debug(`执行安装:${this.template.store},版本:${version}`);
84
- utils_1.log.debug(path_1.default.resolve(this.homePath, config_1.paths.ROOT_PATH, config_1.paths.TARGET_PATH));
85
- const loadingStart = (0, utils_1.loading)('正在下载模板...');
86
- await (0, utils_1.sleep)(1500);
87
- await (0, npminstall_1.default)({
88
- root: path_1.default.resolve(this.homePath, config_1.paths.ROOT_PATH, config_1.paths.TARGET_PATH),
89
- registry: this.origin,
90
- pkgs: [{ name: this.template.store, version: version }],
91
- });
92
- this.copy(this.template.store, version);
93
- loadingStart.stop(true);
94
- utils_1.log.info('info', '模板下载完成');
95
- }
96
- //執行copy
97
- copy(name, version) {
98
- const packageName = utils_1.NpmUtil.getPackageDirName(name, version);
99
- const originPath = path_1.default.resolve(this.homePath, config_1.paths.ROOT_PATH, config_1.paths.TARGET_PATH, 'node_modules', packageName, 'template');
100
- const targetPath = this.basePath;
101
- fs_extra_1.default.copySync(originPath, targetPath);
102
- process.exit(1);
103
- }
104
- async selectTemplate() {
105
- const { template } = await inquirer_1.default.prompt([
106
- {
107
- type: 'list',
108
- name: 'template',
109
- message: '请选择要下载的模板',
110
- choices: this.templates.map((item) => item.name),
111
- },
112
- ]);
113
- this.template = this.templates.filter((item) => item.name === template)[0];
114
- }
115
- async getTemplate() {
116
- const { data: { data }, } = await (0, axios_1.default)({
117
- method: 'get',
118
- url: 'http://101.42.154.196/quan-cli/getAllTemplate',
119
- });
120
- this.templates = data;
121
- }
122
- }
123
- exports.InitAction = InitAction;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InitAction = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ //@ts-ignore
10
+ const userhome_1 = __importDefault(require("userhome"));
11
+ const inquirer_1 = __importDefault(require("inquirer"));
12
+ const fs_extra_1 = __importDefault(require("fs-extra"));
13
+ const axios_1 = __importDefault(require("axios"));
14
+ //@ts-ignore
15
+ const npminstall_1 = __importDefault(require("npminstall"));
16
+ const utils_1 = require("../utils");
17
+ const config_1 = require("../config");
18
+ class InitAction {
19
+ constructor(option) {
20
+ this.cwdPath = process.cwd();
21
+ this.homePath = (0, userhome_1.default)();
22
+ this.basePath = option.packagePath || this.cwdPath;
23
+ this.force = option.force || false;
24
+ this.origin = option.origin || utils_1.NpmUtil.getNpmRegistry(true);
25
+ this.initAction();
26
+ }
27
+ //初始化
28
+ async initAction() {
29
+ utils_1.log.debug('homePath', this.homePath);
30
+ utils_1.log.debug('工作路径', this.cwdPath);
31
+ utils_1.log.debug('要创建的目录', this.basePath);
32
+ //路径不存在
33
+ this.checkPath();
34
+ this.checkForce();
35
+ await this.checkPrompt();
36
+ await this.getTemplate();
37
+ await this.selectTemplate();
38
+ await this.getTemplateVersion();
39
+ await this.install();
40
+ }
41
+ //检查路径是否可用
42
+ checkPath() {
43
+ if (!fs_1.default.existsSync(this.basePath)) {
44
+ utils_1.log.error('error', '路径不存在,请重试!');
45
+ process.exit(1);
46
+ }
47
+ }
48
+ //force清空目录
49
+ checkForce() {
50
+ const isEmpty = utils_1.FileUtil.isEmptyDir(this.basePath);
51
+ if (!isEmpty && this.force) {
52
+ fs_extra_1.default.emptyDirSync(this.basePath);
53
+ }
54
+ }
55
+ //checkPrompt 清空目录
56
+ async checkPrompt() {
57
+ const isEmpty = utils_1.FileUtil.isEmptyDir(this.basePath);
58
+ if (!isEmpty) {
59
+ const isDelDir = await this.getDelPrompt();
60
+ if (!isDelDir) {
61
+ process.exit(1);
62
+ }
63
+ else {
64
+ fs_extra_1.default.emptyDirSync(this.basePath);
65
+ }
66
+ }
67
+ }
68
+ async getDelPrompt() {
69
+ const { isDelDir } = await inquirer_1.default.prompt([
70
+ {
71
+ type: 'confirm',
72
+ name: 'isDelDir',
73
+ message: `是否清空${this.basePath}。注意(文件无法恢复,请谨慎操作)`,
74
+ },
75
+ ]);
76
+ return isDelDir;
77
+ }
78
+ async getTemplateVersion() {
79
+ return await utils_1.NpmUtil.getLatestVersion(this.template.store, this.origin);
80
+ }
81
+ async install() {
82
+ const version = await this.getTemplateVersion();
83
+ utils_1.log.debug(`执行安装:${this.template.store},版本:${version}`);
84
+ utils_1.log.debug(path_1.default.resolve(this.homePath, config_1.paths.ROOT_PATH, config_1.paths.TARGET_PATH));
85
+ const loadingStart = (0, utils_1.loading)('正在下载模板...');
86
+ await (0, utils_1.sleep)(1500);
87
+ await (0, npminstall_1.default)({
88
+ root: path_1.default.resolve(this.homePath, config_1.paths.ROOT_PATH, config_1.paths.TARGET_PATH),
89
+ registry: this.origin,
90
+ pkgs: [{ name: this.template.store, version: version }],
91
+ });
92
+ this.copy(this.template.store, version);
93
+ loadingStart.stop(true);
94
+ utils_1.log.info('info', '模板下载完成');
95
+ }
96
+ //執行copy
97
+ copy(name, version) {
98
+ const packageName = utils_1.NpmUtil.getPackageDirName(name, version);
99
+ const originPath = path_1.default.resolve(this.homePath, config_1.paths.ROOT_PATH, config_1.paths.TARGET_PATH, 'node_modules', packageName, 'template');
100
+ const targetPath = this.basePath;
101
+ fs_extra_1.default.copySync(originPath, targetPath);
102
+ process.exit(1);
103
+ }
104
+ async selectTemplate() {
105
+ const { template } = await inquirer_1.default.prompt([
106
+ {
107
+ type: 'list',
108
+ name: 'template',
109
+ message: '请选择要下载的模板',
110
+ choices: this.templates.map((item) => item.name),
111
+ },
112
+ ]);
113
+ this.template = this.templates.filter((item) => item.name === template)[0];
114
+ }
115
+ async getTemplate() {
116
+ const { data: { data }, } = await (0, axios_1.default)({
117
+ method: 'get',
118
+ url: 'http://101.42.154.196/quan-cli/getAllTemplate',
119
+ });
120
+ this.templates = data;
121
+ }
122
+ }
123
+ exports.InitAction = InitAction;
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./package"), exports);
18
- __exportStar(require("./path"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./package"), exports);
18
+ __exportStar(require("./path"), exports);
@@ -1,7 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pack = void 0;
4
- const utils_1 = require("../utils");
5
- const packJson = require('../../package');
6
- utils_1.log.debug('package', JSON.stringify(packJson));
7
- exports.pack = packJson;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pack = void 0;
4
+ const utils_1 = require("../utils");
5
+ const packJson = require('../../package');
6
+ utils_1.log.debug('package', JSON.stringify(packJson));
7
+ exports.pack = packJson;
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.paths = void 0;
4
- var paths;
5
- (function (paths) {
6
- paths["ROOT_PATH"] = ".quan-cli";
7
- paths["TARGET_PATH"] = "dependencies";
8
- })(paths = exports.paths || (exports.paths = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paths = void 0;
4
+ var paths;
5
+ (function (paths) {
6
+ paths["ROOT_PATH"] = ".quan-cli";
7
+ paths["TARGET_PATH"] = "dependencies";
8
+ })(paths = exports.paths || (exports.paths = {}));
package/lib/index.js CHANGED
@@ -1,60 +1,60 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const commander_1 = require("commander");
7
- const semver_1 = __importDefault(require("semver"));
8
- const minimist_1 = __importDefault(require("minimist"));
9
- const utils_1 = require("./utils");
10
- const config_1 = require("./config");
11
- const actions_1 = require("./actions");
12
- class Cli {
13
- constructor() {
14
- this.program = commander_1.program;
15
- this.init();
16
- }
17
- async init() {
18
- this.checkEnv();
19
- await this.checkCli();
20
- this.registerCommand();
21
- }
22
- checkEnv() {
23
- const args = (0, minimist_1.default)(process.argv.slice(2));
24
- if (args.debug || args.d) {
25
- (0, utils_1.setLogLevel)('debug');
26
- }
27
- }
28
- async checkCli() {
29
- const currentVersion = config_1.pack.version;
30
- let lastVersion;
31
- try {
32
- lastVersion = await utils_1.NpmUtil.getLatestVersion('cyq-cli-template-vue3');
33
- }
34
- catch (e) {
35
- lastVersion = '0.0.0';
36
- }
37
- if (!semver_1.default.lt(currentVersion, lastVersion)) {
38
- utils_1.log.info('tip', `quan-cli最新版本${lastVersion} 当前版本${currentVersion}`);
39
- utils_1.log.info('tip', `使用npm install quan-cli 更新`);
40
- }
41
- utils_1.log.debug('quan-cli当前版本', currentVersion);
42
- utils_1.log.debug('quan-cli最新版本', lastVersion);
43
- }
44
- registerCommand() {
45
- this.program.name(config_1.pack.name).version(config_1.pack.version).description(`quan-cli version:${config_1.pack.version}`);
46
- this.program.option('-d, --debug', '开启debug模式(打印信息)');
47
- this.program
48
- .command('init [type]')
49
- .description('quan-cli 初始化项目')
50
- .option('-p, --packagePath <packagePath>', '指定init包的路径')
51
- .option('-f, --force', '覆盖当前项目')
52
- .option('-o, --origin <origin>', '指定初始化使用的npm源')
53
- .action((str, option) => {
54
- utils_1.log.debug('输入参数', option);
55
- new actions_1.InitAction(option);
56
- });
57
- this.program.parse();
58
- }
59
- }
60
- new Cli();
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const semver_1 = __importDefault(require("semver"));
8
+ const minimist_1 = __importDefault(require("minimist"));
9
+ const utils_1 = require("./utils");
10
+ const config_1 = require("./config");
11
+ const actions_1 = require("./actions");
12
+ class Cli {
13
+ constructor() {
14
+ this.program = commander_1.program;
15
+ this.init();
16
+ }
17
+ async init() {
18
+ this.checkEnv();
19
+ await this.checkCli();
20
+ this.registerCommand();
21
+ }
22
+ checkEnv() {
23
+ const args = (0, minimist_1.default)(process.argv.slice(2));
24
+ if (args.debug || args.d) {
25
+ (0, utils_1.setLogLevel)('debug');
26
+ }
27
+ }
28
+ async checkCli() {
29
+ const currentVersion = config_1.pack.version;
30
+ let lastVersion;
31
+ try {
32
+ lastVersion = await utils_1.NpmUtil.getLatestVersion('cyq-cli-template-vue3');
33
+ }
34
+ catch (e) {
35
+ lastVersion = '0.0.0';
36
+ }
37
+ if (!semver_1.default.lt(currentVersion, lastVersion)) {
38
+ utils_1.log.info('tip', `quan-cli最新版本${lastVersion} 当前版本${currentVersion}`);
39
+ utils_1.log.info('tip', `使用npm install quan-cli 更新`);
40
+ }
41
+ utils_1.log.debug('quan-cli当前版本', currentVersion);
42
+ utils_1.log.debug('quan-cli最新版本', lastVersion);
43
+ }
44
+ registerCommand() {
45
+ this.program.name(config_1.pack.name).version(config_1.pack.version).description(`quan-cli version:${config_1.pack.version}`);
46
+ this.program.option('-d, --debug', '开启debug模式(打印信息)');
47
+ this.program
48
+ .command('init [type]')
49
+ .description('quan-cli 初始化项目')
50
+ .option('-p, --packagePath <packagePath>', '指定init包的路径')
51
+ .option('-f, --force', '覆盖当前项目')
52
+ .option('-o, --origin <origin>', '指定初始化使用的npm源')
53
+ .action((str, option) => {
54
+ utils_1.log.debug('输入参数', option);
55
+ new actions_1.InitAction(option);
56
+ });
57
+ this.program.parse();
58
+ }
59
+ }
60
+ new Cli();
package/lib/utils/file.js CHANGED
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FileUtil = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- class FileUtil {
9
- }
10
- exports.FileUtil = FileUtil;
11
- FileUtil.isEmptyDir = (path) => {
12
- let fileList = fs_1.default.readdirSync(path);
13
- fileList = fileList.filter((file) => ['node_modules', 'src', 'tsconfig.json', 'package.json', '.git', '.DS_Store'].includes(file));
14
- if (fileList && fileList.length > 0) {
15
- return false;
16
- }
17
- else {
18
- return true;
19
- }
20
- };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FileUtil = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ class FileUtil {
9
+ }
10
+ exports.FileUtil = FileUtil;
11
+ FileUtil.isEmptyDir = (path) => {
12
+ let fileList = fs_1.default.readdirSync(path);
13
+ fileList = fileList.filter((file) => ['node_modules', 'src', 'tsconfig.json', 'package.json', '.git', '.DS_Store'].includes(file));
14
+ if (fileList && fileList.length > 0) {
15
+ return false;
16
+ }
17
+ else {
18
+ return true;
19
+ }
20
+ };
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./file"), exports);
18
- __exportStar(require("./log"), exports);
19
- __exportStar(require("./npm"), exports);
20
- __exportStar(require("./loading"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./file"), exports);
18
+ __exportStar(require("./log"), exports);
19
+ __exportStar(require("./npm"), exports);
20
+ __exportStar(require("./loading"), exports);
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = exports.loading = void 0;
4
- const cli_spinner_1 = require("cli-spinner");
5
- const loading = (msg, spinnerString = '|/-\\') => {
6
- const spinner = new cli_spinner_1.Spinner(`${msg}.. %s`);
7
- spinner.setSpinnerString(spinnerString);
8
- spinner.start();
9
- return spinner;
10
- };
11
- exports.loading = loading;
12
- const sleep = async (time = 0) => {
13
- await new Promise((resolve) => {
14
- let timer = setTimeout(() => {
15
- resolve(undefined);
16
- clearTimeout(timer);
17
- }, time);
18
- });
19
- };
20
- exports.sleep = sleep;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sleep = exports.loading = void 0;
4
+ const cli_spinner_1 = require("cli-spinner");
5
+ const loading = (msg, spinnerString = '|/-\\') => {
6
+ const spinner = new cli_spinner_1.Spinner(`${msg}.. %s`);
7
+ spinner.setSpinnerString(spinnerString);
8
+ spinner.start();
9
+ return spinner;
10
+ };
11
+ exports.loading = loading;
12
+ const sleep = async (time = 0) => {
13
+ await new Promise((resolve) => {
14
+ let timer = setTimeout(() => {
15
+ resolve(undefined);
16
+ clearTimeout(timer);
17
+ }, time);
18
+ });
19
+ };
20
+ exports.sleep = sleep;
package/lib/utils/log.js CHANGED
@@ -1,17 +1,17 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setLogLevel = exports.log = void 0;
7
- const npmlog_1 = __importDefault(require("npmlog"));
8
- exports.log = npmlog_1.default;
9
- npmlog_1.default.level = process.env.LOG_LEVEL || 'info';
10
- npmlog_1.default.heading = 'quan-cli';
11
- npmlog_1.default.addLevel('success', 2000, { fg: 'green', bold: true });
12
- npmlog_1.default.addLevel('debug', 1000, { fg: 'blue', bg: 'black' });
13
- const setLogLevel = (level) => {
14
- npmlog_1.default.level = level;
15
- npmlog_1.default.debug(npmlog_1.default.level + '模式开启');
16
- };
17
- exports.setLogLevel = setLogLevel;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setLogLevel = exports.log = void 0;
7
+ const npmlog_1 = __importDefault(require("npmlog"));
8
+ exports.log = npmlog_1.default;
9
+ npmlog_1.default.level = process.env.LOG_LEVEL || 'info';
10
+ npmlog_1.default.heading = 'quan-cli';
11
+ npmlog_1.default.addLevel('success', 2000, { fg: 'green', bold: true });
12
+ npmlog_1.default.addLevel('debug', 1000, { fg: 'blue', bg: 'black' });
13
+ const setLogLevel = (level) => {
14
+ npmlog_1.default.level = level;
15
+ npmlog_1.default.debug(npmlog_1.default.level + '模式开启');
16
+ };
17
+ exports.setLogLevel = setLogLevel;
package/lib/utils/npm.js CHANGED
@@ -1,29 +1,29 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NpmUtil = void 0;
7
- const log_1 = require("./log");
8
- const axios_1 = __importDefault(require("axios"));
9
- class NpmUtil {
10
- // 获取 registry 信息
11
- static getNpmRegistry(isOriginal = false) {
12
- return isOriginal ? 'https://registry.npmjs.org' : 'https://registry.npm.taobao.org';
13
- }
14
- //获取npm最新版本号
15
- static async getLatestVersion(packageName, origin = NpmUtil.getNpmRegistry(true)) {
16
- log_1.log.debug('链接' + origin + '/' + packageName);
17
- const { data } = await (0, axios_1.default)({
18
- method: 'get',
19
- url: origin + '/' + packageName,
20
- });
21
- const version = data['dist-tags'].latest;
22
- return version;
23
- }
24
- //获取npm包在文件中的名字
25
- static getPackageDirName(packageName, version) {
26
- return '_' + packageName + '@' + version + '@' + packageName;
27
- }
28
- }
29
- exports.NpmUtil = NpmUtil;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NpmUtil = void 0;
7
+ const log_1 = require("./log");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class NpmUtil {
10
+ // 获取 registry 信息
11
+ static getNpmRegistry(isOriginal = false) {
12
+ return isOriginal ? 'https://registry.npmjs.org' : 'https://registry.npm.taobao.org';
13
+ }
14
+ //获取npm最新版本号
15
+ static async getLatestVersion(packageName, origin = NpmUtil.getNpmRegistry(true)) {
16
+ log_1.log.debug('链接' + origin + '/' + packageName);
17
+ const { data } = await (0, axios_1.default)({
18
+ method: 'get',
19
+ url: origin + '/' + packageName,
20
+ });
21
+ const version = data['dist-tags'].latest;
22
+ return version;
23
+ }
24
+ //获取npm包在文件中的名字
25
+ static getPackageDirName(packageName, version) {
26
+ return '_' + packageName + '@' + version + '@' + packageName;
27
+ }
28
+ }
29
+ exports.NpmUtil = NpmUtil;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "quan-cli",
3
- "version": "1.0.0",
4
- "description": "",
3
+ "version": "1.0.1",
4
+ "description": "一个用于用于下载包的简易脚手架",
5
+ "homepage": "https://gitee.com/luckqq/quan-cli",
5
6
  "main": "index.js",
6
7
  "bin": {
7
8
  "quan-cli": "./bin/index.js"
@@ -136,7 +136,7 @@ export class InitAction {
136
136
  data: { data },
137
137
  } = await axios({
138
138
  method: 'get',
139
- url: 'http://101.42.154.196/quan-cli/getAllTemplate',
139
+ url: 'http://luckqq.xyz/quan-cli/getAllTemplate',
140
140
  });
141
141
  this.templates = data;
142
142
  }