@standards/cli 0.0.0-stage → 1.0.0-alpha.382
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 +111 -0
- package/README.md +85 -2
- package/dist/bin.mjs +2047 -0
- package/dist/builder-shorthand-DPVmGTec.mjs +236 -0
- package/dist/engine-imports-K-yySYo3.mjs +173 -0
- package/dist/palette-D63ag-eX.mjs +148 -0
- package/dist/scopes-Bqw1v3wB.mjs +122 -0
- package/dist/source-files-D2Bdfvhx.mjs +76 -0
- package/package.json +57 -3
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
|
|
3
|
+
import { readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
//#region src/codemod/source-files.ts
|
|
7
|
+
const IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
8
|
+
"node_modules",
|
|
9
|
+
"dist",
|
|
10
|
+
".next",
|
|
11
|
+
".turbo",
|
|
12
|
+
".git",
|
|
13
|
+
"coverage"
|
|
14
|
+
]);
|
|
15
|
+
const SOURCE_FILE = /\.(?:[cm]?tsx?|[cm]?jsx?)$/;
|
|
16
|
+
const DECLARATION_FILE = /\.d\.[cm]?ts$/;
|
|
17
|
+
function scriptKindOf(fileName) {
|
|
18
|
+
if (/\.tsx$/.test(fileName)) return ts.ScriptKind.TSX;
|
|
19
|
+
if (/\.jsx$/.test(fileName)) return ts.ScriptKind.JSX;
|
|
20
|
+
if (/\.[cm]?js$/.test(fileName)) return ts.ScriptKind.JS;
|
|
21
|
+
return ts.ScriptKind.TS;
|
|
22
|
+
}
|
|
23
|
+
/** One TS or JS file as a tree, with its first parse error if it has one. */
|
|
24
|
+
function parseSourceFile(text, fileName) {
|
|
25
|
+
const file = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, scriptKindOf(fileName));
|
|
26
|
+
const first = file.parseDiagnostics?.[0];
|
|
27
|
+
if (first === void 0) return { file };
|
|
28
|
+
return {
|
|
29
|
+
file,
|
|
30
|
+
error: `${fileName}: cannot parse (${ts.flattenDiagnosticMessageText(first.messageText, " ")})`
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function collectInto(path, accept, into) {
|
|
34
|
+
if ((await stat(path)).isFile()) {
|
|
35
|
+
if (accept(path)) into.push(path);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
for (const entry of await readdir(path)) if (!IGNORED_DIRS.has(entry)) await collectInto(join(path, entry), accept, into);
|
|
39
|
+
}
|
|
40
|
+
function isSourceFile(path) {
|
|
41
|
+
return SOURCE_FILE.test(path) && !DECLARATION_FILE.test(path);
|
|
42
|
+
}
|
|
43
|
+
/** Every file under `paths` that `accept` takes, build output and dependencies left out. */
|
|
44
|
+
async function collectFiles(paths, accept) {
|
|
45
|
+
const files = [];
|
|
46
|
+
for (const path of paths) await collectInto(path, accept, files);
|
|
47
|
+
return files;
|
|
48
|
+
}
|
|
49
|
+
/** Applies non-overlapping edits to `text`, last offset first so earlier ones stay valid. */
|
|
50
|
+
function applyEdits(text, edits) {
|
|
51
|
+
let output = text;
|
|
52
|
+
for (const edit of [...edits].sort((x, y) => y.start - x.start)) output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runs `rewrite` on every source file under `paths`, writes back the ones it
|
|
57
|
+
* changed when `write` is set, and hands every result back for the report.
|
|
58
|
+
*/
|
|
59
|
+
function rewriteSourceFiles(paths, write, rewrite) {
|
|
60
|
+
return rewriteFiles(paths, isSourceFile, write, rewrite);
|
|
61
|
+
}
|
|
62
|
+
/** `rewriteSourceFiles` over the files `accept` takes, whatever their language. */
|
|
63
|
+
async function rewriteFiles(paths, accept, write, rewrite) {
|
|
64
|
+
const results = [];
|
|
65
|
+
for (const path of await collectFiles(paths, accept)) {
|
|
66
|
+
const result = rewrite(await readFile(path, "utf8"), path);
|
|
67
|
+
if (write && result.error === void 0 && result.changed > 0) await writeFile(path, result.output);
|
|
68
|
+
results.push({
|
|
69
|
+
path,
|
|
70
|
+
result
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return results;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { rewriteSourceFiles as i, parseSourceFile as n, rewriteFiles as r, applyEdits as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standards/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-alpha.382",
|
|
4
|
+
"description": "CLI tool to interact with Standards API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"standards": "./dist/bin.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"cli-table3": "^0.6.5",
|
|
19
|
+
"commander": "^13.1.0",
|
|
20
|
+
"typescript": "^5.6.3",
|
|
21
|
+
"ws": "8.21.1",
|
|
22
|
+
"@standards/client": "1.0.0-alpha.382",
|
|
23
|
+
"@standards/constants": "1.0.0-alpha.382",
|
|
24
|
+
"@standards/schema": "1.0.0-alpha.382"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^25.6.0",
|
|
28
|
+
"@types/ws": "8.18.1",
|
|
29
|
+
"jsdom": "^25.0.1",
|
|
30
|
+
"tsdown": "^0.23.0",
|
|
31
|
+
"typescript7": "npm:typescript@^7.0.2",
|
|
32
|
+
"vitest": "^5.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/andyoucreate/standards.git",
|
|
41
|
+
"directory": "packages/cli"
|
|
42
|
+
},
|
|
43
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
44
|
+
"author": "AndYouCreate",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/andyoucreate/standards/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/andyoucreate/standards#readme",
|
|
49
|
+
"standards": {
|
|
50
|
+
"entitlement": "core"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsdown",
|
|
54
|
+
"dev": "tsdown --watch",
|
|
55
|
+
"lint": "biome check .",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"typecheck": "node_modules/typescript7/bin/tsc --noEmit",
|
|
58
|
+
"clean": "rm -rf dist"
|
|
59
|
+
}
|
|
6
60
|
}
|