create-packkit 2.4.0 → 2.5.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/package.json +1 -1
- package/src/cli/args.js +2 -0
- package/src/cli/index.js +1 -1
- package/src/core/features/doctor.js +54 -0
- package/src/core/features/index.js +2 -0
- package/src/core/options.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-packkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Highly configurable scaffolder for modern npm packages and CLIs — pick your stack (TS/JS, bundler, tests, linter, CI, releases) from a CLI or a web configurator.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/cli/args.js
CHANGED
|
@@ -56,6 +56,7 @@ export function parseCliArgs(argv) {
|
|
|
56
56
|
'pkg-checks': { type: 'boolean' },
|
|
57
57
|
knip: { type: 'boolean' },
|
|
58
58
|
'size-limit': { type: 'boolean' },
|
|
59
|
+
doctor: { type: 'boolean' },
|
|
59
60
|
jsr: { type: 'boolean' },
|
|
60
61
|
help: { type: 'boolean', short: 'h' },
|
|
61
62
|
version: { type: 'boolean', short: 'v' },
|
|
@@ -86,6 +87,7 @@ export function parseCliArgs(argv) {
|
|
|
86
87
|
if (values['pkg-checks']) overrides.pkgChecks = true;
|
|
87
88
|
if (values.knip) overrides.knip = true;
|
|
88
89
|
if (values['size-limit']) overrides.sizeLimit = true;
|
|
90
|
+
if (values.doctor) overrides.doctor = true;
|
|
89
91
|
if (values.jsr) overrides.jsr = true;
|
|
90
92
|
for (const [flag, key] of Object.entries(NEGATABLE)) {
|
|
91
93
|
if (values[flag]) overrides[key] = false;
|
package/src/cli/index.js
CHANGED
|
@@ -48,7 +48,7 @@ Options:
|
|
|
48
48
|
--workflows <ci|npm-publish|pages|codeql|codecov|stale> (repeatable)
|
|
49
49
|
--deps <renovate|dependabot|none> --license <MIT|Apache-2.0|ISC|none>
|
|
50
50
|
--pkg-checks (publint + are-the-types-wrong) --knip --jsr --canary
|
|
51
|
-
--size-limit (bundle-size budget, libraries)
|
|
51
|
+
--size-limit (bundle-size budget, libraries) --doctor (env check)
|
|
52
52
|
--no-coverage --no-community --no-agents --no-vscode --no-editorconfig
|
|
53
53
|
--schema Print the full option/preset schema as JSON (for tools/agents)
|
|
54
54
|
-h, --help Show this help
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// A tiny environment doctor: checks the local Node and package manager match
|
|
2
|
+
// what this project expects, and warns (never fails) otherwise. `npm run doctor`
|
|
3
|
+
// runs it any time; for private projects it also runs on postinstall. It is NOT
|
|
4
|
+
// wired to postinstall for publishable packages — that would run in every
|
|
5
|
+
// consumer's install.
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
id: 'doctor',
|
|
9
|
+
active: (cfg) => cfg.doctor && !cfg.monorepo,
|
|
10
|
+
apply(cfg) {
|
|
11
|
+
const files = { 'scripts/doctor.mjs': script(cfg) };
|
|
12
|
+
const pkg = { scripts: { doctor: 'node scripts/doctor.mjs' } };
|
|
13
|
+
if (!cfg.publishable) pkg.scripts.postinstall = 'node scripts/doctor.mjs';
|
|
14
|
+
return { files, pkg };
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function script(cfg) {
|
|
19
|
+
return [
|
|
20
|
+
`/* global process, console, URL */`,
|
|
21
|
+
`// Checks your environment matches this project. Warns only — never fails.`,
|
|
22
|
+
`import { readFileSync } from 'node:fs';`,
|
|
23
|
+
``,
|
|
24
|
+
`const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));`,
|
|
25
|
+
`const gte = (a, b) => {`,
|
|
26
|
+
`\tconst pa = String(a).split('.').map(Number);`,
|
|
27
|
+
`\tconst pb = String(b).split('.').map(Number);`,
|
|
28
|
+
`\tfor (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) > (pb[i] || 0);`,
|
|
29
|
+
`\treturn true;`,
|
|
30
|
+
`};`,
|
|
31
|
+
``,
|
|
32
|
+
`let issues = 0;`,
|
|
33
|
+
`const floor = (pkg.engines?.node || '').replace(/[^0-9.]/g, '');`,
|
|
34
|
+
`const node = process.versions.node;`,
|
|
35
|
+
`if (floor && !gte(node, floor)) {`,
|
|
36
|
+
"\tconsole.warn(`⚠ Node ${node} is below the required >=${floor} — run: nvm install ${floor.split('.')[0]}`);",
|
|
37
|
+
`\tissues++;`,
|
|
38
|
+
`} else {`,
|
|
39
|
+
"\tconsole.log(`✓ Node ${node}`);",
|
|
40
|
+
`}`,
|
|
41
|
+
``,
|
|
42
|
+
`const expectedPm = '${cfg.packageManager}';`,
|
|
43
|
+
`const usingPm = (process.env.npm_config_user_agent || '').split('/')[0];`,
|
|
44
|
+
`if (usingPm && usingPm !== expectedPm) {`,
|
|
45
|
+
"\tconsole.warn(`⚠ This project uses ${expectedPm}, but you ran ${usingPm}.`);",
|
|
46
|
+
`\tissues++;`,
|
|
47
|
+
`} else {`,
|
|
48
|
+
"\tconsole.log(`✓ Package manager: ${expectedPm}`);",
|
|
49
|
+
`}`,
|
|
50
|
+
``,
|
|
51
|
+
`if (issues) console.warn('\\nSee the README "Requirements" section to fix these.');`,
|
|
52
|
+
``,
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
@@ -22,6 +22,7 @@ import storybook from './storybook.js';
|
|
|
22
22
|
import community from './community.js';
|
|
23
23
|
import agents from './agents.js';
|
|
24
24
|
import vscode from './vscode.js';
|
|
25
|
+
import doctor from './doctor.js';
|
|
25
26
|
import gitfiles from './gitfiles.js';
|
|
26
27
|
|
|
27
28
|
export default [
|
|
@@ -46,5 +47,6 @@ export default [
|
|
|
46
47
|
community,
|
|
47
48
|
agents,
|
|
48
49
|
vscode,
|
|
50
|
+
doctor,
|
|
49
51
|
gitfiles,
|
|
50
52
|
];
|
package/src/core/options.js
CHANGED
|
@@ -111,6 +111,7 @@ export const OPTIONS = {
|
|
|
111
111
|
pkgChecks: { group: 'quality', type: 'boolean', label: 'Package checks (publint + are-the-types-wrong)', default: false },
|
|
112
112
|
knip: { group: 'quality', type: 'boolean', label: 'Knip (unused files / deps / exports)', default: false },
|
|
113
113
|
sizeLimit: { group: 'quality', type: 'boolean', label: 'size-limit (bundle-size budget, libraries)', default: false },
|
|
114
|
+
doctor: { group: 'quality', type: 'boolean', label: 'Env doctor (warn on Node / package-manager mismatch)', default: false },
|
|
114
115
|
|
|
115
116
|
// ---- lint / format ----
|
|
116
117
|
lint: {
|