Skip to content

Commit 80e30d5

Browse files
author
wb_zhangyajin
committed
feat: 0.1.0-beta.2
0 parents  commit 80e30d5

30 files changed

+5271
-0
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
tab_width = 2
14+
15+
16+
[{package.json,*.yml,*.yaml}]
17+
indent_size = 2
18+
19+
[Makefile,*.mk,*.mak}]
20+
indent_style = tab
21+
tab_width = 4
22+
23+
[*.md]
24+
trim_trailing_whitespace = false

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
*~
4+
*.swp
5+
*.log
6+
7+
.vscode
8+
.DS_Store
9+
.idea/
10+
.temp/
11+
12+
dist/
13+
coverage/
14+
node_modules/
15+

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org

bin/cli

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
require("../hack.js");
3+
require("../dist/cli.js");

debug.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* 用于本地开发调试TS
3+
*/
4+
5+
require("./hack.js");
6+
7+
require("ts-node").register({
8+
project: `${__dirname}/tsconfig.json`,
9+
require: ["tsconfig-paths/register"],
10+
});
11+
12+
require(`${__dirname}/src/cli`);

hack.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* 使用ts-node开发时,如果存在三方的类库报错,出现类型 错误 Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
3+
* 可以在这里全局定义
4+
*/
5+
Object.defineProperties(global, {
6+
madge: {
7+
value: require("madge"),
8+
},
9+
});

package.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@ks-dilu/cli",
3+
"version": "0.1.0-beta.2",
4+
"description": "的卢微前端cli工具,支持初始化主子应用",
5+
"main": "dist/index.js",
6+
"files": [
7+
"dist",
8+
"README.md",
9+
"LICENSE",
10+
"package.json",
11+
"template",
12+
"hack.js"
13+
],
14+
"bin": {
15+
"dilu": "bin/cli"
16+
},
17+
"types": "dist/types/index.d.ts",
18+
"scripts": {
19+
"prepare": "ts-patch install -s",
20+
"dev": "node debug.js",
21+
"clean-build": "npx tsc --build --clean && rm -rf ./dist",
22+
"compile": "npx tsc --build --verbose --pretty",
23+
"build": "npm run clean-build && npm run compile"
24+
},
25+
"devDependencies": {
26+
"@types/fs-extra": "^9.0.13",
27+
"@types/inquirer": "^8.2.1",
28+
"@types/lodash": "^4.14.182",
29+
"@types/madge": "^5.0.0",
30+
"@types/node": "^18.0.0",
31+
"@types/yargs": "^17.0.10",
32+
"eslint": "^8.18.0",
33+
"ts-node": "^10.8.1",
34+
"ts-patch": "^2.0.1",
35+
"tsconfig-paths": "^4.0.0",
36+
"typescript": "^4.7.4",
37+
"typescript-transform-paths": "^3.3.1"
38+
},
39+
"dependencies": {
40+
"chalk": "^4.1.2",
41+
"cli-progress": "^3.11.2",
42+
"cross-spawn": "7.0.3",
43+
"debug": "^3.2.7",
44+
"dependency-tree": "^8.1.2",
45+
"download": "^8.0.0",
46+
"ejs": "^3.1.8",
47+
"fs-extra": "^10.1.0",
48+
"globby": "^6.1.0",
49+
"import-modules": "^3.1.0",
50+
"inquirer": "^8.2.4",
51+
"lodash": "^4.17.21",
52+
"log-symbols": "^4.1.0",
53+
"madge": "^5.0.1",
54+
"mkdirp": "^1.0.4",
55+
"ora": "^5.4.1",
56+
"plugin-extend": "^0.1.7",
57+
"semver": "^7.3.7",
58+
"shelljs": "^0.8.5",
59+
"vinyl-fs": "^3.0.3",
60+
"vue-template-compiler": "2.6.11",
61+
"yargs": "^17.5.1"
62+
},
63+
"repository": {
64+
"type": "git",
65+
"url": "git@github.com:Kwai-Eshop/dilu-cli.git"
66+
},
67+
"keywords": [
68+
"dilu"
69+
],
70+
"publishConfig": {
71+
"access": "public",
72+
"registry": "https://registry.npmjs.org"
73+
}
74+
}

postInstall.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("111");

