@lntvow/dev 6.1.1 → 6.3.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 +65 -0
- package/dist/cli.mjs +1 -1
- package/dist/configs/.prettierignore +7 -1
- package/dist/configs/{.npmrc → npmrc} +0 -3
- package/dist/main-BIi5AhnC.mjs +5 -0
- package/package.json +14 -15
- package/dist/cli.d.mts +0 -1
- package/dist/main-D-WPidsG.mjs +0 -1
- /package/dist/configs/{.gitignore → gitignore} +0 -0
package/README.md
CHANGED
|
@@ -19,3 +19,68 @@
|
|
|
19
19
|
[](https://www.typescriptlang.org/)
|
|
20
20
|
[](https://www.npmjs.com/package/@lntvow/dev)
|
|
21
21
|
[](https://www.npmjs.com/package/@lntvow/dev)
|
|
22
|
+
|
|
23
|
+
A small CLI that sets up a development environment: copies config files, installs the shared dev dependencies and adds the standard npm scripts.
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Node.js **22.0.0** or later
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Run it in the project you want to set up:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# pnpm
|
|
35
|
+
pnpm dlx @lntvow/dev init
|
|
36
|
+
|
|
37
|
+
# npm
|
|
38
|
+
npx @lntvow/dev init
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or install it globally:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pnpm add -g @lntvow/dev
|
|
45
|
+
dev init
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `dev init`
|
|
49
|
+
|
|
50
|
+
Initializes the current directory:
|
|
51
|
+
|
|
52
|
+
1. Copies the template config files (existing files are left untouched).
|
|
53
|
+
2. Installs `@lntvow/cli`, `@lntvow/eslint-config`, `eslint`, `prettier` and `typescript` as dev dependencies.
|
|
54
|
+
3. Merges the default scripts into `package.json` (existing scripts win).
|
|
55
|
+
|
|
56
|
+
Options:
|
|
57
|
+
|
|
58
|
+
| Option | Description |
|
|
59
|
+
| ------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `--no-temp` | Skip copying template files |
|
|
61
|
+
| `--no-scripts` | Skip updating `package.json` scripts |
|
|
62
|
+
| `--pm <pnpm\|yarn\|npm>` | Package manager; auto-detected from the lockfile / `npm_config_user_agent`, otherwise prompted |
|
|
63
|
+
|
|
64
|
+
Files copied when missing:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
.editorconfig
|
|
68
|
+
.gitignore
|
|
69
|
+
.npmrc
|
|
70
|
+
.prettierignore
|
|
71
|
+
.prettierrc
|
|
72
|
+
.vscode/settings.json
|
|
73
|
+
eslint.config.mjs
|
|
74
|
+
README.md
|
|
75
|
+
tsconfig.json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Scripts added when missing: `prepare`, `rimraf`, `upgrade`, `tidy`, `commit`, `prerelease`, `release`, `changelog`, `version`, `lint:eslint`, `lint:tsc`, `lint`.
|
|
79
|
+
|
|
80
|
+
### `dev release`
|
|
81
|
+
|
|
82
|
+
Pulls, stages, commits and pushes the current repository. The commit message is the date in `YYYYMMDD` form.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
[MIT](LICENSE)
|
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
(e=>e.major>
|
|
2
|
+
(e=>e.major>22||e.major===22&&e.minor>=0)((e=>{let[t=`0`,n=`0`]=e.split(`.`);return{major:Number(t),minor:Number(n)}})(process.versions.node))||(process.stderr.write(`@lntvow/dev: Node.js v22.0+ is required (current: v${process.versions.node}).\nIf you use nvm, run:\n nvm install 22\n nvm use 22\n nvm alias default 22\n`),process.exit(1)),import(`./main-BIi5AhnC.mjs`);export{};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{Option as e,program as t}from"commander";import{isCancel as n,select as r}from"@clack/prompts";import{execFileSync as i}from"node:child_process";import{copyFileSync as a,existsSync as o,lstatSync as s,mkdirSync as c,readFileSync as l,readdirSync as u,rmSync as d,rmdirSync as f,writeFileSync as p}from"node:fs";import{basename as m,dirname as h,relative as g,resolve as _}from"node:path";import v from"picocolors";import{fileURLToPath as y}from"node:url";import b from"simple-git";var x=`@lntvow/dev`,S=`6.3.0`;const C={gitignore:`.gitignore`,npmrc:`.npmrc`},w={info:e=>console.log(v.blue(`● ${e}`)),success:e=>console.log(v.green(`✓ ${e}`)),warn:e=>console.log(v.yellow(`▲ ${e}`)),error:e=>console.error(v.red(`✗ ${e}`))};function T(e,t){let n=e instanceof Error?e.message:String(e);w.error(t?`${t}: ${n}`:n),process.exitCode=1}function E(e,t,n={}){return i(e,t,{stdio:`inherit`,shell:process.platform===`win32`,...n})}async function D(){for(let{file:e,manager:t}of[{file:`pnpm-lock.yaml`,manager:`pnpm`},{file:`yarn.lock`,manager:`yarn`},{file:`package-lock.json`,manager:`npm`}])if(o(_(process.cwd(),e)))return t;let e=process.env.npm_config_user_agent||``;return e.startsWith(`pnpm`)?`pnpm`:e.startsWith(`yarn`)?`yarn`:e.startsWith(`npm`)?`npm`:O()}async function O(){if(!process.stdin.isTTY)throw Error(`No lock file found and stdin is not interactive. Pass --pm <pnpm|yarn|npm>.`);let e=await r({message:`No lock file found. Please select a package manager`,options:[{label:`pnpm`,value:`pnpm`},{label:`yarn`,value:`yarn`},{label:`npm`,value:`npm`}],initialValue:`pnpm`});if(n(e))throw Error(`Package manager selection canceled.`);return e}function k(e,t,n={created:[],skipped:[]}){let r=s(e);if(r.isSymbolicLink())throw Error(`Template contains a symbolic link, which is not supported: ${e}`);if(r.isDirectory()){if(m(e)===`node_modules`)return n;c(t,{recursive:!0}),u(e).forEach(r=>{k(_(e,r),_(t,r),n)})}else{let r=_(h(t),C[m(t)]??m(t));if(o(r))return n.skipped.push(r),n;a(e,r),n.created.push(r)}return n}const A={prepare:`cli hooks`,rimraf:`cli rimraf ./node_modules/`,upgrade:`cli upgrade -u -x "@types/node" && pnpm install`,tidy:`cli tidy`,commit:`git add -A && cli commit`,prerelease:`pnpm lint && pnpm run --if-present test`,release:`git add -A && cli release -r -a`,changelog:`cli changelog -p angular -i CHANGELOG.md -s`,version:`pnpm changelog && git add -A`,"lint:eslint":`eslint --fix --cache`,"lint:tsc":`tsc --noEmit`,lint:`cli run lint:eslint lint:tsc`},j=[`@lntvow/cli`,`@lntvow/eslint-config`,`eslint`,`prettier`,`typescript`].sort((e,t)=>e.localeCompare(t));function M(t){t.command(`init`).description(`init project`).option(`-t, --temp`,`copy template files`,!0).option(`--no-temp`,`not copy template files`).option(`-s, --scripts`,`init scripts`,!0).option(`--no-scripts`,`not init scripts`).addOption(new e(`--pm <manager>`,`package manager (auto-detect from lockfile/userAgent; prompt if ambiguous)`).choices([`pnpm`,`yarn`,`npm`])).action(N)}async function N(e){w.success(`Init project by @lntvow/dev`),w.info(`Cwd is ${process.cwd()}`);let{temp:t,scripts:n,pm:r}=e,i={created:[],skipped:[]},a=null;try{a=P(),t&&I(i),await B(r),n&&R(),w.success(`Project initialization completed successfully!`)}catch(e){L(i.created),F(a),T(e,`Initialization failed`)}}function P(){let e=_(process.cwd(),`package.json`);if(o(e))return null;let t=m(process.cwd()).toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[-.]+|[-.]+$/g,``)||`project`,n=`${JSON.stringify({name:t,version:`0.0.0`},null,2)}\n`;return p(e,n),w.info(`Created package.json for "${t}"`),n}function F(e){if(!e)return;let t=_(process.cwd(),`package.json`);o(t)&&l(t,`utf8`)===e&&(d(t,{force:!0}),w.warn(`Rolled back generated package.json`))}function I(e){let t=y(new URL(`./configs`,import.meta.url)),n=process.cwd();w.info(`Copying template files from "${t}" to "${n}"`),k(t,n,e);for(let t of e.created)w.info(` created ${g(n,t)}`);for(let t of e.skipped)w.warn(` skipped ${g(n,t)} (already exists)`);w.success(`Template files copied (${e.created.length} created, ${e.skipped.length} skipped)`)}function L(e){if(e.length!==0){for(let t of e){d(t,{force:!0});let e=h(t);if(e!==process.cwd())try{f(e)}catch{}}w.warn(`Rolled back ${e.length} copied template file(s)`)}}function R(){let e,t=_(process.cwd(),`package.json`);try{w.info(`Updating package.json scripts...`),e=l(t,`utf-8`);let n=JSON.parse(e),r={...n,scripts:{...A,...n.scripts}};p(t,z(r,e)),w.success(`Package.json scripts updated successfully`)}catch(n){throw e&&p(t,e),n}}function z(e,t){let n=/^([ \t]+)"/m.exec(t)?.[1],r=t.includes(`\r
|
|
2
|
+
`)?`\r
|
|
3
|
+
`:`
|
|
4
|
+
`;return(n?JSON.stringify(e,null,n):JSON.stringify(e)).replaceAll(`
|
|
5
|
+
`,r)+(/\r?\n$/.test(t)?r:``)}async function B(e){let t=j.map(e=>`${e}@latest`),n=e??await D(),{command:r,args:i}={pnpm:{command:`pnpm`,args:[`add`,`-D`,...t]},yarn:{command:`yarn`,args:[`add`,`-D`,...t]},npm:{command:`npm`,args:[`install`,`-D`,...t]}}[n];w.info(`Installing dependencies: ${r} ${i.join(` `)}`),E(r,i),w.success(`Dependencies installed successfully`)}function V(e){e.command(`release`).description(`git release`).action(H)}async function H(){console.log(v.green(`Release project...`));try{await U(),w.success(`Release completed successfully!`)}catch(e){T(e,`Release failed`)}}async function U(){let e=b(process.cwd()),t=W(/* @__PURE__ */ new Date);await e.pull(),await e.add(`.`),await e.commit(t,[`--no-verify`]),await e.push(`origin`),w.success(`Committed: ${t}`)}function W(e){return`${e.getFullYear()}${String(e.getMonth()+1).padStart(2,`0`)}${String(e.getDate()).padStart(2,`0`)}`}t.name(x).version(S,`-v, --version`,`output the version number`),M(t),V(t),t.parseAsync().catch(T);export{};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/dev",
|
|
3
|
-
"version": "6.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "6.3.0",
|
|
4
|
+
"description": "CLI for scaffolding development environment configs, dependencies and scripts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dev"
|
|
7
7
|
],
|
|
@@ -16,49 +16,48 @@
|
|
|
16
16
|
".": "./dist/cli.mjs",
|
|
17
17
|
"./package.json": "./package.json"
|
|
18
18
|
},
|
|
19
|
-
"types": "./dist/cli.d.mts",
|
|
20
19
|
"bin": {
|
|
21
20
|
"dev": "./dist/cli.mjs",
|
|
22
21
|
"lntvow": "./dist/cli.mjs"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
"dist/configs/*"
|
|
24
|
+
"dist"
|
|
27
25
|
],
|
|
28
26
|
"dependencies": {
|
|
29
27
|
"@clack/prompts": "^1.6.0",
|
|
30
28
|
"commander": "^15.0.0",
|
|
31
|
-
"dayjs": "^1.11.21",
|
|
32
|
-
"local-pkg": "^1.2.1",
|
|
33
29
|
"picocolors": "^1.1.1",
|
|
34
30
|
"simple-git": "^3.36.0"
|
|
35
31
|
},
|
|
36
32
|
"devDependencies": {
|
|
37
|
-
"@lntvow/cli": "
|
|
33
|
+
"@lntvow/cli": "0.3.0",
|
|
38
34
|
"@lntvow/eslint-config": "^10.3.1",
|
|
39
|
-
"@types/node": "^
|
|
35
|
+
"@types/node": "^22.0.0",
|
|
40
36
|
"eslint": "^10.5.0",
|
|
41
37
|
"prettier": "^3.8.4",
|
|
42
38
|
"publint": "^0.3.21",
|
|
43
39
|
"tsdown": "^0.22.3",
|
|
44
40
|
"tsx": "^4.22.4",
|
|
45
|
-
"typescript": "^6.0.3"
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"vitest": "^5.0.5"
|
|
46
43
|
},
|
|
47
44
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
49
|
-
"pnpm": ">=10.0.0"
|
|
45
|
+
"node": ">=22.0.0"
|
|
50
46
|
},
|
|
51
47
|
"scripts": {
|
|
52
48
|
"rimraf": "cli rimraf ./node_modules/",
|
|
53
49
|
"upgrade": "cli upgrade -u -x \"@types/node\" && pnpm install",
|
|
54
50
|
"tidy": "cli tidy",
|
|
55
|
-
"commit": "git add -A && cli
|
|
56
|
-
"
|
|
51
|
+
"commit": "git add -A && cli commit",
|
|
52
|
+
"prerelease": "pnpm lint && pnpm run --if-present test",
|
|
53
|
+
"release": "git add -A && cli release -r -a",
|
|
57
54
|
"changelog": "cli changelog -p angular -i CHANGELOG.md -s",
|
|
58
55
|
"version": "pnpm changelog && git add -A",
|
|
59
56
|
"lint:eslint": "eslint --fix --cache",
|
|
60
57
|
"lint:tsc": "tsc --noEmit",
|
|
61
|
-
"lint": "cli
|
|
58
|
+
"lint": "cli run lint:eslint lint:tsc",
|
|
59
|
+
"pretest": "pnpm build",
|
|
60
|
+
"test": "vitest run",
|
|
62
61
|
"build": "tsdown",
|
|
63
62
|
"dev": "tsx src/cli.ts"
|
|
64
63
|
}
|
package/dist/cli.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/main-D-WPidsG.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Option as e,program as t}from"commander";import{copyFileSync as n,existsSync as r,mkdirSync as i,readFileSync as a,readdirSync as o,statSync as s,writeFileSync as c}from"node:fs";import{basename as l,resolve as u}from"node:path";import{fileURLToPath as d}from"node:url";import{isCancel as f,select as p}from"@clack/prompts";import{execSync as m}from"node:child_process";import h from"picocolors";import g from"dayjs";import _ from"simple-git";var v=`@lntvow/dev`,y=`6.1.1`;const b={prepare:`cli hooks`,rimraf:`cli rimraf ./node_modules/`,upgrade:`cli upgrade -u -x "@types/node" && pnpm install`,tidy:`cli tidy`,commit:`git add -A && cli commit`,release:`pnpm lint && git add -A && cli release package.json -a`,changelog:`cli changelog -p angular -i CHANGELOG.md -s`,version:`pnpm changelog && git add -A`,"lint:eslint":`eslint --fix --cache`,"lint:tsc":`tsc --noEmit`,lint:`cli parallel lint:eslint lint:tsc`},x=[`@lntvow/cli`,`@lntvow/eslint-config`,`eslint`,`prettier`,`typescript`].sort((e,t)=>e.localeCompare(t)),S={info:e=>console.log(h.blue(`● ${e}`)),success:e=>console.log(h.green(`✓ ${e}`)),warn:e=>console.log(h.yellow(`▲ ${e}`)),error:e=>console.log(h.red(`✗ ${e}`))};function C(e,t={}){try{return m(e,{stdio:`inherit`,...t})}catch(t){throw S.error(`命令执行失败: ${e}`),t}}async function w(){for(let{file:e,manager:t}of[{file:`pnpm-lock.yaml`,manager:`pnpm`},{file:`yarn.lock`,manager:`yarn`},{file:`package-lock.json`,manager:`npm`}])if(r(u(process.cwd(),e)))return t;let e=process.env.npm_config_user_agent||``;return e.startsWith(`pnpm`)?`pnpm`:e.startsWith(`yarn`)?`yarn`:T()}async function T(){let e=await p({message:`No lock file found. Please select a package manager`,options:[{label:`pnpm`,value:`pnpm`},{label:`yarn`,value:`yarn`},{label:`npm`,value:`npm`}],initialValue:`pnpm`});if(f(e))throw Error(`Package manager selection canceled.`);return e}function E(e,t){if(s(e).isDirectory()){if(l(e)===`node_modules`)return;i(t,{recursive:!0}),o(e).forEach(n=>{E(u(e,n),u(t,n))})}else{if(r(t))return;n(e,t)}}function D(t){t.command(`init`).description(`init project`).option(`-t, --temp`,`copy template files`,!0).option(`--no-temp`,`not copy template files`).option(`-s, --scripts`,`init scripts`,!0).option(`--no-scripts`,`not init scripts`).addOption(new e(`--pm <manager>`,`package manager (auto-detect from lockfile/userAgent; prompt if ambiguous)`).choices([`pnpm`,`yarn`,`npm`])).action(O)}async function O(e){S.success(`Init project by @lntvow/dev`),S.info(`Cwd is ${process.cwd()}`);let{temp:t,scripts:n,pm:r}=e;try{t&&k(),await j(r),n&&A(),S.success(`Project initialization completed successfully!`)}catch(e){S.error(`Initialization failed: ${e.message}`),process.exit(1)}}function k(){try{let e=d(new URL(`./configs`,import.meta.url)),t=process.cwd();S.info(`Copying template files from "${e}" to "${t}"`),E(e,t),S.success(`Template files copied successfully`)}catch(e){throw S.error(`Failed to copy template files: ${e.message}`),e}}function A(){let e,t=u(process.cwd(),`package.json`);try{S.info(`Updating package.json scripts...`),e=a(t,`utf-8`);let n=JSON.parse(e),r={...n,scripts:{...b,...n.scripts}};c(t,JSON.stringify(r,null,2)),S.success(`Package.json scripts updated successfully`)}catch(n){throw e&&c(t,e),S.error(`Failed to update package.json: ${n.message}`),n}}async function j(e){try{let t=x.map(e=>`${e}@latest`).join(` `),n=e??await w(),r={pnpm:`pnpm add -D ${t}`,yarn:`yarn add -D ${t}`,npm:`npm install -D ${t}`}[n];S.info(`Installing dependencies: ${r}`),C(r),S.success(`Dependencies installed successfully`)}catch(e){throw S.error(`Dependency installation failed: ${e.message}`),e}}function M(e){e.command(`release`).description(`git release`).action(N)}async function N(){console.log(h.green(`Release project...`));try{await P(),S.success(`Release completed successfully!`)}catch(e){S.error(`Release failed: ${e.message}`),process.exit(1)}}async function P(){let e=_(process.cwd());try{let t=g().format(`YYYYMMDD`);await e.pull(),await e.add(`.`),await e.commit(t,[`--no-verify`]),await e.push(`origin`),S.success(`提交成功: ${t}`)}catch(e){S.error(`Git操作失败: ${e.message}`),process.exit(1)}}t.name(v).version(y,`-v, --version`,`output the version number`),D(t),M(t),t.parse();export{};
|
|
File without changes
|