@standards/cli 0.0.0-stage → 1.0.0-alpha.384

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.
@@ -0,0 +1,122 @@
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 { r as rewriteFiles } from "./source-files-D2Bdfvhx.mjs";
4
+ import { readFile, writeFile } from "node:fs/promises";
5
+ import { basename, join } from "node:path";
6
+ //#region src/codemod/scopes.ts
7
+ /**
8
+ * Every package that left `@stndrds` for `@standards`: the restricted ones
9
+ * (now on the licensed registry only) and the public ones (now on npmjs and
10
+ * the licensed registry). A historical list: packages created later never had
11
+ * an `@stndrds` name.
12
+ */
13
+ const RENAMED_PACKAGES = [
14
+ "adapter-cache",
15
+ "adapter-kernel",
16
+ "adapter-meilisearch",
17
+ "adapter-nestjs",
18
+ "adapter-oidc-provider",
19
+ "adapter-postgres",
20
+ "adapter-posthog",
21
+ "adapter-redis",
22
+ "adapter-supabase",
23
+ "adapter-vercel-sandbox",
24
+ "auth",
25
+ "blocks",
26
+ "cli",
27
+ "client",
28
+ "constants",
29
+ "ds",
30
+ "engine",
31
+ "fonts",
32
+ "react",
33
+ "runtime",
34
+ "schema",
35
+ "ui"
36
+ ];
37
+ const SCOPE_REGISTRY_LINE = `@standards:registry=https://registry.standards.run/`;
38
+ /**
39
+ * The key line belongs in the user-level `~/.npmrc`, never the project one:
40
+ * pnpm does not expand environment variables in registry credentials read
41
+ * from a project `.npmrc`, so `${STANDARDS_TOKEN}` there reaches the
42
+ * registry as no key at all (401). Earlier runs of this codemod wrote it.
43
+ */
44
+ const PROJECT_AUTH_LINE = /^\s*\/\/registry\.standards\.run\/:_authToken=\$\{[^}]+\}\s*$/;
45
+ /** Public on npmjs too: a project using only these needs no licence and no registry line. */
46
+ const PUBLIC_PACKAGES = /* @__PURE__ */ new Set([
47
+ "cli",
48
+ "client",
49
+ "constants",
50
+ "schema"
51
+ ]);
52
+ const LICENSED_NAME = new RegExp(`@standards/(${RENAMED_PACKAGES.filter((name) => !PUBLIC_PACKAGES.has(name)).join("|")})(?![a-z0-9-])`);
53
+ const OLD_NAME = new RegExp(`@stndrds/(${RENAMED_PACKAGES.join("|")})(?![a-z0-9-])`, "g");
54
+ /** Code, styles, manifests, workspace config and agent guidance (AGENTS.md, CLAUDE.md). */
55
+ const REWRITTEN_FILE = /\.(?:[cm]?tsx?|[cm]?jsx?|css|scss|sass|less|json|jsonc|ya?ml|mdx?)$/;
56
+ /** Lockfiles are regenerated by the install that follows, never edited. */
57
+ const LOCKFILES = /* @__PURE__ */ new Set([
58
+ "pnpm-lock.yaml",
59
+ "package-lock.json",
60
+ "yarn.lock",
61
+ "bun.lock"
62
+ ]);
63
+ /** Renames every reference to one of our packages from `@stndrds/<name>` to `@standards/<name>`. */
64
+ function rewriteScopes(source) {
65
+ let changed = 0;
66
+ const output = source.replace(OLD_NAME, (_match, name) => {
67
+ changed += 1;
68
+ return `@standards/${name}`;
69
+ });
70
+ return {
71
+ output,
72
+ changed,
73
+ licensed: LICENSED_NAME.test(output)
74
+ };
75
+ }
76
+ /**
77
+ * Project `.npmrc` pointing `@standards` at the licensed registry: a different
78
+ * `@standards:registry` is replaced in place, an env-variable key line for the
79
+ * registry is removed (it never worked there), every other line is kept.
80
+ */
81
+ function ensureScopesNpmrc(text) {
82
+ const lines = text.split("\n");
83
+ if (lines.at(-1) === "") lines.pop();
84
+ const output = lines.filter((line) => !PROJECT_AUTH_LINE.test(line)).map((line) => line.trim().startsWith("@standards:registry=") ? SCOPE_REGISTRY_LINE : line);
85
+ if (!output.includes(SCOPE_REGISTRY_LINE)) output.push(SCOPE_REGISTRY_LINE);
86
+ return `${output.join("\n")}\n`;
87
+ }
88
+ function isRewritten(path) {
89
+ return REWRITTEN_FILE.test(path) && !LOCKFILES.has(basename(path));
90
+ }
91
+ async function readOptional(path) {
92
+ try {
93
+ return await readFile(path, "utf8");
94
+ } catch {
95
+ return "";
96
+ }
97
+ }
98
+ async function runScopes(paths, options) {
99
+ const report = {
100
+ files: 0,
101
+ changed: 0,
102
+ licensed: false
103
+ };
104
+ const results = await rewriteFiles(paths, isRewritten, options.write, rewriteScopes);
105
+ for (const { result } of results) {
106
+ if (result.licensed) report.licensed = true;
107
+ if (result.changed === 0) continue;
108
+ report.files += 1;
109
+ report.changed += result.changed;
110
+ }
111
+ if (!report.licensed) return report;
112
+ const npmrcPath = join(options.root, ".npmrc");
113
+ const current = await readOptional(npmrcPath);
114
+ const next = ensureScopesNpmrc(current);
115
+ if (next !== current) {
116
+ report.npmrc = npmrcPath;
117
+ if (options.write) await writeFile(npmrcPath, next);
118
+ }
119
+ return report;
120
+ }
121
+ //#endregion
122
+ export { runScopes };
@@ -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": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-alpha.384",
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.384",
23
+ "@standards/constants": "1.0.0-alpha.384",
24
+ "@standards/schema": "1.0.0-alpha.384"
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
  }