@farris/cli 2.2.5 → 2.3.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/lib/commands/add-app.js +6 -0
- package/lib/commands/add-app.js.map +1 -0
- package/lib/commands/add-lib.js +6 -0
- package/lib/commands/add-lib.js.map +1 -0
- package/lib/commands/add-project.js +194 -0
- package/lib/commands/add-project.js.map +1 -0
- package/lib/commands/build-components.js +57 -50
- package/lib/commands/build-components.js.map +1 -1
- package/lib/commands/build-css.js +38 -38
- package/lib/commands/build-css.js.map +1 -1
- package/lib/commands/build-lib.js +30 -25
- package/lib/commands/build-lib.js.map +1 -1
- package/lib/commands/build.js +19 -14
- package/lib/commands/build.js.map +1 -1
- package/lib/commands/create-app-options.js +72 -74
- package/lib/commands/create-app-options.js.map +1 -1
- package/lib/commands/create-app.js +131 -126
- package/lib/commands/create-app.js.map +1 -1
- package/lib/commands/create-options.js +32 -29
- package/lib/commands/create-options.js.map +1 -1
- package/lib/commands/create.js +277 -224
- package/lib/commands/create.js.map +1 -1
- package/lib/commands/dev-serve.js +18 -18
- package/lib/commands/extract-i18n.js +74 -74
- package/lib/commands/extract-i18n.js.map +1 -1
- package/lib/commands/generate/api.js +124 -124
- package/lib/commands/generate/api.js.map +1 -1
- package/lib/commands/generate/common.js +101 -100
- package/lib/commands/generate/common.js.map +1 -1
- package/lib/commands/generate/component.js +156 -156
- package/lib/commands/generate/component.js.map +1 -1
- package/lib/commands/generate/view.js +168 -168
- package/lib/commands/generate/view.js.map +1 -1
- package/lib/commands/preview-serve.js +16 -16
- package/lib/commands/workspace/add-app.js +15 -180
- package/lib/commands/workspace/add-app.js.map +1 -1
- package/lib/commands/workspace/create.js +62 -379
- package/lib/commands/workspace/create.js.map +1 -1
- package/lib/commands/workspace/inspect.js +30 -30
- package/lib/commands/workspace/inspect.js.map +1 -1
- package/lib/commands/workspace/verify.js +38 -38
- package/lib/commands/workspace/verify.js.map +1 -1
- package/lib/common/agents-doc.js +34 -0
- package/lib/common/agents-doc.js.map +1 -0
- package/lib/common/apply-catalog-deps.js +15 -15
- package/lib/common/apply-catalog-deps.js.map +1 -1
- package/lib/common/component-file-name.js +3 -3
- package/lib/common/constant.js +64 -64
- package/lib/common/constant.js.map +1 -1
- package/lib/common/create-app-target.js +46 -46
- package/lib/common/create-app-target.js.map +1 -1
- package/lib/common/generate-app.js +109 -85
- package/lib/common/generate-app.js.map +1 -1
- package/lib/common/get-dependencies.js +9 -9
- package/lib/common/get-farris-config.js +25 -25
- package/lib/common/get-farris-config.js.map +1 -1
- package/lib/common/get-version.js +6 -6
- package/lib/common/get-vite-config.js +106 -106
- package/lib/common/get-vite-config.js.map +1 -1
- package/lib/common/lib-package-exports.js +24 -24
- package/lib/common/lib-package-exports.js.map +1 -1
- package/lib/common/list-lib-components.js +23 -23
- package/lib/common/list-lib-components.js.map +1 -1
- package/lib/common/output.js +164 -94
- package/lib/common/output.js.map +1 -1
- package/lib/common/project-layout.js +143 -0
- package/lib/common/project-layout.js.map +1 -0
- package/lib/common/safety.js +173 -171
- package/lib/common/safety.js.map +1 -1
- package/lib/common/template-manifest.js +14 -16
- package/lib/common/template-manifest.js.map +1 -1
- package/lib/common/template-renderer.js +114 -114
- package/lib/common/template-renderer.js.map +1 -1
- package/lib/common/transaction.js +83 -83
- package/lib/common/transaction.js.map +1 -1
- package/lib/common/verifier.js +194 -150
- package/lib/common/verifier.js.map +1 -1
- package/lib/common/workspace-contract.js +86 -0
- package/lib/common/workspace-contract.js.map +1 -0
- package/lib/config/vite-app.js +13 -13
- package/lib/config/vite-common.js +20 -20
- package/lib/config/vite-common.js.map +1 -1
- package/lib/config/vite-component.js +32 -32
- package/lib/config/vite-component.js.map +1 -1
- package/lib/config/vite-lib.js +26 -26
- package/lib/index.js +234 -205
- package/lib/index.js.map +1 -1
- package/lib/plugins/create-app-package-json.js +24 -0
- package/lib/plugins/create-app-package-json.js.map +1 -0
- package/lib/plugins/create-component-style.js +44 -44
- package/lib/plugins/create-package-json.js +48 -48
- package/lib/plugins/create-package-json.js.map +1 -1
- package/lib/plugins/dts.js +8 -8
- package/lib/plugins/html-system.js +9 -9
- package/lib/plugins/replace.js +17 -17
- package/lib/plugins/systemjs-bundle.js +15 -15
- package/lib/plugins/systemjs-bundle.js.map +1 -1
- package/package.json +53 -52
- package/templates/create/.gitignore.tpl +12 -0
- package/templates/create/.npmrc.tpl +1 -0
- package/templates/create/AGENTS.md +62 -0
- package/templates/create/CLAUDE.md +1 -0
- package/templates/create/README.md +14 -1
- package/templates/create/package.json +11 -3
- package/templates/create/pnpm-workspace.yaml +2 -1
- package/templates/lib/.eslintrc.cjs +15 -0
- package/templates/lib/.gitignore.tpl +3 -0
- package/templates/lib/.prettierrc.json +8 -0
- package/templates/lib/index.html +1 -1
- package/templates/lib/package.json +39 -4
- package/templates/lib/{components → test/components}/button/button.spec.ts +3 -2
- package/templates/lib/test/components/button/button.spec.tsx +11 -0
- package/templates/lib/tsconfig.json +5 -1
- package/templates/lib/vitest.config.ts +1 -1
- package/templates/mobile/.gitignore.tpl +31 -0
- package/templates/mobile/.gitlab-ci.yml +3 -9
- package/templates/mobile/index.html +1 -1
- package/templates/mobile/package.json +14 -10
- package/templates/mobile/src/main.ts +5 -4
- package/templates/mobile/src/router/index.ts +17 -17
- package/templates/mobile/test/src/components/TheButton.spec.ts +15 -0
- package/templates/mobile/test/src/components/TheButton.spec.tsx +15 -0
- package/templates/mobile/tsconfig.json +3 -2
- package/templates/mobile/vitest.config.ts +2 -1
- package/templates/web/.gitignore.tpl +31 -0
- package/templates/web/.gitlab-ci.yml +3 -9
- package/templates/web/index.html +1 -1
- package/templates/web/package.json +14 -10
- package/templates/web/src/locales/index.ts +5 -0
- package/templates/web/src/locales/zh-CN.json +1 -0
- package/templates/web/src/main.ts +5 -2
- package/templates/web/src/router/index.ts +17 -17
- package/templates/web/src/styles/index.css +0 -0
- package/templates/web/src/styles/index.scss +0 -0
- package/templates/web/test/src/components/TheButton.spec.ts +15 -0
- package/templates/web/test/src/components/TheButton.spec.tsx +15 -0
- package/templates/web/tsconfig.json +3 -2
- package/templates/web/vitest.config.ts +2 -1
- package/lib/common/project-package-name.js +0 -5
- package/lib/common/project-package-name.js.map +0 -1
- package/templates/mobile/.changeset/README.md +0 -4
- package/templates/mobile/.changeset/config.json +0 -11
- package/templates/mobile/project.json +0 -4
- package/templates/mobile/src/components/TheButton.spec.ts +0 -8
- package/templates/web/.changeset/README.md +0 -4
- package/templates/web/.changeset/config.json +0 -11
- package/templates/web/project.json +0 -4
- package/templates/web/src/components/TheButton.spec.ts +0 -8
- package/templates/workspace/app/farris.config.mjs +0 -13
- package/templates/workspace/app/index.html +0 -12
- package/templates/workspace/app/package.json +0 -22
- package/templates/workspace/app/src/App.tsx +0 -11
- package/templates/workspace/app/src/main.ts +0 -12
- package/templates/workspace/app/src/router/index.ts +0 -16
- package/templates/workspace/app/src/views/home/composables/use-home.ts +0 -7
- package/templates/workspace/app/src/views/home/home.component.tsx +0 -15
- package/templates/workspace/app/src/views/home/index.ts +0 -4
- package/templates/workspace/app/tsconfig.json +0 -21
- package/templates/workspace/root/README.md +0 -28
- package/templates/workspace/root/package.json +0 -13
- package/templates/workspace/root/pnpm-workspace.yaml +0 -12
- /package/templates/{workspace/app → mobile}/src/locales/index.ts +0 -0
- /package/templates/{workspace/app → mobile}/src/locales/zh-CN.json +0 -0
- /package/templates/{workspace/app → mobile}/src/styles/index.css +0 -0
- /package/templates/{workspace/app → mobile}/src/styles/index.scss +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { listProjects } from './project-layout.js';
|
|
4
|
+
import { renderProjectList } from './workspace-contract.js';
|
|
5
|
+
export const AGENTS_DOC_NAME = 'AGENTS.md';
|
|
6
|
+
export const AGENTS_PROJECTS_START = '<!-- projects:start -->';
|
|
7
|
+
export const AGENTS_PROJECTS_END = '<!-- projects:end -->';
|
|
8
|
+
/**
|
|
9
|
+
* 用真实工程列表刷新 AGENTS.md 的子工程清单区块。
|
|
10
|
+
* 文件或标记缺失时返回 false,由调用方决定是否告警(不作为失败原因,见设计文档 §8.1 第 3 条)。
|
|
11
|
+
*/
|
|
12
|
+
export function refreshAgentsProjectList(wsRoot) {
|
|
13
|
+
const agentsPath = join(wsRoot, AGENTS_DOC_NAME);
|
|
14
|
+
if (!existsSync(agentsPath)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const content = readFileSync(agentsPath, 'utf-8');
|
|
18
|
+
const start = content.indexOf(AGENTS_PROJECTS_START);
|
|
19
|
+
const end = content.indexOf(AGENTS_PROJECTS_END);
|
|
20
|
+
if (start === -1 || end === -1 || end < start) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const block = [
|
|
24
|
+
AGENTS_PROJECTS_START,
|
|
25
|
+
renderProjectList(listProjects(wsRoot)),
|
|
26
|
+
AGENTS_PROJECTS_END
|
|
27
|
+
].join('\n');
|
|
28
|
+
const next = content.slice(0, start) + block + content.slice(end + AGENTS_PROJECTS_END.length);
|
|
29
|
+
if (next !== content) {
|
|
30
|
+
writeFileSync(agentsPath, next, 'utf-8');
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=agents-doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents-doc.js","sourceRoot":"","sources":["../../src/common/agents-doc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,C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ERSIONS).filter((key) => key !== 'pnpm');
|
|
4
|
-
for (const section of ['dependencies', 'devDependencies']) {
|
|
5
|
-
const block = pkg[section];
|
|
6
|
-
if (!block || typeof block !== 'object') {
|
|
7
|
-
continue;
|
|
8
|
-
}
|
|
9
|
-
for (const key of keys) {
|
|
10
|
-
if (block[key] !== undefined) {
|
|
11
|
-
block[key] = 'catalog:';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import { DEFAULT_CATALOG_VERSIONS } from './constant.js';
|
|
2
|
+
export function applyCatalogDeps(pkg) {
|
|
3
|
+
const keys = Object.keys(DEFAULT_CATALOG_VERSIONS).filter((key) => key !== 'pnpm');
|
|
4
|
+
for (const section of ['dependencies', 'devDependencies']) {
|
|
5
|
+
const block = pkg[section];
|
|
6
|
+
if (!block || typeof block !== 'object') {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
for (const key of keys) {
|
|
10
|
+
if (block[key] !== undefined) {
|
|
11
|
+
block[key] = 'catalog:';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
16
|
//# sourceMappingURL=apply-catalog-deps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-catalog-deps.js","sourceRoot":"","sources":["../../src/common/apply-catalog-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,UAAU,gBAAgB,CAAC,GAAwB;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;IACnF,KAAK,MAAM,OAAO,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAU,EAAE
|
|
1
|
+
{"version":3,"file":"apply-catalog-deps.js","sourceRoot":"","sources":["../../src/common/apply-catalog-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,UAAU,gBAAgB,CAAC,GAAwB;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;IACnF,KAAK,MAAM,OAAO,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAU,EAAE;QAClE,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACvC,SAAS;SACV;QACD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;gBAC5B,KAAK,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;aACzB;SACF;KACF;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function componentFileName(_format, entryName) {
|
|
2
|
-
return `${entryName}/index.esm.js`;
|
|
3
|
-
}
|
|
1
|
+
export function componentFileName(_format, entryName) {
|
|
2
|
+
return `${entryName}/index.esm.js`;
|
|
3
|
+
}
|
|
4
4
|
//# sourceMappingURL=component-file-name.js.map
|
package/lib/common/constant.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { join, dirname } from 'node:path';
|
|
4
|
-
import { getVersion } from './get-version.js';
|
|
5
|
-
function findRootDir(dir) {
|
|
6
|
-
if (existsSync(join(dir, 'farris.config.js')) || existsSync(join(dir, 'farris.config.mjs'))) {
|
|
7
|
-
return dir;
|
|
8
|
-
}
|
|
9
|
-
const parentDir = dirname(dir);
|
|
10
|
-
if (dir === parentDir) {
|
|
11
|
-
return dir;
|
|
12
|
-
}
|
|
13
|
-
return findRootDir(parentDir);
|
|
14
|
-
}
|
|
15
|
-
export const getDirname = (url) => fileURLToPath(new URL('.', url));
|
|
16
|
-
// Root paths
|
|
17
|
-
export const CWD = process.cwd();
|
|
18
|
-
export const ROOT = findRootDir(CWD);
|
|
19
|
-
export const FAARIS_CONFIG_FILE = join(CWD, 'farris.config.mjs');
|
|
20
|
-
export const getPackageName = () => {
|
|
21
|
-
const { PackageName = '@components' } = process.env;
|
|
22
|
-
return PackageName;
|
|
23
|
-
};
|
|
24
|
-
// Schema & Version Baseline
|
|
25
|
-
export const SCHEMA_VERSION = 1;
|
|
26
|
-
export const CLI_VERSION = getVersion();
|
|
27
|
-
// Catalog Dependency Versions Baseline
|
|
28
|
-
export const DEFAULT_CATALOG_VERSIONS = {
|
|
29
|
-
'@farris/ui-vue': '1.8.5-beta.4',
|
|
30
|
-
'@farris/cli': CLI_VERSION,
|
|
31
|
-
'typescript': '5.7.3',
|
|
32
|
-
'vite': '5.4.19',
|
|
33
|
-
'vue': '3.5.13',
|
|
34
|
-
'vue-router': '4.5.0',
|
|
35
|
-
'vue-tsc': '2.2.0',
|
|
36
|
-
'sass': '1.90.0',
|
|
37
|
-
'pnpm': '9.15.4'
|
|
38
|
-
};
|
|
39
|
-
// Standard Engines
|
|
40
|
-
export const DEFAULT_ENGINES = {
|
|
41
|
-
node: '^18.0.0 || >=20.0.0',
|
|
42
|
-
pnpm: '>=9.0.0 <10.0.0'
|
|
43
|
-
};
|
|
44
|
-
// Exit Codes
|
|
45
|
-
export var ExitCode;
|
|
46
|
-
(function (ExitCode) {
|
|
47
|
-
ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
|
|
48
|
-
ExitCode[ExitCode["GENERAL_ERROR"] = 1] = "GENERAL_ERROR";
|
|
49
|
-
ExitCode[ExitCode["TARGET_CONFLICT"] = 2] = "TARGET_CONFLICT";
|
|
50
|
-
ExitCode[ExitCode["VERIFY_FAILED"] = 3] = "VERIFY_FAILED";
|
|
51
|
-
ExitCode[ExitCode["FS_ERROR"] = 4] = "FS_ERROR";
|
|
52
|
-
})(ExitCode || (ExitCode = {}));
|
|
53
|
-
// Workspace Safety Status
|
|
54
|
-
export var WorkspaceStatus;
|
|
55
|
-
(function (WorkspaceStatus) {
|
|
56
|
-
WorkspaceStatus["MISSING"] = "missing";
|
|
57
|
-
WorkspaceStatus["EMPTY"] = "empty";
|
|
58
|
-
WorkspaceStatus["AI_CONFIG_ONLY"] = "ai-config-only";
|
|
59
|
-
WorkspaceStatus["PRESERVED_INPUT_ONLY"] = "preserved-input-only";
|
|
60
|
-
WorkspaceStatus["EXISTING_WORKSPACE"] = "existing-workspace";
|
|
61
|
-
WorkspaceStatus["EXISTING_OR_UNKNOWN_PROJECT"] = "existing-or-unknown-project";
|
|
62
|
-
WorkspaceStatus["NON_EMPTY_PROJECT"] = "non-empty-project";
|
|
63
|
-
WorkspaceStatus["INVALID_TARGET"] = "invalid-target";
|
|
64
|
-
})(WorkspaceStatus || (WorkspaceStatus = {}));
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { join, dirname } from 'node:path';
|
|
4
|
+
import { getVersion } from './get-version.js';
|
|
5
|
+
function findRootDir(dir) {
|
|
6
|
+
if (existsSync(join(dir, 'farris.config.js')) || existsSync(join(dir, 'farris.config.mjs'))) {
|
|
7
|
+
return dir;
|
|
8
|
+
}
|
|
9
|
+
const parentDir = dirname(dir);
|
|
10
|
+
if (dir === parentDir) {
|
|
11
|
+
return dir;
|
|
12
|
+
}
|
|
13
|
+
return findRootDir(parentDir);
|
|
14
|
+
}
|
|
15
|
+
export const getDirname = (url) => fileURLToPath(new URL('.', url));
|
|
16
|
+
// Root paths
|
|
17
|
+
export const CWD = process.cwd();
|
|
18
|
+
export const ROOT = findRootDir(CWD);
|
|
19
|
+
export const FAARIS_CONFIG_FILE = join(CWD, 'farris.config.mjs');
|
|
20
|
+
export const getPackageName = () => {
|
|
21
|
+
const { PackageName = '@components' } = process.env;
|
|
22
|
+
return PackageName;
|
|
23
|
+
};
|
|
24
|
+
// Schema & Version Baseline
|
|
25
|
+
export const SCHEMA_VERSION = 1;
|
|
26
|
+
export const CLI_VERSION = getVersion();
|
|
27
|
+
// Catalog Dependency Versions Baseline
|
|
28
|
+
export const DEFAULT_CATALOG_VERSIONS = {
|
|
29
|
+
'@farris/ui-vue': '1.8.5-beta.4',
|
|
30
|
+
'@farris/cli': CLI_VERSION,
|
|
31
|
+
'typescript': '5.7.3',
|
|
32
|
+
'vite': '5.4.19',
|
|
33
|
+
'vue': '3.5.13',
|
|
34
|
+
'vue-router': '4.5.0',
|
|
35
|
+
'vue-tsc': '2.2.0',
|
|
36
|
+
'sass': '1.90.0',
|
|
37
|
+
'pnpm': '9.15.4'
|
|
38
|
+
};
|
|
39
|
+
// Standard Engines
|
|
40
|
+
export const DEFAULT_ENGINES = {
|
|
41
|
+
node: '^18.0.0 || >=20.0.0',
|
|
42
|
+
pnpm: '>=9.0.0 <10.0.0'
|
|
43
|
+
};
|
|
44
|
+
// Exit Codes
|
|
45
|
+
export var ExitCode;
|
|
46
|
+
(function (ExitCode) {
|
|
47
|
+
ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
|
|
48
|
+
ExitCode[ExitCode["GENERAL_ERROR"] = 1] = "GENERAL_ERROR";
|
|
49
|
+
ExitCode[ExitCode["TARGET_CONFLICT"] = 2] = "TARGET_CONFLICT";
|
|
50
|
+
ExitCode[ExitCode["VERIFY_FAILED"] = 3] = "VERIFY_FAILED";
|
|
51
|
+
ExitCode[ExitCode["FS_ERROR"] = 4] = "FS_ERROR";
|
|
52
|
+
})(ExitCode || (ExitCode = {}));
|
|
53
|
+
// Workspace Safety Status
|
|
54
|
+
export var WorkspaceStatus;
|
|
55
|
+
(function (WorkspaceStatus) {
|
|
56
|
+
WorkspaceStatus["MISSING"] = "missing";
|
|
57
|
+
WorkspaceStatus["EMPTY"] = "empty";
|
|
58
|
+
WorkspaceStatus["AI_CONFIG_ONLY"] = "ai-config-only";
|
|
59
|
+
WorkspaceStatus["PRESERVED_INPUT_ONLY"] = "preserved-input-only";
|
|
60
|
+
WorkspaceStatus["EXISTING_WORKSPACE"] = "existing-workspace";
|
|
61
|
+
WorkspaceStatus["EXISTING_OR_UNKNOWN_PROJECT"] = "existing-or-unknown-project";
|
|
62
|
+
WorkspaceStatus["NON_EMPTY_PROJECT"] = "non-empty-project";
|
|
63
|
+
WorkspaceStatus["INVALID_TARGET"] = "invalid-target";
|
|
64
|
+
})(WorkspaceStatus || (WorkspaceStatus = {}));
|
|
65
65
|
//# sourceMappingURL=constant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/common/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,SAAS,WAAW,CAAC,GAAW;IAC5B,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC,EAAE
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/common/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,SAAS,WAAW,CAAC,GAAW;IAC5B,IAAI,UAAU,C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QAAQ;CACnB,CAAC;AAEF,mBAAmB;AACnB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE,iBAAiB;CAC1B,CAAC;AAEF,aAAa;AACb,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAChB,6CAAW,CAAA;IACX,yDAAiB,CAAA;IACjB,6DAAmB,CAAA;IACnB,yDAAiB,CAAA;IACjB,+CAAY,CAAA;AAChB,CAAC,EANW,QAAQ,KAAR,QAAQ,QAMnB;AAED,0BAA0B;AAC1B,MAAM,CAAN,IAAY,eASX;AATD,WAAY,eAAe;IACvB,sCAAmB,CAAA;IACnB,kCAAe,CAAA;IACf,oDAAiC,CAAA;IACjC,gEAA6C,CAAA;IAC7C,4DAAyC,CAAA;IACzC,8EAA2D,CAAA;IAC3D,0DAAuC,CAAA;IACvC,oDAAiC,CAAA;AACrC,CAAC,EATW,eAAe,KAAf,eAAe,QAS1B"}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
-
import { ExitCode } from './constant.js';
|
|
3
|
-
export class CreateAppError extends Error {
|
|
4
|
-
constructor(message, exitCode = ExitCode.GENERAL_ERROR) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = 'CreateAppError';
|
|
7
|
-
this.exitCode = exitCode;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function isValidPackageName(name) {
|
|
11
|
-
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name);
|
|
12
|
-
}
|
|
13
|
-
export function toValidPackageName(name) {
|
|
14
|
-
return name
|
|
15
|
-
.trim()
|
|
16
|
-
.toLowerCase()
|
|
17
|
-
.replace(/\s+/g, '-')
|
|
18
|
-
.replace(/^[._]/, '')
|
|
19
|
-
.replace(/[^a-z0-9-~]+/g, '-')
|
|
20
|
-
.replace(/^-+|-+$/g, '');
|
|
21
|
-
}
|
|
22
|
-
export function resolvePackageName(name) {
|
|
23
|
-
const trimmed = name.trim();
|
|
24
|
-
if (isValidPackageName(trimmed)) {
|
|
25
|
-
return trimmed;
|
|
26
|
-
}
|
|
27
|
-
const derived = toValidPackageName(trimmed);
|
|
28
|
-
if (!derived || !isValidPackageName(derived)) {
|
|
29
|
-
throw new CreateAppError(`无法从目标名推导合法包名: ${name}`);
|
|
30
|
-
}
|
|
31
|
-
return derived;
|
|
32
|
-
}
|
|
33
|
-
export function assertTargetInsideCwd(name, cwd = process.cwd()) {
|
|
34
|
-
const trimmed = name.trim();
|
|
35
|
-
if (!trimmed || trimmed === '.' || trimmed === './') {
|
|
36
|
-
throw new CreateAppError('目标目录不能是当前目录');
|
|
37
|
-
}
|
|
38
|
-
if (trimmed.includes('\0')) {
|
|
39
|
-
throw new CreateAppError('目标路径包含非法字符');
|
|
40
|
-
}
|
|
41
|
-
const resolved = resolve(cwd, trimmed);
|
|
42
|
-
const rel = relative(cwd, resolved);
|
|
43
|
-
if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) {
|
|
44
|
-
throw new CreateAppError(`目标目录必须位于当前工作目录内: ${name}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
+
import { ExitCode } from './constant.js';
|
|
3
|
+
export class CreateAppError extends Error {
|
|
4
|
+
constructor(message, exitCode = ExitCode.GENERAL_ERROR) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'CreateAppError';
|
|
7
|
+
this.exitCode = exitCode;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function isValidPackageName(name) {
|
|
11
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name);
|
|
12
|
+
}
|
|
13
|
+
export function toValidPackageName(name) {
|
|
14
|
+
return name
|
|
15
|
+
.trim()
|
|
16
|
+
.toLowerCase()
|
|
17
|
+
.replace(/\s+/g, '-')
|
|
18
|
+
.replace(/^[._]/, '')
|
|
19
|
+
.replace(/[^a-z0-9-~]+/g, '-')
|
|
20
|
+
.replace(/^-+|-+$/g, '');
|
|
21
|
+
}
|
|
22
|
+
export function resolvePackageName(name) {
|
|
23
|
+
const trimmed = name.trim();
|
|
24
|
+
if (isValidPackageName(trimmed)) {
|
|
25
|
+
return trimmed;
|
|
26
|
+
}
|
|
27
|
+
const derived = toValidPackageName(trimmed);
|
|
28
|
+
if (!derived || !isValidPackageName(derived)) {
|
|
29
|
+
throw new CreateAppError(`无法从目标名推导合法包名: ${name}`);
|
|
30
|
+
}
|
|
31
|
+
return derived;
|
|
32
|
+
}
|
|
33
|
+
export function assertTargetInsideCwd(name, cwd = process.cwd()) {
|
|
34
|
+
const trimmed = name.trim();
|
|
35
|
+
if (!trimmed || trimmed === '.' || trimmed === './') {
|
|
36
|
+
throw new CreateAppError('目标目录不能是当前目录');
|
|
37
|
+
}
|
|
38
|
+
if (trimmed.includes('\0')) {
|
|
39
|
+
throw new CreateAppError('目标路径包含非法字符');
|
|
40
|
+
}
|
|
41
|
+
const resolved = resolve(cwd, trimmed);
|
|
42
|
+
const rel = relative(cwd, resolved);
|
|
43
|
+
if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) {
|
|
44
|
+
throw new CreateAppError(`目标目录必须位于当前工作目录内: ${name}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
47
|
//# sourceMappingURL=create-app-target.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app-target.js","sourceRoot":"","sources":["../../src/common/create-app-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGvC,YAAY,OAAe,EAAE,WAAqB,Q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AAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE;QACzD,MAAM,IAAI,cAAc,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;KACtD;AACH,CAAC"}
|
|
@@ -1,86 +1,110 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
-
import { getVersion } from './get-version.js';
|
|
4
|
-
import { logInfo } from './output.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { assertTargetInsideCwd, resolvePackageName } from './create-app-target.js';
|
|
8
|
-
export function toLibName(name) {
|
|
9
|
-
const unscoped = name.replace(/^@[^/]+\//, '');
|
|
10
|
-
return unscoped
|
|
11
|
-
.split(/[^A-Za-z0-9]+/)
|
|
12
|
-
.filter(Boolean)
|
|
13
|
-
.map((token) => token.charAt(0).toUpperCase() + token.slice(1))
|
|
14
|
-
.join('');
|
|
15
|
-
}
|
|
16
|
-
export function formatsLiteral(formats) {
|
|
17
|
-
if (!formats || formats.length === 0) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
import { existsSync, readdirSync, rmSync, rmdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
+
import { getVersion } from './get-version.js';
|
|
4
|
+
import { logInfo } from './output.js';
|
|
5
|
+
import { getTemplateDir, resolveTemplate } from './template-manifest.js';
|
|
6
|
+
import { renderTemplateDir } from './template-renderer.js';
|
|
7
|
+
import { assertTargetInsideCwd, resolvePackageName } from './create-app-target.js';
|
|
8
|
+
export function toLibName(name) {
|
|
9
|
+
const unscoped = name.replace(/^@[^/]+\//, '');
|
|
10
|
+
return unscoped
|
|
11
|
+
.split(/[^A-Za-z0-9]+/)
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.map((token) => token.charAt(0).toUpperCase() + token.slice(1))
|
|
14
|
+
.join('');
|
|
15
|
+
}
|
|
16
|
+
export function formatsLiteral(formats) {
|
|
17
|
+
if (!formats || formats.length === 0) {
|
|
18
|
+
return JSON.stringify(['es']);
|
|
19
|
+
}
|
|
20
|
+
return JSON.stringify(formats);
|
|
21
|
+
}
|
|
22
|
+
const STYLE_IMPORT = {
|
|
23
|
+
none: '',
|
|
24
|
+
css: "\nimport './styles/index.css';",
|
|
25
|
+
scss: "\nimport './styles/index.scss';"
|
|
26
|
+
};
|
|
27
|
+
/** 按样式方案裁剪 styles 目录;lib 不需要(其源码入口是 components/)。 */
|
|
28
|
+
export function appTemplateFilter(style) {
|
|
29
|
+
return (relativePath) => {
|
|
30
|
+
const normalized = relativePath.replace(/\\/g, '/');
|
|
31
|
+
if (style === 'none' && normalized.startsWith('src/styles')) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (style === 'css' && normalized === 'src/styles/index.scss') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (style === 'scss' && normalized === 'src/styles/index.css') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function buildTemplateVariables(input) {
|
|
44
|
+
return {
|
|
45
|
+
name: input.packageName,
|
|
46
|
+
appName: input.packageName,
|
|
47
|
+
title: input.title ?? input.packageName,
|
|
48
|
+
formats: formatsLiteral(input.formats),
|
|
49
|
+
format: input.format ?? '',
|
|
50
|
+
platform: input.platform ?? '',
|
|
51
|
+
cliVersion: getVersion(),
|
|
52
|
+
libName: toLibName(input.packageName),
|
|
53
|
+
styleImport: STYLE_IMPORT[input.style]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function rollbackCreatedTarget(targetPath, cwd) {
|
|
57
|
+
if (existsSync(targetPath)) {
|
|
58
|
+
rmSync(targetPath, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
let parent = dirname(targetPath);
|
|
61
|
+
while (parent !== cwd) {
|
|
62
|
+
const rel = relative(cwd, parent);
|
|
63
|
+
if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
// 父路径可能是文件(如 apps 是文件而目标是 apps/foo),readdirSync 会抛 ENOTDIR
|
|
67
|
+
if (!existsSync(parent) || !statSync(parent).isDirectory() || readdirSync(parent).length > 0) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
rmdirSync(parent);
|
|
71
|
+
parent = dirname(parent);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export const generateApp = (options) => {
|
|
75
|
+
const { name, type, formats, format, platform, style = 'css', title } = options;
|
|
76
|
+
const packageName = options.packageName ?? resolvePackageName(name);
|
|
77
|
+
const manifest = resolveTemplate({
|
|
78
|
+
type: type,
|
|
79
|
+
platform: platform
|
|
80
|
+
});
|
|
81
|
+
const templatePath = getTemplateDir(manifest.id);
|
|
82
|
+
const cwd = process.cwd();
|
|
83
|
+
assertTargetInsideCwd(name, cwd);
|
|
84
|
+
const targetPath = resolve(cwd, name);
|
|
85
|
+
const created = !existsSync(targetPath);
|
|
86
|
+
try {
|
|
87
|
+
const render = renderTemplateDir({
|
|
88
|
+
sourceDir: templatePath,
|
|
89
|
+
targetDir: targetPath,
|
|
90
|
+
variables: buildTemplateVariables({ packageName, formats, format, platform, style, title }),
|
|
91
|
+
filter: manifest.id === 'lib' ? undefined : appTemplateFilter(style)
|
|
92
|
+
});
|
|
93
|
+
if (render.unreplacedPlaceholders.length > 0) {
|
|
94
|
+
throw new Error(`模板渲染后仍存在未替换占位符: ${render.unreplacedPlaceholders
|
|
95
|
+
.map((item) => `${item.file} (${item.placeholder})`)
|
|
96
|
+
.join(', ')}`);
|
|
97
|
+
}
|
|
98
|
+
if (options.hints !== false) {
|
|
99
|
+
logInfo(`cd ${name}`);
|
|
100
|
+
logInfo(`npm install or yarn`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (created) {
|
|
105
|
+
rollbackCreatedTarget(targetPath, cwd);
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
86
110
|
//# sourceMappingURL=generate-app.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-app.js","sourceRoot":"","sources":["../../src/common/generate-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"generate-app.js","sourceRoot":"","sources":["../../src/common/generate-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO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CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YAC3F,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC;SACrE,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5C,MAAM,IAAI,KAAK,CACb,mBAAmB,MAAM,CAAC,sBAAsB;iBAC7C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,GAAG,CAAC;iBACnD,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;SACH;QAED,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE;YAC3B,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,qBAAqB,CAAC,CAAC;SAChC;KACF;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,OAAO,EAAE;YACX,qBAAqB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;SACxC;QACD,MAAM,KAAK,CAAC;KACb;AACH,CAAC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { CWD } from "../common/constant.js";
|
|
4
|
-
export const getDependencies = () => {
|
|
5
|
-
const pkg = readFileSync(resolve(CWD, 'package.json'), 'utf-8');
|
|
6
|
-
const packageJson = JSON.parse(pkg);
|
|
7
|
-
const { dependencies, peerDependencies } = packageJson;
|
|
8
|
-
return [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {})];
|
|
9
|
-
};
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { CWD } from "../common/constant.js";
|
|
4
|
+
export const getDependencies = () => {
|
|
5
|
+
const pkg = readFileSync(resolve(CWD, 'package.json'), 'utf-8');
|
|
6
|
+
const packageJson = JSON.parse(pkg);
|
|
7
|
+
const { dependencies, peerDependencies } = packageJson;
|
|
8
|
+
return [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {})];
|
|
9
|
+
};
|
|
10
10
|
//# sourceMappingURL=get-dependencies.js.map
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
export async function getFarrisConfigAsync(configFile) {
|
|
5
|
-
const cwd = process.cwd();
|
|
6
|
-
const explicit = configFile !== undefined && configFile !== '';
|
|
7
|
-
const resolved = resolve(cwd, explicit ? configFile : 'farris.config.mjs');
|
|
8
|
-
if (!existsSync(resolved)) {
|
|
9
|
-
if (explicit) {
|
|
10
|
-
throw new Error(`配置文件不存在: ${resolved}`);
|
|
11
|
-
}
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
const loaded = await import(pathToFileURL(resolved).href);
|
|
16
|
-
if (loaded.default === undefined) {
|
|
17
|
-
throw new Error('missing default export');
|
|
18
|
-
}
|
|
19
|
-
return loaded.default;
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
const cause = err instanceof Error ? err.message : String(err);
|
|
23
|
-
throw new Error(`Failed to load farris config: ${resolved} — ${cause}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
export async function getFarrisConfigAsync(configFile) {
|
|
5
|
+
const cwd = process.cwd();
|
|
6
|
+
const explicit = configFile !== undefined && configFile !== '';
|
|
7
|
+
const resolved = resolve(cwd, explicit ? configFile : 'farris.config.mjs');
|
|
8
|
+
if (!existsSync(resolved)) {
|
|
9
|
+
if (explicit) {
|
|
10
|
+
throw new Error(`配置文件不存在: ${resolved}`);
|
|
11
|
+
}
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const loaded = await import(pathToFileURL(resolved).href);
|
|
16
|
+
if (loaded.default === undefined) {
|
|
17
|
+
throw new Error('missing default export');
|
|
18
|
+
}
|
|
19
|
+
return loaded.default;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
const cause = err instanceof Error ? err.message : String(err);
|
|
23
|
+
throw new Error(`Failed to load farris config: ${resolved} — ${cause}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
26
|
//# sourceMappingURL=get-farris-config.js.map
|