@fluixi/cli 0.1.0-alpha.82 → 0.1.0-alpha.83

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.
Files changed (57) hide show
  1. package/README.md +21 -3
  2. package/dist/add.cjs +590 -0
  3. package/dist/add.d.ts +10 -0
  4. package/dist/add.d.ts.map +1 -0
  5. package/dist/add.js +107 -0
  6. package/dist/add.mjs +562 -0
  7. package/dist/check.cjs +102 -0
  8. package/dist/check.d.ts +13 -0
  9. package/dist/check.d.ts.map +1 -0
  10. package/dist/check.js +88 -0
  11. package/dist/check.mjs +76 -0
  12. package/dist/cli.cjs +977 -78
  13. package/dist/cli.js +44 -2
  14. package/dist/cli.mjs +976 -77
  15. package/dist/doctor.cjs +119 -0
  16. package/dist/doctor.d.ts +13 -0
  17. package/dist/doctor.d.ts.map +1 -0
  18. package/dist/doctor.js +114 -0
  19. package/dist/doctor.mjs +92 -0
  20. package/dist/generate.cjs +614 -65
  21. package/dist/generate.d.ts.map +1 -1
  22. package/dist/generate.js +118 -48
  23. package/dist/generate.mjs +619 -64
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.mjs +1 -1
  26. package/dist/report.cjs +54 -0
  27. package/dist/report.d.ts +5 -0
  28. package/dist/report.d.ts.map +1 -0
  29. package/dist/report.js +31 -0
  30. package/dist/report.mjs +28 -0
  31. package/dist/scaffold/auth.cjs +422 -0
  32. package/dist/scaffold/auth.d.ts +39 -0
  33. package/dist/scaffold/auth.d.ts.map +1 -0
  34. package/dist/scaffold/auth.js +137 -0
  35. package/dist/scaffold/auth.mjs +389 -0
  36. package/dist/scaffold/edit.cjs +153 -0
  37. package/dist/scaffold/edit.d.ts +35 -0
  38. package/dist/scaffold/edit.d.ts.map +1 -0
  39. package/dist/scaffold/edit.js +140 -0
  40. package/dist/scaffold/edit.mjs +124 -0
  41. package/dist/scaffold/index.cjs +610 -0
  42. package/dist/scaffold/index.d.ts +10 -0
  43. package/dist/scaffold/index.d.ts.map +1 -0
  44. package/dist/scaffold/index.js +9 -0
  45. package/dist/scaffold/index.mjs +569 -0
  46. package/dist/scaffold/prompt.cjs +108 -0
  47. package/dist/scaffold/prompt.d.ts +9 -0
  48. package/dist/scaffold/prompt.d.ts.map +1 -0
  49. package/dist/scaffold/prompt.js +95 -0
  50. package/dist/scaffold/prompt.mjs +81 -0
  51. package/dist/scaffold/templates.cjs +274 -0
  52. package/dist/scaffold/templates.d.ts +26 -0
  53. package/dist/scaffold/templates.d.ts.map +1 -0
  54. package/dist/scaffold/templates.js +216 -0
  55. package/dist/scaffold/templates.mjs +229 -0
  56. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  57. package/package.json +19 -3
