@done-coding/cli-inject 0.1.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @done-coding/cli-inject
2
+
3
+ done-coding注入信息文件命令行工具
4
+
5
+ ## 使用
6
+
7
+ npm install @done-coding/cli-inject
package/es/cli.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { createCli as e } from "./main.mjs";
3
+ e();
package/es/handler.mjs ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import u from "node:path";
3
+ import r from "node:fs";
4
+ import d from "lodash.get";
5
+ import j from "lodash.set";
6
+ import e from "chalk";
7
+ const P = async (a) => {
8
+ const { sourceJsonFilePath: c, injectKeyPath: g, injectInfoFilePath: l } = a, i = process.cwd();
9
+ if (!c.endsWith(".json"))
10
+ return console.log(e.red("源文件必须是json格式")), process.exit(1);
11
+ if (!l.endsWith(".json"))
12
+ return console.log(e.red("注入文件必须是json格式")), process.exit(1);
13
+ const h = u.resolve(i, c), p = JSON.parse(
14
+ r.readFileSync(h, "utf-8")
15
+ ), s = g.reduce((n, f) => (j(n, f, d(p, f)), n), {}), o = u.resolve(i, l), t = JSON.stringify(s, null, 2);
16
+ if (r.existsSync(o)) {
17
+ const n = r.readFileSync(o, "utf-8");
18
+ if (t === n)
19
+ return console.log(e.green("注入文件已存在且内容相同,无需重复注入")), s;
20
+ console.log(e.green("文件内容变化,开始覆盖注入文件"));
21
+ } else
22
+ console.log(e.green("开始注入文件"));
23
+ return r.writeFileSync(o, t), console.log(
24
+ e.green(`文件注入成功过: ${o}`),
25
+ e.blue(t)
26
+ ), s;
27
+ };
28
+ export {
29
+ P as handler
30
+ };
package/es/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { handler as e } from "./handler.mjs";
3
+ import { command as m } from "./main.mjs";
4
+ export {
5
+ m as command,
6
+ e as handler
7
+ };
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ const n = {
3
+ version: "0.1.0",
4
+ name: "@done-coding/cli-inject",
5
+ description: "注入信息文件命令行工具"
6
+ };
7
+ export {
8
+ n as default
9
+ };
package/es/main.mjs ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import c from "yargs";
3
+ import { hideBin as l } from "yargs/helpers";
4
+ import { handler as n } from "./handler.mjs";
5
+ import s from "chalk";
6
+ import i from "./injectInfo.json.mjs";
7
+ const m = () => ({
8
+ sourceJsonFilePath: {
9
+ type: "string",
10
+ alias: "s",
11
+ describe: "信息源json文件相对路径",
12
+ default: "./package.json"
13
+ },
14
+ injectKeyPath: {
15
+ type: "array",
16
+ alias: "k",
17
+ describe: "需要注入的key路径",
18
+ default: ["name", "version", "description"]
19
+ },
20
+ injectInfoFilePath: {
21
+ type: "string",
22
+ alias: "i",
23
+ describe: "注入信息文件路径",
24
+ default: "./src/injectInfo.json"
25
+ }
26
+ }), t = "inject", d = (e, o) => {
27
+ console.log(e ? s.red(e) : s.red(o.message)), process.exit(1);
28
+ }, p = i.description, g = `Usage: $0 ${t} [options]`, f = "Usage: $0 [options]", r = (e, o) => {
29
+ const a = m();
30
+ return e.strict().usage(o).help("help").version(i.version).alias("v", "version").alias("h", "help").options(a).fail(d).argv;
31
+ }, h = (e) => r(e, g), k = {
32
+ command: t,
33
+ describe: p,
34
+ builder: h,
35
+ handler: n
36
+ }, C = async () => {
37
+ const e = c(l(process.argv)), o = await r(e, f);
38
+ return n(o);
39
+ };
40
+ export {
41
+ k as command,
42
+ C as createCli
43
+ };
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@done-coding/cli-inject",
3
+ "version": "0.1.0",
4
+ "description": "注入信息文件命令行工具",
5
+ "private": false,
6
+ "module": "es/index.mjs",
7
+ "type": "module",
8
+ "types": "types/index.d.ts",
9
+ "bin": {
10
+ "dc-inject": "es/cli.mjs"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./es/index.mjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "es",
19
+ "lib",
20
+ "types",
21
+ "gif"
22
+ ],
23
+ "scripts": {
24
+ "clean": "rimraf es lib types",
25
+ "predev": "pnpm run clean",
26
+ "dev": "vite build --watch",
27
+ "prebuild": "pnpm run clean",
28
+ "build": "vite build",
29
+ "prepack": "pnpm build"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://gitee.com/justsosu/done-coding-cli.git",
34
+ "directory": "packages/inject"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "author": "JustSoSu",
40
+ "license": "MIT",
41
+ "sideEffects": false,
42
+ "devDependencies": {
43
+ "@types/lodash.get": "^4.4.9",
44
+ "@types/lodash.set": "^4.3.9",
45
+ "@types/node": "^20.0.0",
46
+ "@types/prompts": "^2.4.6",
47
+ "@types/yargs": "^17.0.28",
48
+ "rimraf": "^6.0.1",
49
+ "typescript": "^5.2.2",
50
+ "vite": "^4.4.11",
51
+ "vite-plugin-dts": "^3.6.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=16.0.0"
55
+ },
56
+ "dependencies": {
57
+ "chalk": "^5.3.0",
58
+ "lodash.get": "^4.4.2",
59
+ "lodash.set": "^4.3.2",
60
+ "prompts": "^2.4.2",
61
+ "yargs": "^17.7.2"
62
+ },
63
+ "gitHead": "86e1d77d045ee4bbf2c48c4e7c55ae79ae29939c"
64
+ }
package/types/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Options } from './utils';
2
+ import type { ArgumentsCamelCase } from "yargs";
3
+ export declare const handler: (argv: ArgumentsCamelCase<Options>) => Promise<Record<string, any>>;
@@ -0,0 +1,2 @@
1
+ export { handler } from "./handler";
2
+ export { command } from "./main";
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ "version": "0.1.0",
3
+ "name": "@done-coding/cli-inject",
4
+ "description": "注入信息文件命令行工具"
5
+ };
6
+
7
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { CommandModule } from "yargs";
2
+ import type { Options } from './utils';
3
+ export declare const command: CommandModule<Options, Options>;
4
+ export declare const createCli: () => Promise<Record<string, any>>;
@@ -0,0 +1 @@
1
+ export * from "./types";
@@ -0,0 +1,8 @@
1
+ export interface Options {
2
+ /** json文件相对路径 */
3
+ sourceJsonFilePath: string;
4
+ /** 注入的key路径 */
5
+ injectKeyPath: string[];
6
+ /** 注入信息文件路径 */
7
+ injectInfoFilePath: string;
8
+ }