src/cli.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import yargs, { boolean } from "yargs";
2+
import { hideBin } from "yargs/helpers";
3+
import importModules from "import-modules";
4+
const commands = importModules("cmds", {
5+
fileExtensions: [".js", ".ts"],
6+
}) as Record<string, any>;
7+
8+
const argvs = hideBin(process.argv);
9+
10+
let yargsInstance = yargs(argvs);
11+
12+
const commandsKey = Object.keys(commands);
13+
14+
yargsInstance = commandsKey.reduce((pre, current) => {
15+
return pre.command(commands[current]);
16+
}, yargsInstance);
17+
18+
yargsInstance.version("v", require("../package.json").version).help("h").argv;
19+
20+
// 没有参数是默认显示帮助信息
21+
if (argvs.length == 0) {
22+
yargsInstance.showHelp();
23+
}

src/cmds/create.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { checkAndDownPkg } from "@/core/remote";
2+
import { CommandBuilder } from "yargs";
3+
import {
4+
createScaffold,
5+
initScaffoldNpm,
6+
isDiluPluginPkg,
7+
} from "../create/index";
8+
9+
export const command: string = "create [templatePkgName]";
10+
export const desc = "创建DL(的卢)主子应用";
11+
export const builder: CommandBuilder = {};
12+
13+
export const handler = async function (argv) {
14+
try {
15+
if (argv.templatePkgName && isDiluPluginPkg(argv.templatePkgName)) {
16+
await checkAndDownPkg(argv.templatePkgName);
17+
}
18+
await checkAndDownPkg("@ks-dilu/cli-template-micro-base");
19+
await checkAndDownPkg("@ks-dilu/cli-template-master-base");
20+
} catch {}
21+
22+
try {
23+
await createScaffold();
24+
} catch {}
25+
return void 0;
26+
};

src/cmds/scaffold.ts_bak

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// import { CommandBuilder } from "yargs";
2+
// import { execTemplate } from "@/create";
3+
// export const command: string = "scaffold";
4+
// export const desc = "创建的卢应用的插件(脚手架)模板";
5+
// export const builder: CommandBuilder = {};
6+
// export const handler = async function (argv) {
7+
// await execTemplate("@ks-dilu/cli-template-scaffold-template");
8+
// return void 0;
9+
// };

src/cmds/split.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Split from "@/split";
2+
3+
export const command: string = `split`;
4+
export const desc =
5+
"老工程拆分工具,根据提供的入口自动分析依赖,提取相关文件到指定的目录";
6+
export const builder = (yargs) => {
7+
return yargs
8+
.check((argv) => {
9+
if (!argv.enter) {
10+
throw new Error("请填写入口参数");
11+
}
12+
13+
return true;
14+
})
15+
.options({
16+
enter: {
17+
alias: "e",
18+
desc: "入口路径(相对路径)",
19+
string: true,
20+
},
21+
projectName: {
22+
alias: "n",
23+
desc: "文件夹名称",
24+
string: true,
25+
},
26+
outputDir: {
27+
alias: "o",
28+
desc: "输出目录",
29+
string: true,
30+
},
31+
});
32+
};
33+
export const handler = function (argv) {
34+
// console.log("功能开发中,敬请期待……");
35+
36+
new Split(argv);
37+
};

src/core/log.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use strict";
2+
const logSymbols = require("log-symbols");
3+
4+
type LogFn = (msg: string) => void;
5+
export interface ILogger {
6+
log: (type: string, msg: string) => void;
7+
error: LogFn;
8+
info: LogFn;
9+
success: LogFn;
10+
warning: LogFn;
11+
write: LogFn;
12+
}
13+
14+
const logger: ILogger = {
15+
log(type, msg) {
16+
var symbols = logSymbols[type] || logSymbols.info;
17+
18+
console.log(symbols, msg);
19+
},
20+
error(msg) {
21+
this.log("error", msg);
22+
},
23+
info(msg) {
24+
this.log("info", msg);
25+
},
26+
success(msg) {
27+
this.log("success", msg);
28+
},
29+
warning(msg) {
30+
this.log("warning", msg);
31+
},
32+
write(msg) {
33+
console.log(msg);
34+
},
35+
};
36+
37+
export default logger;

0 commit comments

Comments
 (0)