package/dist/check.cjs ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/check.ts
21
+ var check_exports = {};
22
+ __export(check_exports, {
23
+ check: () => check,
24
+ checkProject: () => checkProject
25
+ });
26
+ module.exports = __toCommonJS(check_exports);
27
+ var import_node_fs = require("node:fs");
28
+ var import_node_module = require("node:module");
29
+ var import_node_path = require("node:path");
30
+ var import_rules = require("@fluixi/ts-plugin/rules");
31
+ var import_ui = require("@fluixi/start/ui");
32
+ function loadTypeScript(root) {
33
+ try {
34
+ return (0, import_node_module.createRequire)((0, import_node_path.join)(root, "package.json"))("typescript");
35
+ } catch {
36
+ throw new Error("fluixi check needs typescript in the app: npm install -D typescript");
37
+ }
38
+ }
39
+ function rootFiles(ts, configPath, seen = /* @__PURE__ */ new Set()) {
40
+ seen.add(configPath);
41
+ const read = ts.readConfigFile(configPath, ts.sys.readFile);
42
+ if (read.error) throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, "\n"));
43
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, (0, import_node_path.dirname)(configPath));
44
+ const files = [...parsed.fileNames];
45
+ let options = parsed.options;
46
+ for (const ref of parsed.projectReferences ?? []) {
47
+ const path = ts.resolveProjectReferencePath(ref);
48
+ if (seen.has(path) || !(0, import_node_fs.existsSync)(path)) continue;
49
+ const child = rootFiles(ts, path, seen);
50
+ files.push(...child.files);
51
+ if (!parsed.fileNames.length) options = child.options;
52
+ }
53
+ return { files, options };
54
+ }
55
+ function checkProject(root = process.cwd(), ts = loadTypeScript(root)) {
56
+ const configPath = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
57
+ if (!configPath) throw new Error(`no tsconfig.json in ${root}`);
58
+ const { files, options } = rootFiles(ts, configPath);
59
+ for (const name of ["fluixi.config.ts", "fluixi.config.mts", "fluixi.config.js"]) {
60
+ const path = (0, import_node_path.resolve)(root, name);
61
+ if ((0, import_node_fs.existsSync)(path) && !files.includes(path)) files.push(path);
62
+ }
63
+ const compilerOptions = { ...options, noEmit: true };
64
+ const host = ts.createCompilerHost(compilerOptions, true);
65
+ const program = ts.createProgram({ rootNames: [...new Set(files)], options: compilerOptions, host });
66
+ const out = [];
67
+ for (const sf of program.getSourceFiles()) {
68
+ if (sf.isDeclarationFile || /[\\/]node_modules[\\/]/.test(sf.fileName)) continue;
69
+ for (const d of (0, import_rules.envAuthDiagnostics)(ts, program, sf.fileName, ts.sys)) {
70
+ const at = sf.getLineAndCharacterOfPosition(d.start ?? 0);
71
+ out.push({
72
+ file: (0, import_node_path.relative)(root, sf.fileName),
73
+ line: at.line + 1,
74
+ column: at.character + 1,
75
+ code: d.code,
76
+ severity: d.category === ts.DiagnosticCategory.Error ? "error" : d.category === ts.DiagnosticCategory.Warning ? "warning" : "suggestion",
77
+ message: ts.flattenDiagnosticMessageText(d.messageText, " ")
78
+ });
79
+ }
80
+ }
81
+ return out.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column);
82
+ }
83
+ function check(root = process.cwd(), strict = false) {
84
+ const found = checkProject(root);
85
+ const shown = found.filter((f) => f.severity !== "suggestion");
86
+ const mark = { error: import_ui.c.red("error"), warning: import_ui.c.yellow("warning"), suggestion: import_ui.c.gray("note") };
87
+ const lines = shown.map(
88
+ (f) => ` ${import_ui.c.cyan(`${f.file}:${f.line}:${f.column}`)} ${mark[f.severity]} ${import_ui.c.gray(`FX${f.code}`)} ${f.message}`
89
+ );
90
+ const errors = shown.filter((f) => f.severity === "error").length;
91
+ const warnings = shown.length - errors;
92
+ const notes = found.length - shown.length;
93
+ const tally = [`${errors} error${errors === 1 ? "" : "s"}`, `${warnings} warning${warnings === 1 ? "" : "s"}`];
94
+ if (notes) tally.push(`${notes} note${notes === 1 ? "" : "s"}`);
95
+ console.log(["", ...lines, ...lines.length ? [""] : [], ` ${shown.length ? import_ui.c.bold(tally.join(", ")) : `${import_ui.c.green("✓")} no env or auth findings`}`, ""].join("\n"));
96
+ return errors || strict && warnings ? 1 : 0;
97
+ }
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ check,
101
+ checkProject
102
+ });
@@ -0,0 +1,13 @@
1
+ import type * as TS from 'typescript';
2
+ export interface Finding {
3
+ file: string;
4
+ line: number;
5
+ column: number;
6
+ code: number;
7
+ severity: 'error' | 'warning' | 'suggestion';
8
+ message: string;
9
+ }
10
+ export declare function checkProject(root?: string, ts?: typeof TS): Finding[];
11
+ /** Print the findings. Returns the exit code: 1 on an error, or on a warning with `--strict`. */
12
+ export declare function check(root?: string, strict?: boolean): number;
13
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAItC,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,YAAY,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;CACjB;AA4BD,wBAAgB,YAAY,CAAC,IAAI,SAAgB,EAAE,EAAE,GAAE,OAAO,EAAyB,GAAG,OAAO,EAAE,CA8BlG;AAED,iGAAiG;AACjG,wBAAgB,KAAK,CAAC,IAAI,SAAgB,EAAE,MAAM,UAAQ,GAAG,MAAM,CAclE"}
package/dist/check.js ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * `fluixi check`: the editor's env and auth rules over the whole project, for CI.
3
+ *
4
+ * The rules are the ts-plugin's own, so the terminal and the editor never disagree. TypeScript
5
+ * comes from the app: its version is the one the project compiles with, and the CLI does not
6
+ * ship a second copy.
7
+ */
8
+ import { existsSync } from 'node:fs';
9
+ import { createRequire } from 'node:module';
10
+ import { dirname, join, relative, resolve } from 'node:path';
11
+ import { envAuthDiagnostics } from '@fluixi/ts-plugin/rules';
12
+ import { c } from '@fluixi/start/ui';
13
+ function loadTypeScript(root) {
14
+ try {
15
+ return createRequire(join(root, 'package.json'))('typescript');
16
+ }
17
+ catch {
18
+ throw new Error('fluixi check needs typescript in the app: npm install -D typescript');
19
+ }
20
+ }
21
+ /** Source files a tsconfig names, following project references one level down. */
22
+ function rootFiles(ts, configPath, seen = new Set()) {
23
+ seen.add(configPath);
24
+ const read = ts.readConfigFile(configPath, ts.sys.readFile);
25
+ if (read.error)
26
+ throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, '\n'));
27
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, dirname(configPath));
28
+ const files = [...parsed.fileNames];
29
+ let options = parsed.options;
30
+ for (const ref of parsed.projectReferences ?? []) {
31
+ const path = ts.resolveProjectReferencePath(ref);
32
+ if (seen.has(path) || !existsSync(path))
33
+ continue;
34
+ const child = rootFiles(ts, path, seen);
35
+ files.push(...child.files);
36
+ if (!parsed.fileNames.length)
37
+ options = child.options;
38
+ }
39
+ return { files, options };
40
+ }
41
+ export function checkProject(root = process.cwd(), ts = loadTypeScript(root)) {
42
+ const configPath = ts.findConfigFile(root, ts.sys.fileExists, 'tsconfig.json');
43
+ if (!configPath)
44
+ throw new Error(`no tsconfig.json in ${root}`);
45
+ const { files, options } = rootFiles(ts, configPath);
46
+ // fluixi.config.ts is rarely in `include`, and it is where env.public is declared.
47
+ for (const name of ['fluixi.config.ts', 'fluixi.config.mts', 'fluixi.config.js']) {
48
+ const path = resolve(root, name);
49
+ if (existsSync(path) && !files.includes(path))
50
+ files.push(path);
51
+ }
52
+ const compilerOptions = { ...options, noEmit: true };
53
+ // The rules walk up through `parent`, which a bare program only sets once it binds a file.
54
+ const host = ts.createCompilerHost(compilerOptions, true);
55
+ const program = ts.createProgram({ rootNames: [...new Set(files)], options: compilerOptions, host });
56
+ const out = [];
57
+ for (const sf of program.getSourceFiles()) {
58
+ if (sf.isDeclarationFile || /[\\/]node_modules[\\/]/.test(sf.fileName))
59
+ continue;
60
+ for (const d of envAuthDiagnostics(ts, program, sf.fileName, ts.sys)) {
61
+ const at = sf.getLineAndCharacterOfPosition(d.start ?? 0);
62
+ out.push({
63
+ file: relative(root, sf.fileName),
64
+ line: at.line + 1,
65
+ column: at.character + 1,
66
+ code: d.code,
67
+ severity: d.category === ts.DiagnosticCategory.Error ? 'error' : d.category === ts.DiagnosticCategory.Warning ? 'warning' : 'suggestion',
68
+ message: ts.flattenDiagnosticMessageText(d.messageText, ' '),
69
+ });
70
+ }
71
+ }
72
+ return out.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column);
73
+ }
74
+ /** Print the findings. Returns the exit code: 1 on an error, or on a warning with `--strict`. */
75
+ export function check(root = process.cwd(), strict = false) {
76
+ const found = checkProject(root);
77
+ const shown = found.filter((f) => f.severity !== 'suggestion');
78
+ const mark = { error: c.red('error'), warning: c.yellow('warning'), suggestion: c.gray('note') };
79
+ const lines = shown.map((f) => ` ${c.cyan(`${f.file}:${f.line}:${f.column}`)} ${mark[f.severity]} ${c.gray(`FX${f.code}`)} ${f.message}`);
80
+ const errors = shown.filter((f) => f.severity === 'error').length;
81
+ const warnings = shown.length - errors;
82
+ const notes = found.length - shown.length;
83
+ const tally = [`${errors} error${errors === 1 ? '' : 's'}`, `${warnings} warning${warnings === 1 ? '' : 's'}`];
84
+ if (notes)
85
+ tally.push(`${notes} note${notes === 1 ? '' : 's'}`);
86
+ console.log(['', ...lines, ...(lines.length ? [''] : []), ` ${shown.length ? c.bold(tally.join(', ')) : `${c.green('✓')} no env or auth findings`}`, ''].join('\n'));
87
+ return errors || (strict && warnings) ? 1 : 0;
88
+ }
package/dist/check.mjs ADDED
@@ -0,0 +1,76 @@
1
+ // src/check.ts
2
+ import { existsSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { dirname, join, relative, resolve } from "node:path";
5
+ import { envAuthDiagnostics } from "@fluixi/ts-plugin/rules";
6
+ import { c } from "@fluixi/start/ui";
7
+ function loadTypeScript(root) {
8
+ try {
9
+ return createRequire(join(root, "package.json"))("typescript");
10
+ } catch {
11
+ throw new Error("fluixi check needs typescript in the app: npm install -D typescript");
12
+ }
13
+ }
14
+ function rootFiles(ts, configPath, seen = /* @__PURE__ */ new Set()) {
15
+ seen.add(configPath);
16
+ const read = ts.readConfigFile(configPath, ts.sys.readFile);
17
+ if (read.error) throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, "\n"));
18
+ const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, dirname(configPath));
19
+ const files = [...parsed.fileNames];
20
+ let options = parsed.options;
21
+ for (const ref of parsed.projectReferences ?? []) {
22
+ const path = ts.resolveProjectReferencePath(ref);
23
+ if (seen.has(path) || !existsSync(path)) continue;
24
+ const child = rootFiles(ts, path, seen);
25
+ files.push(...child.files);
26
+ if (!parsed.fileNames.length) options = child.options;
27
+ }
28
+ return { files, options };
29
+ }
30
+ function checkProject(root = process.cwd(), ts = loadTypeScript(root)) {
31
+ const configPath = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
32
+ if (!configPath) throw new Error(`no tsconfig.json in ${root}`);
33
+ const { files, options } = rootFiles(ts, configPath);
34
+ for (const name of ["fluixi.config.ts", "fluixi.config.mts", "fluixi.config.js"]) {
35
+ const path = resolve(root, name);
36
+ if (existsSync(path) && !files.includes(path)) files.push(path);
37
+ }
38
+ const compilerOptions = { ...options, noEmit: true };
39
+ const host = ts.createCompilerHost(compilerOptions, true);
40
+ const program = ts.createProgram({ rootNames: [...new Set(files)], options: compilerOptions, host });
41
+ const out = [];
42
+ for (const sf of program.getSourceFiles()) {
43
+ if (sf.isDeclarationFile || /[\\/]node_modules[\\/]/.test(sf.fileName)) continue;
44
+ for (const d of envAuthDiagnostics(ts, program, sf.fileName, ts.sys)) {
45
+ const at = sf.getLineAndCharacterOfPosition(d.start ?? 0);
46
+ out.push({
47
+ file: relative(root, sf.fileName),
48
+ line: at.line + 1,
49
+ column: at.character + 1,
50
+ code: d.code,
51
+ severity: d.category === ts.DiagnosticCategory.Error ? "error" : d.category === ts.DiagnosticCategory.Warning ? "warning" : "suggestion",
52
+ message: ts.flattenDiagnosticMessageText(d.messageText, " ")
53
+ });
54
+ }
55
+ }
56
+ return out.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column);
57
+ }
58
+ function check(root = process.cwd(), strict = false) {
59
+ const found = checkProject(root);
60
+ const shown = found.filter((f) => f.severity !== "suggestion");
61
+ const mark = { error: c.red("error"), warning: c.yellow("warning"), suggestion: c.gray("note") };
62
+ const lines = shown.map(
63
+ (f) => ` ${c.cyan(`${f.file}:${f.line}:${f.column}`)} ${mark[f.severity]} ${c.gray(`FX${f.code}`)} ${f.message}`
64
+ );
65
+ const errors = shown.filter((f) => f.severity === "error").length;
66
+ const warnings = shown.length - errors;
67
+ const notes = found.length - shown.length;
68
+ const tally = [`${errors} error${errors === 1 ? "" : "s"}`, `${warnings} warning${warnings === 1 ? "" : "s"}`];
69
+ if (notes) tally.push(`${notes} note${notes === 1 ? "" : "s"}`);
70
+ console.log(["", ...lines, ...lines.length ? [""] : [], ` ${shown.length ? c.bold(tally.join(", ")) : `${c.green("✓")} no env or auth findings`}`, ""].join("\n"));
71
+ return errors || strict && warnings ? 1 : 0;
72
+ }
73
+ export {
74
+ check,
75
+ checkProject
76
+ };