prodex 1.4.11 → 2.0.1
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 +20 -20
- package/README.md +240 -234
- package/bin/prodex.js +0 -0
- package/dist/app/execute-run.d.ts +2 -0
- package/dist/app/execute-run.js +74 -0
- package/dist/app/project-context.d.ts +12 -0
- package/dist/app/project-context.js +48 -0
- package/dist/app/run-plans.d.ts +11 -0
- package/dist/app/run-plans.js +61 -0
- package/dist/cache/cache-keys.d.ts +9 -0
- package/dist/cache/cache-manager.d.ts +9 -0
- package/dist/{core/managers/cache.js → cache/cache-manager.js} +5 -18
- package/dist/cli/cli-input.d.ts +2 -0
- package/dist/cli/cli-input.js +138 -124
- package/dist/cli/flag-specs.d.ts +12 -0
- package/dist/cli/flag-specs.js +28 -0
- package/dist/cli/help.d.ts +2 -0
- package/dist/cli/help.js +83 -0
- package/dist/cli/report-command.d.ts +2 -0
- package/dist/cli/report-command.js +101 -0
- package/dist/cli/reporter.d.ts +2 -0
- package/dist/cli/reporter.js +8 -0
- package/dist/commands/init-command.d.ts +1 -0
- package/dist/commands/init-command.js +9 -0
- package/dist/commands/migrate-command.d.ts +7 -0
- package/dist/commands/migrate-command.js +76 -0
- package/dist/commands/profiles-command.d.ts +6 -0
- package/dist/commands/profiles-command.js +16 -0
- package/dist/commands/run-command.d.ts +11 -0
- package/dist/commands/run-command.js +17 -0
- package/dist/config/build-config.d.ts +13 -0
- package/dist/config/build-config.js +127 -0
- package/dist/config/create-default-config.d.ts +9 -0
- package/dist/config/create-default-config.js +25 -0
- package/dist/config/default-config.d.ts +2 -0
- package/dist/config/default-config.js +23 -0
- package/dist/config/json.d.ts +2 -0
- package/dist/config/json.js +10 -0
- package/dist/config/load.d.ts +9 -0
- package/dist/config/load.js +48 -0
- package/dist/config/migration/detect.d.ts +4 -0
- package/dist/config/migration/detect.js +22 -0
- package/dist/config/migration/index.d.ts +4 -0
- package/dist/{shared → config/migration}/index.js +4 -3
- package/dist/config/migration/messages.d.ts +2 -0
- package/dist/config/migration/messages.js +35 -0
- package/dist/config/migration/transform.d.ts +2 -0
- package/dist/config/migration/transform.js +80 -0
- package/dist/config/migration/types.d.ts +16 -0
- package/dist/config/string-list.d.ts +2 -0
- package/dist/config/string-list.js +17 -0
- package/dist/diagnostics/logger.d.ts +3 -0
- package/dist/diagnostics/logger.js +33 -0
- package/dist/filesystem/glob-scan.d.ts +4 -0
- package/dist/filesystem/glob-scan.js +26 -0
- package/dist/filesystem/inspect.d.ts +1 -0
- package/dist/filesystem/inspect.js +15 -0
- package/dist/filesystem/path.d.ts +2 -0
- package/dist/filesystem/path.js +11 -0
- package/dist/filesystem/read-file.d.ts +8 -0
- package/dist/{shared/io.js → filesystem/read-file.js} +0 -25
- package/dist/filesystem/stat-cache.d.ts +1 -0
- package/dist/filesystem/stat-cache.js +22 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +76 -83
- package/dist/output/markdown.d.ts +12 -0
- package/dist/output/markdown.js +150 -0
- package/dist/output/naming.d.ts +2 -0
- package/dist/output/naming.js +30 -0
- package/dist/output/produce-output.d.ts +2 -0
- package/dist/output/produce-output.js +35 -0
- package/dist/output/render-constants.d.ts +21 -0
- package/dist/{constants → output}/render-constants.js +2 -1
- package/dist/output/text.d.ts +2 -0
- package/dist/output/text.js +14 -0
- package/dist/resolvers/js/extract-imports.d.ts +1 -0
- package/dist/resolvers/js/js-resolver.d.ts +2 -0
- package/dist/resolvers/js/js-resolver.js +45 -89
- package/dist/resolvers/js/resolve-alias.d.ts +2 -0
- package/dist/resolvers/js/resolve-alias.js +12 -20
- package/dist/resolvers/php/bindings.d.ts +8 -0
- package/dist/resolvers/php/bindings.js +8 -9
- package/dist/resolvers/php/extract-imports.d.ts +13 -0
- package/dist/resolvers/php/extract-imports.js +1 -1
- package/dist/resolvers/php/php-resolver.d.ts +2 -0
- package/dist/resolvers/php/php-resolver.js +61 -90
- package/dist/resolvers/php/psr4.d.ts +5 -0
- package/dist/resolvers/php/psr4.js +7 -7
- package/dist/resolvers/resolver-constants.d.ts +4 -0
- package/dist/resolvers/resolver-constants.js +7 -0
- package/dist/resolvers/resolver-result.d.ts +5 -0
- package/dist/resolvers/resolver-result.js +18 -0
- package/dist/tracing/exclude.d.ts +6 -0
- package/dist/{shared/patterns.js → tracing/exclude.js} +4 -4
- package/dist/tracing/follow-chain.d.ts +5 -0
- package/dist/tracing/follow-chain.js +63 -0
- package/dist/tracing/include-files.d.ts +2 -0
- package/dist/tracing/include-files.js +36 -0
- package/dist/tracing/resolver-registry.d.ts +5 -0
- package/dist/tracing/resolver-registry.js +20 -0
- package/dist/tracing/trace-run.d.ts +2 -0
- package/dist/tracing/trace-run.js +21 -0
- package/dist/tracing/trace-stats.d.ts +4 -0
- package/dist/tracing/trace-stats.js +16 -0
- package/dist/types/app.types.d.ts +62 -0
- package/dist/types/app.types.js +2 -0
- package/dist/types/cli.types.d.ts +22 -0
- package/dist/types/cli.types.js +0 -10
- package/dist/types/config.types.d.ts +34 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +3 -1
- package/dist/types/output.types.d.ts +6 -0
- package/dist/types/output.types.js +2 -0
- package/dist/types/resolver.types.d.ts +23 -0
- package/dist/types/tracing.types.d.ts +23 -0
- package/dist/types/tracing.types.js +2 -0
- package/dist/types/utils.types.d.ts +10 -0
- package/package.json +35 -12
- package/schema/prodex.schema.json +122 -0
- package/dist/cli/init.js +0 -21
- package/dist/cli/picker.js +0 -83
- package/dist/cli/summary.js +0 -32
- package/dist/constants/config.js +0 -27
- package/dist/constants/default-config.js +0 -43
- package/dist/constants/flags.js +0 -79
- package/dist/constants/index.js +0 -20
- package/dist/core/combine.js +0 -56
- package/dist/core/dependency.js +0 -98
- package/dist/core/helpers.js +0 -85
- package/dist/core/managers/config.js +0 -140
- package/dist/core/output.js +0 -49
- package/dist/core/renderers.js +0 -210
- package/dist/debug.js +0 -15
- package/dist/lib/logger.js +0 -42
- package/dist/lib/polyfills.js +0 -17
- package/dist/lib/prompt.js +0 -34
- package/dist/lib/questions.js +0 -28
- package/dist/lib/utils.js +0 -46
- package/dist/shared/collections.js +0 -33
- package/dist/store.js +0 -15
- /package/dist/{constants → cache}/cache-keys.js +0 -0
- /package/dist/{types/core.types.js → config/migration/types.js} +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.reportCommandResult = reportCommandResult;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const path_2 = require("../filesystem/path");
|
|
9
|
+
function reportCommandResult(result) {
|
|
10
|
+
for (const warning of result.warnings)
|
|
11
|
+
console.warn(`Warning: ${warning}`);
|
|
12
|
+
for (const error of result.errors)
|
|
13
|
+
console.error(`Error: ${error}`);
|
|
14
|
+
if (result.message)
|
|
15
|
+
console.log(result.message);
|
|
16
|
+
if (result.profiles)
|
|
17
|
+
reportProfiles(result.profiles);
|
|
18
|
+
if (result.migration)
|
|
19
|
+
reportMigration(result.migration);
|
|
20
|
+
reportRuns(result.runs);
|
|
21
|
+
}
|
|
22
|
+
function reportRuns(runs) {
|
|
23
|
+
for (const run of runs) {
|
|
24
|
+
reportRunWarningsAndErrors(run);
|
|
25
|
+
}
|
|
26
|
+
const successfulRuns = runs.filter((run) => run.outputPath);
|
|
27
|
+
if (!successfulRuns.length)
|
|
28
|
+
return;
|
|
29
|
+
const rows = successfulRuns.map((run) => ({
|
|
30
|
+
label: formatRunLabel(run),
|
|
31
|
+
mode: run.mode,
|
|
32
|
+
files: String(run.files.length),
|
|
33
|
+
output: formatPath(run.outputPath, run.root),
|
|
34
|
+
}));
|
|
35
|
+
const labelWidth = maxWidth(rows.map((row) => row.label));
|
|
36
|
+
const modeWidth = maxWidth(rows.map((row) => row.mode));
|
|
37
|
+
const filesWidth = maxWidth(rows.map((row) => row.files));
|
|
38
|
+
for (const row of rows) {
|
|
39
|
+
console.log(`✓ ${row.label.padEnd(labelWidth)} ${row.mode.padEnd(modeWidth)} ${row.files.padStart(filesWidth)} ${row.output}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function reportRunWarningsAndErrors(run) {
|
|
43
|
+
const label = run.profile ? ` [${run.profile}]` : "";
|
|
44
|
+
for (const warning of run.warnings)
|
|
45
|
+
console.warn(`Warning${label}: ${warning}`);
|
|
46
|
+
for (const error of run.errors)
|
|
47
|
+
console.error(`Error${label}: ${error}`);
|
|
48
|
+
}
|
|
49
|
+
function reportMigration(migration) {
|
|
50
|
+
if (migration.errors.length)
|
|
51
|
+
return;
|
|
52
|
+
if (!migration.needed) {
|
|
53
|
+
console.log("prodex.json is already using config version 4.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (migration.written) {
|
|
57
|
+
console.log(`Backed up prodex.json to ${formatPath(migration.backupPath, path_1.default.dirname(migration.path))}`);
|
|
58
|
+
console.log("Migrated prodex.json to version 4.");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const from = migration.fromVersion ?? "legacy";
|
|
62
|
+
console.log(`prodex.json can be migrated from version ${from} to version 4.`);
|
|
63
|
+
if (migration.changes.length) {
|
|
64
|
+
console.log("");
|
|
65
|
+
console.log("Changes:");
|
|
66
|
+
for (const change of migration.changes)
|
|
67
|
+
console.log(` ${change}`);
|
|
68
|
+
}
|
|
69
|
+
console.log("");
|
|
70
|
+
console.log("Run `prodex migrate --write` to update prodex.json.");
|
|
71
|
+
}
|
|
72
|
+
function reportProfiles(profiles) {
|
|
73
|
+
if (!profiles.length) {
|
|
74
|
+
console.log("No profiles configured.");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.log("Available profiles:");
|
|
78
|
+
for (const profile of profiles)
|
|
79
|
+
console.log(` ${profile}`);
|
|
80
|
+
}
|
|
81
|
+
function formatRunLabel(run) {
|
|
82
|
+
if (run.profile)
|
|
83
|
+
return run.profile;
|
|
84
|
+
if (run.outputName)
|
|
85
|
+
return run.outputName;
|
|
86
|
+
if (!run.outputPath)
|
|
87
|
+
return "run";
|
|
88
|
+
const ext = path_1.default.extname(run.outputPath);
|
|
89
|
+
const base = path_1.default.basename(run.outputPath, ext);
|
|
90
|
+
return base.replace(/-trace(?:_\d{6}-\d{4})?$/, "") || "run";
|
|
91
|
+
}
|
|
92
|
+
function formatPath(filePath, root) {
|
|
93
|
+
const absolute = path_1.default.resolve(filePath);
|
|
94
|
+
const relative = path_1.default.relative(root, absolute);
|
|
95
|
+
if (!relative.startsWith("..") && !path_1.default.isAbsolute(relative))
|
|
96
|
+
return (0, path_2.normalizePath)(relative);
|
|
97
|
+
return (0, path_2.normalizePath)(absolute);
|
|
98
|
+
}
|
|
99
|
+
function maxWidth(values) {
|
|
100
|
+
return values.reduce((max, value) => Math.max(max, value.length), 0);
|
|
101
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportCommandResult = exports.renderVersion = exports.renderHelp = void 0;
|
|
4
|
+
var help_1 = require("./help");
|
|
5
|
+
Object.defineProperty(exports, "renderHelp", { enumerable: true, get: function () { return help_1.renderHelp; } });
|
|
6
|
+
Object.defineProperty(exports, "renderVersion", { enumerable: true, get: function () { return help_1.renderVersion; } });
|
|
7
|
+
var report_command_1 = require("./report-command");
|
|
8
|
+
Object.defineProperty(exports, "reportCommandResult", { enumerable: true, get: function () { return report_command_1.reportCommandResult; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initCommand(rootArg: string | undefined, cwd: string, force?: boolean): import("../config/create-default-config").InitResult;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initCommand = initCommand;
|
|
4
|
+
const project_context_1 = require("../app/project-context");
|
|
5
|
+
const create_default_config_1 = require("../config/create-default-config");
|
|
6
|
+
function initCommand(rootArg, cwd, force) {
|
|
7
|
+
const root = (0, project_context_1.resolveRoot)(rootArg, cwd);
|
|
8
|
+
return (0, create_default_config_1.createDefaultConfig)(root, { force });
|
|
9
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.migrateCommand = migrateCommand;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const json_1 = require("../config/json");
|
|
10
|
+
const transform_1 = require("../config/migration/transform");
|
|
11
|
+
const detect_1 = require("../config/migration/detect");
|
|
12
|
+
const project_context_1 = require("../app/project-context");
|
|
13
|
+
function migrateCommand(params) {
|
|
14
|
+
const root = (0, project_context_1.resolveRoot)(params.rootArg, params.cwd);
|
|
15
|
+
const configPath = path_1.default.join(root, "prodex.json");
|
|
16
|
+
const warnings = [];
|
|
17
|
+
const errors = (0, project_context_1.validateRoot)(root, params.rootArg);
|
|
18
|
+
if (errors.length)
|
|
19
|
+
return emptyMigrationResult(configPath, warnings, errors);
|
|
20
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
21
|
+
errors.push("No prodex.json found.");
|
|
22
|
+
return emptyMigrationResult(configPath, warnings, errors);
|
|
23
|
+
}
|
|
24
|
+
let raw;
|
|
25
|
+
try {
|
|
26
|
+
raw = (0, json_1.parseJsonFile)(fs_1.default.readFileSync(configPath, "utf8"));
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
errors.push(`Invalid prodex.json: ${err?.message || err}`);
|
|
30
|
+
return emptyMigrationResult(configPath, warnings, errors);
|
|
31
|
+
}
|
|
32
|
+
const preview = (0, transform_1.migrateConfig)(raw);
|
|
33
|
+
if (params.check && preview.needed) {
|
|
34
|
+
errors.push(`prodex.json requires migration to version ${detect_1.REQUIRED_CONFIG_VERSION}.`);
|
|
35
|
+
}
|
|
36
|
+
if (params.check) {
|
|
37
|
+
return { ...preview, ok: !preview.needed, written: false, path: configPath, warnings, errors };
|
|
38
|
+
}
|
|
39
|
+
if (!preview.needed || !params.write) {
|
|
40
|
+
return { ...preview, ok: !errors.length, written: false, path: configPath, warnings, errors };
|
|
41
|
+
}
|
|
42
|
+
const backupPath = nextBackupPath(root, preview.fromVersion);
|
|
43
|
+
fs_1.default.copyFileSync(configPath, backupPath);
|
|
44
|
+
fs_1.default.writeFileSync(configPath, `${JSON.stringify(preview.config, null, 4)}\n`, "utf8");
|
|
45
|
+
return {
|
|
46
|
+
...preview,
|
|
47
|
+
ok: true,
|
|
48
|
+
written: true,
|
|
49
|
+
backupPath,
|
|
50
|
+
path: configPath,
|
|
51
|
+
warnings,
|
|
52
|
+
errors,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function nextBackupPath(root, version) {
|
|
56
|
+
const suffix = version ? `v${String(version).replace(/\W+/g, "_")}` : "legacy";
|
|
57
|
+
let backup = path_1.default.join(root, `prodex.${suffix}.backup.json`);
|
|
58
|
+
let index = 1;
|
|
59
|
+
while (fs_1.default.existsSync(backup)) {
|
|
60
|
+
backup = path_1.default.join(root, `prodex.${suffix}.backup.${index}.json`);
|
|
61
|
+
index++;
|
|
62
|
+
}
|
|
63
|
+
return backup;
|
|
64
|
+
}
|
|
65
|
+
function emptyMigrationResult(pathValue, warnings, errors) {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
needed: false,
|
|
69
|
+
toVersion: detect_1.REQUIRED_CONFIG_VERSION,
|
|
70
|
+
changes: [],
|
|
71
|
+
written: false,
|
|
72
|
+
path: pathValue,
|
|
73
|
+
warnings,
|
|
74
|
+
errors,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.profilesCommand = profilesCommand;
|
|
4
|
+
const project_context_1 = require("../app/project-context");
|
|
5
|
+
function profilesCommand(rootArg, cwd = process.cwd()) {
|
|
6
|
+
const project = (0, project_context_1.loadProjectContext)(rootArg, cwd);
|
|
7
|
+
const warnings = [...project.warnings];
|
|
8
|
+
const errors = [...project.errors];
|
|
9
|
+
if (errors.length)
|
|
10
|
+
return { profiles: [], warnings, errors };
|
|
11
|
+
return {
|
|
12
|
+
profiles: Object.keys(project.config.profiles ?? {}).sort(),
|
|
13
|
+
warnings,
|
|
14
|
+
errors,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProdexFlags, RunResult } from "../types";
|
|
2
|
+
export interface RunCommandResult {
|
|
3
|
+
runs: RunResult[];
|
|
4
|
+
warnings: string[];
|
|
5
|
+
errors: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function runCommand(params: {
|
|
8
|
+
rootArg?: string;
|
|
9
|
+
flags?: Partial<ProdexFlags>;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
}): Promise<RunCommandResult>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCommand = runCommand;
|
|
4
|
+
const execute_run_1 = require("../app/execute-run");
|
|
5
|
+
const run_plans_1 = require("../app/run-plans");
|
|
6
|
+
async function runCommand(params) {
|
|
7
|
+
const planned = (0, run_plans_1.createRunPlans)(params);
|
|
8
|
+
const warnings = [...planned.warnings];
|
|
9
|
+
const errors = [...planned.errors];
|
|
10
|
+
if (errors.length)
|
|
11
|
+
return { runs: [], warnings, errors };
|
|
12
|
+
const runs = [];
|
|
13
|
+
for (const plan of planned.plans) {
|
|
14
|
+
runs.push(await (0, execute_run_1.executeRun)(plan));
|
|
15
|
+
}
|
|
16
|
+
return { runs, warnings, errors };
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DeepPartial, ProdexConfig, ProdexConfigFile, ProdexFlags } from "../types";
|
|
2
|
+
export interface ConfigBuildResult {
|
|
3
|
+
config?: ProdexConfig;
|
|
4
|
+
warnings: string[];
|
|
5
|
+
errors: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function buildConfig(params: {
|
|
8
|
+
root: string;
|
|
9
|
+
userConfig: ProdexConfigFile;
|
|
10
|
+
flags?: Partial<ProdexFlags>;
|
|
11
|
+
profileName?: string;
|
|
12
|
+
}): ConfigBuildResult;
|
|
13
|
+
export declare function deepMerge<T extends Record<string, any>>(base: T, patch: DeepPartial<T>): T;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildConfig = buildConfig;
|
|
7
|
+
exports.deepMerge = deepMerge;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const default_config_1 = require("./default-config");
|
|
10
|
+
const path_2 = require("../filesystem/path");
|
|
11
|
+
const string_list_1 = require("./string-list");
|
|
12
|
+
function buildConfig(params) {
|
|
13
|
+
const warnings = [];
|
|
14
|
+
const errors = [];
|
|
15
|
+
const base = deepMerge(default_config_1.DEFAULT_PRODEX_CONFIG, params.userConfig || {});
|
|
16
|
+
const profile = params.profileName ? base.profiles?.[params.profileName] : undefined;
|
|
17
|
+
if (params.profileName && !profile) {
|
|
18
|
+
errors.push(`Unknown profile "${params.profileName}".`);
|
|
19
|
+
return { warnings, errors };
|
|
20
|
+
}
|
|
21
|
+
const layered = applyProfileLayer(base, profile);
|
|
22
|
+
const config = toRuntimeConfig(layered, params.root, params.flags, profile, params.profileName);
|
|
23
|
+
normalizeRuntimeConfig(config, warnings);
|
|
24
|
+
validateRuntimeConfig(config, errors);
|
|
25
|
+
return { config, warnings, errors };
|
|
26
|
+
}
|
|
27
|
+
function applyProfileLayer(config, profile) {
|
|
28
|
+
if (!profile)
|
|
29
|
+
return config;
|
|
30
|
+
const patch = {};
|
|
31
|
+
if (profile.entry)
|
|
32
|
+
patch.entry = profile.entry;
|
|
33
|
+
if (profile.include)
|
|
34
|
+
patch.include = profile.include;
|
|
35
|
+
if (profile.exclude)
|
|
36
|
+
patch.exclude = profile.exclude;
|
|
37
|
+
return deepMerge(config, patch);
|
|
38
|
+
}
|
|
39
|
+
function toRuntimeConfig(fileConfig, root, flags, profile, profileName) {
|
|
40
|
+
const output = {
|
|
41
|
+
...default_config_1.DEFAULT_PRODEX_CONFIG.output,
|
|
42
|
+
...fileConfig.output,
|
|
43
|
+
};
|
|
44
|
+
const resolve = {
|
|
45
|
+
...default_config_1.DEFAULT_PRODEX_CONFIG.resolve,
|
|
46
|
+
...fileConfig.resolve,
|
|
47
|
+
};
|
|
48
|
+
const cfg = {
|
|
49
|
+
...fileConfig,
|
|
50
|
+
output,
|
|
51
|
+
resolve,
|
|
52
|
+
entry: fileConfig.entry ?? [],
|
|
53
|
+
include: fileConfig.include ?? [],
|
|
54
|
+
exclude: fileConfig.exclude ?? [],
|
|
55
|
+
profiles: fileConfig.profiles ?? {},
|
|
56
|
+
root,
|
|
57
|
+
name: flags?.name ?? profile?.name ?? profileName,
|
|
58
|
+
};
|
|
59
|
+
applyExplicitFlags(cfg, flags);
|
|
60
|
+
return cfg;
|
|
61
|
+
}
|
|
62
|
+
function applyExplicitFlags(cfg, flags) {
|
|
63
|
+
if (!flags)
|
|
64
|
+
return;
|
|
65
|
+
if (flags.format !== undefined)
|
|
66
|
+
cfg.output.format = flags.format;
|
|
67
|
+
if (flags.name !== undefined && flags.name !== null)
|
|
68
|
+
cfg.name = (0, path_2.sanitizeFileName)(flags.name);
|
|
69
|
+
if (flags.maxDepth !== undefined && flags.maxDepth !== null)
|
|
70
|
+
cfg.resolve.maxDepth = flags.maxDepth;
|
|
71
|
+
if (flags.maxFiles !== undefined && flags.maxFiles !== null)
|
|
72
|
+
cfg.resolve.maxFiles = flags.maxFiles;
|
|
73
|
+
if (flags.entry !== undefined)
|
|
74
|
+
cfg.entry = flags.entry;
|
|
75
|
+
if (flags.include !== undefined)
|
|
76
|
+
cfg.include = flags.include;
|
|
77
|
+
if (flags.exclude !== undefined)
|
|
78
|
+
cfg.exclude = flags.exclude;
|
|
79
|
+
}
|
|
80
|
+
function normalizeRuntimeConfig(cfg, warnings) {
|
|
81
|
+
cfg.root = path_1.default.resolve(cfg.root);
|
|
82
|
+
cfg.output.dir = (0, path_2.normalizePath)(String(cfg.output.dir || "prodex"));
|
|
83
|
+
cfg.name = cfg.name ? (0, path_2.sanitizeFileName)(String(cfg.name)) : undefined;
|
|
84
|
+
cfg.entry = normalizePatterns(cfg.entry, warnings, "entry");
|
|
85
|
+
cfg.include = normalizePatterns(cfg.include, warnings, "include");
|
|
86
|
+
cfg.exclude = normalizePatterns(cfg.exclude, warnings, "exclude");
|
|
87
|
+
cfg.resolve.aliases = cfg.resolve.aliases ?? {};
|
|
88
|
+
cfg.profiles = cfg.profiles ?? {};
|
|
89
|
+
}
|
|
90
|
+
function normalizePatterns(value, warnings, field) {
|
|
91
|
+
const normalized = [];
|
|
92
|
+
for (const item of (0, string_list_1.toStringList)(value))
|
|
93
|
+
normalized.push((0, path_2.normalizePath)(item));
|
|
94
|
+
if (!Array.isArray(value) && value !== undefined && typeof value !== "string") {
|
|
95
|
+
warnings.push(`${field} should be a string array; ignoring invalid value.`);
|
|
96
|
+
}
|
|
97
|
+
return normalized;
|
|
98
|
+
}
|
|
99
|
+
function validateRuntimeConfig(cfg, errors) {
|
|
100
|
+
if (!["md", "txt"].includes(cfg.output.format)) {
|
|
101
|
+
errors.push(`output.format must be "md" or "txt".`);
|
|
102
|
+
}
|
|
103
|
+
if (!Number.isFinite(cfg.resolve.maxDepth) || cfg.resolve.maxDepth < 0) {
|
|
104
|
+
errors.push("resolve.maxDepth must be a non-negative number.");
|
|
105
|
+
}
|
|
106
|
+
if (!Number.isFinite(cfg.resolve.maxFiles) || cfg.resolve.maxFiles < 0) {
|
|
107
|
+
errors.push("resolve.maxFiles must be a non-negative number.");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function deepMerge(base, patch) {
|
|
111
|
+
const out = Array.isArray(base) ? [...base] : { ...base };
|
|
112
|
+
for (const [key, value] of Object.entries(patch || {})) {
|
|
113
|
+
if (value === undefined)
|
|
114
|
+
continue;
|
|
115
|
+
const current = base[key];
|
|
116
|
+
if (Array.isArray(value))
|
|
117
|
+
out[key] = [...value];
|
|
118
|
+
else if (isPlainObject(value) && isPlainObject(current))
|
|
119
|
+
out[key] = deepMerge(current, value);
|
|
120
|
+
else
|
|
121
|
+
out[key] = value;
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
function isPlainObject(value) {
|
|
126
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
127
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createDefaultConfig = createDefaultConfig;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const default_config_1 = require("./default-config");
|
|
10
|
+
function createDefaultConfig(root = process.cwd(), opts = {}) {
|
|
11
|
+
const dest = path_1.default.join(root, "prodex.json");
|
|
12
|
+
if (fs_1.default.existsSync(dest) && !opts.force) {
|
|
13
|
+
return {
|
|
14
|
+
ok: false,
|
|
15
|
+
path: dest,
|
|
16
|
+
error: "prodex.json already exists.",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
fs_1.default.writeFileSync(dest, `${JSON.stringify(default_config_1.DEFAULT_PRODEX_CONFIG, null, 4)}\n`, "utf8");
|
|
20
|
+
return {
|
|
21
|
+
ok: true,
|
|
22
|
+
path: dest,
|
|
23
|
+
message: `Created ${dest}`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PRODEX_CONFIG = void 0;
|
|
4
|
+
exports.DEFAULT_PRODEX_CONFIG = {
|
|
5
|
+
version: 4,
|
|
6
|
+
$schema: "https://raw.githubusercontent.com/emxhive/prodex/main/schema/prodex.schema.json",
|
|
7
|
+
output: {
|
|
8
|
+
dir: "prodex",
|
|
9
|
+
versioned: true,
|
|
10
|
+
format: "md",
|
|
11
|
+
},
|
|
12
|
+
entry: [],
|
|
13
|
+
include: [],
|
|
14
|
+
exclude: ["node_modules/**", "vendor/**", "dist/**", "@shadcn/**", "**/components/ui/**"],
|
|
15
|
+
resolve: {
|
|
16
|
+
aliases: {
|
|
17
|
+
"@": "resources/js",
|
|
18
|
+
},
|
|
19
|
+
maxDepth: 10,
|
|
20
|
+
maxFiles: 200,
|
|
21
|
+
},
|
|
22
|
+
profiles: {},
|
|
23
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseJsonFile = parseJsonFile;
|
|
4
|
+
exports.stripBom = stripBom;
|
|
5
|
+
function parseJsonFile(text) {
|
|
6
|
+
return JSON.parse(stripBom(text));
|
|
7
|
+
}
|
|
8
|
+
function stripBom(text) {
|
|
9
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProdexConfigFile } from "../types";
|
|
2
|
+
export interface LoadConfigResult {
|
|
3
|
+
config: ProdexConfigFile;
|
|
4
|
+
path: string;
|
|
5
|
+
warnings: string[];
|
|
6
|
+
errors: string[];
|
|
7
|
+
exists: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function loadConfig(root: string): LoadConfigResult;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadConfig = loadConfig;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const default_config_1 = require("./default-config");
|
|
10
|
+
const migration_1 = require("./migration");
|
|
11
|
+
const json_1 = require("./json");
|
|
12
|
+
function loadConfig(root) {
|
|
13
|
+
const configPath = path_1.default.join(root, "prodex.json");
|
|
14
|
+
const warnings = [];
|
|
15
|
+
const errors = [];
|
|
16
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
17
|
+
return {
|
|
18
|
+
config: default_config_1.DEFAULT_PRODEX_CONFIG,
|
|
19
|
+
path: configPath,
|
|
20
|
+
warnings,
|
|
21
|
+
errors,
|
|
22
|
+
exists: false,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const parsed = (0, json_1.parseJsonFile)(fs_1.default.readFileSync(configPath, "utf8"));
|
|
27
|
+
if ((0, migration_1.requiresConfigMigration)(parsed)) {
|
|
28
|
+
errors.push((0, migration_1.isOutdatedConfig)(parsed) ? (0, migration_1.configVersionError)(parsed.version) : (0, migration_1.legacyConfigShapeError)());
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
config: parsed,
|
|
32
|
+
path: configPath,
|
|
33
|
+
warnings,
|
|
34
|
+
errors,
|
|
35
|
+
exists: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
errors.push(`Invalid prodex.json: ${err?.message || err}`);
|
|
40
|
+
return {
|
|
41
|
+
config: default_config_1.DEFAULT_PRODEX_CONFIG,
|
|
42
|
+
path: configPath,
|
|
43
|
+
warnings,
|
|
44
|
+
errors,
|
|
45
|
+
exists: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUIRED_CONFIG_VERSION = void 0;
|
|
4
|
+
exports.isOutdatedConfig = isOutdatedConfig;
|
|
5
|
+
exports.requiresConfigMigration = requiresConfigMigration;
|
|
6
|
+
exports.looksLikeLegacyConfig = looksLikeLegacyConfig;
|
|
7
|
+
exports.REQUIRED_CONFIG_VERSION = 4;
|
|
8
|
+
function isOutdatedConfig(config) {
|
|
9
|
+
return typeof config?.version === "number" && config.version < exports.REQUIRED_CONFIG_VERSION;
|
|
10
|
+
}
|
|
11
|
+
function requiresConfigMigration(config) {
|
|
12
|
+
return isOutdatedConfig(config) || looksLikeLegacyConfig(config);
|
|
13
|
+
}
|
|
14
|
+
function looksLikeLegacyConfig(config) {
|
|
15
|
+
return !!(config?.shortcuts ||
|
|
16
|
+
config?.entry?.files ||
|
|
17
|
+
config?.resolve?.include ||
|
|
18
|
+
config?.resolve?.exclude ||
|
|
19
|
+
config?.resolve?.depth ||
|
|
20
|
+
config?.resolve?.limit ||
|
|
21
|
+
config?.output?.prefix);
|
|
22
|
+
}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./detect"), exports);
|
|
18
|
+
__exportStar(require("./messages"), exports);
|
|
19
|
+
__exportStar(require("./transform"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configVersionError = configVersionError;
|
|
4
|
+
exports.legacyConfigShapeError = legacyConfigShapeError;
|
|
5
|
+
const detect_1 = require("./detect");
|
|
6
|
+
const V4_CHANGES = [
|
|
7
|
+
"Prodex v4 changed the config shape:",
|
|
8
|
+
" entry.files -> entry",
|
|
9
|
+
" resolve.include -> include",
|
|
10
|
+
" resolve.exclude -> exclude",
|
|
11
|
+
" resolve.depth -> resolve.maxDepth",
|
|
12
|
+
" resolve.limit -> resolve.maxFiles",
|
|
13
|
+
" shortcuts -> profiles",
|
|
14
|
+
"",
|
|
15
|
+
"Preview migration:",
|
|
16
|
+
" prodex migrate",
|
|
17
|
+
"",
|
|
18
|
+
"Update prodex.json:",
|
|
19
|
+
" prodex migrate --write",
|
|
20
|
+
];
|
|
21
|
+
function configVersionError(version) {
|
|
22
|
+
const label = typeof version === "number" ? String(version) : "an older format";
|
|
23
|
+
return [
|
|
24
|
+
`prodex.json uses config version ${label}, but this Prodex version requires config version ${detect_1.REQUIRED_CONFIG_VERSION}.`,
|
|
25
|
+
"",
|
|
26
|
+
...V4_CHANGES,
|
|
27
|
+
].join("\n");
|
|
28
|
+
}
|
|
29
|
+
function legacyConfigShapeError() {
|
|
30
|
+
return [
|
|
31
|
+
"prodex.json contains legacy config fields that must be migrated to config version 4.",
|
|
32
|
+
"",
|
|
33
|
+
...V4_CHANGES,
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|