@yaoxfly/cli 1.0.0
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/LICENSE +21 -0
- package/bin/create.js +147 -0
- package/bin/index.js +24 -0
- package/bin/utils.js +33 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 yaoxfly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/create.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.create = void 0;
|
|
39
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const fs_1 = __importDefault(require("fs"));
|
|
42
|
+
const ora_1 = __importDefault(require("ora"));
|
|
43
|
+
const download_git_repo_1 = __importDefault(require("download-git-repo"));
|
|
44
|
+
const log_symbols_1 = __importDefault(require("log-symbols"));
|
|
45
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
46
|
+
const utils_1 = require("./utils");
|
|
47
|
+
const tips = (param) => {
|
|
48
|
+
const { install, installMode, projectName } = param || {};
|
|
49
|
+
console.log(log_symbols_1.default.success, chalk_1.default.green('The project is initialized'));
|
|
50
|
+
console.log('\n To get started');
|
|
51
|
+
console.log(`\n cd ${projectName}`);
|
|
52
|
+
!install && console.log(`\n ${installMode} i`);
|
|
53
|
+
console.log(`\n npm run serve`);
|
|
54
|
+
};
|
|
55
|
+
const create = (projectName, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const { force } = options || {};
|
|
57
|
+
if (!force && fs_1.default.existsSync(projectName)) {
|
|
58
|
+
console.log(chalk_1.default.red("Error, In this directory, the project name already exsits !"));
|
|
59
|
+
console.log(chalk_1.default.green('You can use option -f to force delete the directory except for direct mode !'));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const template = Promise.resolve().then(() => __importStar(require(`${__dirname}/../template`)));
|
|
63
|
+
const templateObj = yield template;
|
|
64
|
+
const choices = [];
|
|
65
|
+
Object.keys(templateObj.default).forEach(key => {
|
|
66
|
+
choices.push(`${key} (${templateObj.default[key].description})`);
|
|
67
|
+
});
|
|
68
|
+
const param = [
|
|
69
|
+
{
|
|
70
|
+
type: 'list',
|
|
71
|
+
message: '请选择一个预设',
|
|
72
|
+
name: 'templateName',
|
|
73
|
+
choices: choices,
|
|
74
|
+
filter: (val) => val.split(' ')[0]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: 'input',
|
|
78
|
+
message: '请输入项目描述',
|
|
79
|
+
name: 'description',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'input',
|
|
83
|
+
message: '请输入作者名称',
|
|
84
|
+
name: 'author',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: 'confirm',
|
|
88
|
+
message: '请确认是否安装npm包?',
|
|
89
|
+
name: 'install',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: 'list',
|
|
93
|
+
message: '请选择一个安装方式',
|
|
94
|
+
name: 'installMode',
|
|
95
|
+
default: 'pnpm',
|
|
96
|
+
choices: ['pnpm', 'npm', 'yarn'],
|
|
97
|
+
when: (answers) => {
|
|
98
|
+
const { install } = answers;
|
|
99
|
+
return install;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
const answers = yield inquirer_1.default.prompt(param);
|
|
104
|
+
if (fs_1.default.existsSync(projectName)) {
|
|
105
|
+
console.log(chalk_1.default.white('\n Start Delete original item... \n'));
|
|
106
|
+
const spinner = (0, ora_1.default)("Delete...");
|
|
107
|
+
spinner.start();
|
|
108
|
+
yield fs_extra_1.default.remove(projectName);
|
|
109
|
+
spinner.succeed();
|
|
110
|
+
}
|
|
111
|
+
const { templateName, description, author, install, installMode } = answers || {};
|
|
112
|
+
const url = templateObj[templateName].url;
|
|
113
|
+
const direct = url.split(':')[0] === 'direct';
|
|
114
|
+
console.log(chalk_1.default.white('\n Start generating... \n'));
|
|
115
|
+
const spinner = (0, ora_1.default)("Downloading...");
|
|
116
|
+
spinner.start();
|
|
117
|
+
(0, download_git_repo_1.default)(url, projectName, { clone: direct }, (err) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
if (err) {
|
|
119
|
+
spinner.fail();
|
|
120
|
+
console.log(chalk_1.default.red(`Generation failed. ${err}`));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const meta = {
|
|
124
|
+
description: description,
|
|
125
|
+
name: projectName.replace(/\/|\\/g, '-'),
|
|
126
|
+
author: author
|
|
127
|
+
};
|
|
128
|
+
const filePath = `${projectName}/package.json`;
|
|
129
|
+
const packageJsonData = (0, utils_1.readFile)(filePath);
|
|
130
|
+
Object.assign(packageJsonData, meta);
|
|
131
|
+
fs_1.default.writeFileSync(filePath, JSON.stringify(packageJsonData, null, 2));
|
|
132
|
+
spinner.succeed();
|
|
133
|
+
if (install) {
|
|
134
|
+
const stdout = yield (0, utils_1.shellExec)({
|
|
135
|
+
directive: `${installMode} i`,
|
|
136
|
+
cwd: projectName,
|
|
137
|
+
loading: 'Install...',
|
|
138
|
+
log: `${installMode} i`
|
|
139
|
+
});
|
|
140
|
+
console.log(stdout);
|
|
141
|
+
tips({ projectName, install, installMode });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
tips({ projectName, install, installMode });
|
|
145
|
+
}));
|
|
146
|
+
});
|
|
147
|
+
exports.create = create;
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const create_1 = require("./create");
|
|
10
|
+
const program = new commander_1.Command();
|
|
11
|
+
program
|
|
12
|
+
.version(require('../package').version)
|
|
13
|
+
.name('yx-cli');
|
|
14
|
+
program
|
|
15
|
+
.command('create <project-name>')
|
|
16
|
+
.description('create a new project')
|
|
17
|
+
.option('-f --force', 'if it exist, overwrite directory')
|
|
18
|
+
.action((projectName, options) => {
|
|
19
|
+
(0, create_1.create)(projectName, options);
|
|
20
|
+
});
|
|
21
|
+
program.on('--help', () => {
|
|
22
|
+
console.log(`\r\n Run ${chalk_1.default.green(`yx-cli <command> --help`)} to understand the details\r\n `);
|
|
23
|
+
});
|
|
24
|
+
program.parse(process.argv);
|
package/bin/utils.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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.shellExec = exports.readFile = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const readFile = (filePath) => {
|
|
11
|
+
const file = (0, fs_1.readFileSync)(filePath);
|
|
12
|
+
return JSON.parse(file.toString());
|
|
13
|
+
};
|
|
14
|
+
exports.readFile = readFile;
|
|
15
|
+
const shellExec = (config) => {
|
|
16
|
+
const { directive, cwd, loading, log } = config || {};
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
console.log(`\n ${log} \n`);
|
|
19
|
+
const spinner = (0, ora_1.default)(loading);
|
|
20
|
+
spinner.start();
|
|
21
|
+
(0, child_process_1.exec)(directive, { cwd }, (error, stdout) => {
|
|
22
|
+
if (error) {
|
|
23
|
+
spinner.fail();
|
|
24
|
+
console.error(error);
|
|
25
|
+
reject(error);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
resolve(stdout);
|
|
29
|
+
spinner.succeed();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.shellExec = shellExec;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yaoxfly/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "脚手架工具,开箱即用",
|
|
5
|
+
"main": "bin",
|
|
6
|
+
"private": false,
|
|
7
|
+
"author": "yaoxfly",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "tsc -w",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"lint": "eslint . --ext .js,.ts, --fix"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"yx-cli": "./bin/index.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"cli",
|
|
25
|
+
"yaoxfly",
|
|
26
|
+
"vue",
|
|
27
|
+
"vitepress",
|
|
28
|
+
"vite"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/yaoxfly/yaoxfly-cli.git"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^18.8.5",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
38
|
+
"eslint": "^8.25.0",
|
|
39
|
+
"typescript": "^4.8.4"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"chalk": "4.1.2",
|
|
43
|
+
"commander": "9.4.1",
|
|
44
|
+
"download-git-repo": "3.0.2",
|
|
45
|
+
"fs-extra": "10.1.0",
|
|
46
|
+
"inquirer": "8.0.0",
|
|
47
|
+
"log-symbols": "4.0.0",
|
|
48
|
+
"ora": "5.2.0"
|
|
49
|
+
}
|
|
50
|
+
}
|