@xfe-repo/mini-app 1.6.5 → 2.0.0-beta.2
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/README.md +64 -2
- package/babel.config.js +2 -12
- package/config/dev.ts +1 -25
- package/config/index.ts +52 -21
- package/config/prod.ts +1 -7
- package/deploy/.drone.yml +153 -160
- package/deploy/Dockerfile +4 -0
- package/deploy/helm/Chart.yaml +1 -1
- package/deploy/helm/templates/deployment.yaml +60 -22
- package/deploy/helm/templates/pvc.yaml +17 -0
- package/deploy/helm/templates/template.yaml +16 -0
- package/deploy/helm/templates/virtualService.yaml +13 -8
- package/deploy/helm/values.yaml +40 -7
- package/dist/chunk-4JD7C4FF.mjs +22 -164
- package/dist/chunk-MLSNG3O7.mjs +67 -336
- package/dist/chunk-MSNDQMQN.mjs +153 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/cli.js +504 -681
- package/dist/cli.mjs +55 -348
- package/dist/config.d.mts +6 -5
- package/dist/config.d.ts +6 -5
- package/dist/config.js +168 -298
- package/dist/config.mjs +11 -2
- package/dist/preview.js +87 -401
- package/dist/preview.mjs +11 -2
- package/dist/upload.js +83 -349
- package/dist/upload.mjs +7 -2
- package/dist/workspace-7FXUJJOQ.mjs +220 -0
- package/package.json +19 -18
- package/dist/chunk-75BJNL7E.mjs +0 -239
package/dist/cli.js
CHANGED
|
@@ -1,721 +1,544 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
|
|
32
|
+
// ../../shared/deploy/workspace.ts
|
|
33
|
+
var workspace_exports = {};
|
|
34
|
+
__export(workspace_exports, {
|
|
35
|
+
configWorkspace: () => configWorkspace,
|
|
36
|
+
printDeployment: () => printDeployment
|
|
37
|
+
});
|
|
38
|
+
function configWorkspace({ workspaceRoot, frameworkRoot }) {
|
|
39
|
+
const root = import_node_fs2.default.realpathSync(workspaceRoot);
|
|
40
|
+
const configuration = readJson(import_node_path3.default.join(root, "xfe.json"));
|
|
41
|
+
const applications = configuration.deploy?.applications;
|
|
42
|
+
const targets = configuration.deploy?.targets ?? Object.keys(applications ?? {});
|
|
43
|
+
if (!applications || typeof applications !== "object" || Array.isArray(applications)) {
|
|
44
|
+
throw new Error("\u6839 xfe.json.deploy.applications \u5FC5\u987B\u58F0\u660E\u5E94\u7528\u76EE\u5F55\u548C type");
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(targets) || targets.some((name) => !Object.hasOwn(applications, name))) {
|
|
47
|
+
throw new Error("deploy.targets \u5FC5\u987B\u662F\u5DF2\u58F0\u660E\u5E94\u7528\u540D\u7EC4\u6210\u7684\u6570\u7EC4");
|
|
48
|
+
}
|
|
49
|
+
const yaml = (0, import_node_module2.createRequire)(import_node_path3.default.join(frameworkRoot, "package.json"))("yaml");
|
|
50
|
+
const order = orderTargets({ applications, targets });
|
|
51
|
+
const output = [];
|
|
52
|
+
const steps = [];
|
|
53
|
+
const deploymentNames = /* @__PURE__ */ new Set();
|
|
54
|
+
let pipeline;
|
|
55
|
+
for (const name of order) {
|
|
56
|
+
if (!APPLICATION_NAME.test(name)) throw new Error(`\u5E94\u7528\u540D\u79F0\u65E0\u6548: ${name}`);
|
|
57
|
+
const application = applications[name];
|
|
58
|
+
const directory = resolveApplication(root, application);
|
|
59
|
+
const packageJson = readJson(import_node_path3.default.join(directory, "package.json"));
|
|
60
|
+
const project = readJson(import_node_path3.default.join(directory, "xfe.json"));
|
|
61
|
+
if (!project.deploy) throw new Error(`\u5E94\u7528 ${name} \u7F3A\u5C11 xfe.json.deploy`);
|
|
62
|
+
const deploymentName = project.project;
|
|
63
|
+
if (typeof deploymentName !== "string" || !APPLICATION_NAME.test(deploymentName) || deploymentNames.has(deploymentName)) {
|
|
64
|
+
throw new Error(`\u5E94\u7528 ${name} \u5FC5\u987B\u6709\u552F\u4E00\u7684 xfe.json.project \u5C0F\u5199\u53D1\u5E03\u540D\u79F0`);
|
|
55
65
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
deploymentNames.add(deploymentName);
|
|
67
|
+
const provider = application.type === "mini" /* Mini */ ? "@xfe-repo/mini-app" : "@xfe-repo/web-app";
|
|
68
|
+
const providerRoot = application.type === "node" /* Node */ ? resolveWebProvider({ root, applications }) : import_node_path3.default.dirname((0, import_node_module2.createRequire)(import_node_path3.default.join(directory, "package.json")).resolve(`${provider}/package.json`));
|
|
69
|
+
const raw = (0, import_node_child_process.execFileSync)(process.execPath, [import_node_path3.default.join(providerRoot, "bin/index.js"), "config", "--json"], {
|
|
70
|
+
cwd: directory,
|
|
71
|
+
encoding: "utf8",
|
|
72
|
+
maxBuffer: COMMAND_OUTPUT_LIMIT
|
|
62
73
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (i && _arr.length === i) break;
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
_d = true;
|
|
79
|
-
_e = err;
|
|
80
|
-
} finally{
|
|
81
|
-
try {
|
|
82
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
83
|
-
} finally{
|
|
84
|
-
if (_d) throw _e;
|
|
85
|
-
}
|
|
74
|
+
const documents = JSON.parse(raw);
|
|
75
|
+
const appPipeline = documents.find((document) => document.kind === "pipeline");
|
|
76
|
+
if (!appPipeline) throw new Error(`\u5E94\u7528 ${name} \u672A\u751F\u6210\u6D41\u6C34\u7EBF\uFF0C\u8BF7\u914D\u7F6E xfe.json.deploy`);
|
|
77
|
+
if (!pipeline) {
|
|
78
|
+
pipeline = { ...appPipeline, name: "deploy", steps };
|
|
79
|
+
steps.push(appPipeline.steps.find((step) => step.name === "install"));
|
|
80
|
+
steps.push({
|
|
81
|
+
name: "configure",
|
|
82
|
+
image: steps[0].image,
|
|
83
|
+
pull: "if-not-exists",
|
|
84
|
+
commands: ["pnpm deploy:config", "git diff --exit-code -- deploy/.drone.yml"]
|
|
85
|
+
});
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
97
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
98
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
ownKeys.forEach(function(key) {
|
|
102
|
-
_define_property(target, key, source[key]);
|
|
103
|
-
});
|
|
87
|
+
const relative = import_node_path3.default.relative(root, directory).split(import_node_path3.default.sep).join("/");
|
|
88
|
+
const secrets = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const document of documents.filter((document2) => document2.kind === "secret")) {
|
|
90
|
+
const secretName = document.name === "target-k8s-config" ? `${name}-${document.name}` : document.name;
|
|
91
|
+
const secret = { ...document, name: secretName };
|
|
92
|
+
const existing = output.find((item) => item.name === secretName);
|
|
93
|
+
if (existing && JSON.stringify(existing) !== JSON.stringify(secret)) throw new Error(`\u51ED\u636E\u58F0\u660E\u51B2\u7A81: ${secretName}`);
|
|
94
|
+
secrets.set(document.name, secretName);
|
|
95
|
+
if (!existing) output.push(secret);
|
|
104
96
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
for (const step of appPipeline.steps) {
|
|
98
|
+
if (["install", "configure"].includes(step.name)) continue;
|
|
99
|
+
const next = { ...step, name: `${name}-${step.name}` };
|
|
100
|
+
if (next.depends_on) next.depends_on = next.depends_on.map((dependency) => `${name}-${dependency}`);
|
|
101
|
+
if (next.environment) {
|
|
102
|
+
next.environment = Object.fromEntries(
|
|
103
|
+
Object.entries(next.environment).map(([key, value]) => [
|
|
104
|
+
key,
|
|
105
|
+
value?.from_secret && secrets.has(value.from_secret) ? { from_secret: secrets.get(value.from_secret) } : value
|
|
106
|
+
])
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (step.commands) {
|
|
110
|
+
let commands2 = step.commands.filter(
|
|
111
|
+
(command2) => !["pnpm exec xfe-web config", "git diff --exit-code -- deploy/.drone.yml", "cp -a node_modules deploy/modules"].includes(
|
|
112
|
+
command2
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
if (application.type === "node" /* Node */ && step.name === "build") commands2 = ["pnpm run build:ci"];
|
|
116
|
+
if (step.name === "build" && application.type !== "mini" /* Mini */) {
|
|
117
|
+
commands2.push(
|
|
118
|
+
...packageCommands({
|
|
119
|
+
name,
|
|
120
|
+
relative,
|
|
121
|
+
packageName: packageJson.name,
|
|
122
|
+
isWeb: application.type === "web" /* Web */
|
|
123
|
+
})
|
|
124
|
+
);
|
|
115
125
|
}
|
|
116
|
-
|
|
126
|
+
next.commands = [
|
|
127
|
+
`cd ${quote(relative)}`,
|
|
128
|
+
...commands2.map(
|
|
129
|
+
(command2) => command2.replaceAll("$DRONE_REPO_NAME", deploymentName).replaceAll("${DRONE_REPO}", deploymentName).replaceAll("$DRONE_REPO", deploymentName).replaceAll("$CI_COMMIT_SHA", "$DRONE_COMMIT_SHA")
|
|
130
|
+
)
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
if (step.name === "image-build") {
|
|
134
|
+
const context = application.type === "mini" /* Mini */ ? relative : `deploy/artifacts/${name}`;
|
|
135
|
+
next.settings = {
|
|
136
|
+
...step.settings,
|
|
137
|
+
repo_name: deploymentName,
|
|
138
|
+
tags: step.settings.tags.map((tag) => tag.replaceAll("${CI_COMMIT_SHA}", "${DRONE_COMMIT_SHA}")),
|
|
139
|
+
context,
|
|
140
|
+
dockerfile: application.type === "mini" /* Mini */ ? "deploy/Dockerfile" : "Dockerfile"
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
steps.push(next);
|
|
117
144
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function _object_spread_props(target, source) {
|
|
121
|
-
source = source != null ? source : {};
|
|
122
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
123
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
124
|
-
} else {
|
|
125
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
126
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
127
|
-
});
|
|
145
|
+
if (application.type === "node" /* Node */) {
|
|
146
|
+
import_node_fs2.default.copyFileSync(import_node_path3.default.join(directory, "migration-job.yaml"), import_node_path3.default.join(directory, "deploy/helm/templates/migration-job.yaml"));
|
|
128
147
|
}
|
|
129
|
-
|
|
148
|
+
}
|
|
149
|
+
if (!pipeline) throw new Error("deploy.targets \u81F3\u5C11\u9700\u8981\u9009\u62E9\u4E00\u4E2A\u5E94\u7528");
|
|
150
|
+
steps[0].commands = ["pnpm config set registry https://registry.npmmirror.com", "pnpm install --frozen-lockfile"];
|
|
151
|
+
const deployDirectory = import_node_path3.default.join(root, "deploy");
|
|
152
|
+
if (import_node_fs2.default.lstatSync(deployDirectory, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("\u6839 deploy \u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5");
|
|
153
|
+
import_node_fs2.default.mkdirSync(deployDirectory, { recursive: true });
|
|
154
|
+
import_node_fs2.default.writeFileSync(
|
|
155
|
+
import_node_path3.default.join(deployDirectory, ".drone.yml"),
|
|
156
|
+
[pipeline, ...output].map((document) => yaml.stringify(document, { defaultStringType: "QUOTE_SINGLE", defaultKeyType: "PLAIN", lineWidth: 0 })).join("---\n")
|
|
157
|
+
);
|
|
130
158
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
140
|
-
target[key] = source[key];
|
|
141
|
-
}
|
|
142
|
-
return target;
|
|
143
|
-
}
|
|
144
|
-
target = _object_without_properties_loose(source, excluded);
|
|
145
|
-
if (Object.getOwnPropertySymbols) {
|
|
146
|
-
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
147
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
148
|
-
key = sourceKeys[i];
|
|
149
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
150
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
151
|
-
target[key] = source[key];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return target;
|
|
159
|
+
function printDeployment(frameworkRoot) {
|
|
160
|
+
const yaml = (0, import_node_module2.createRequire)(import_node_path3.default.join(frameworkRoot, "package.json"))("yaml");
|
|
161
|
+
const source = import_node_fs2.default.readFileSync(import_node_path3.default.join(process.cwd(), "deploy/.drone.yml"), "utf8");
|
|
162
|
+
process.stdout.write(
|
|
163
|
+
JSON.stringify(
|
|
164
|
+
yaml.parseAllDocuments(source).map((document) => document.toJS()).filter(Boolean)
|
|
165
|
+
)
|
|
166
|
+
);
|
|
155
167
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
function orderTargets({ applications, targets }) {
|
|
169
|
+
const ordered = [];
|
|
170
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
171
|
+
const selected = new Set(targets);
|
|
172
|
+
const visit = (name) => {
|
|
173
|
+
if (ordered.includes(name)) return;
|
|
174
|
+
if (visiting.has(name)) throw new Error(`\u5E94\u7528\u53D1\u5E03\u987A\u5E8F\u5305\u542B\u5FAA\u73AF: ${name}`);
|
|
175
|
+
const dependencies = applications[name].dependsOn ?? [];
|
|
176
|
+
if (!Array.isArray(dependencies) || dependencies.some((dependency) => !Object.hasOwn(applications, dependency))) {
|
|
177
|
+
throw new Error(`\u5E94\u7528 ${name} \u7684 dependsOn \u5305\u542B\u672A\u77E5\u5E94\u7528`);
|
|
164
178
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return _set_prototype_of(o, p);
|
|
179
|
+
visiting.add(name);
|
|
180
|
+
dependencies.filter((dependency) => selected.has(dependency)).forEach(visit);
|
|
181
|
+
visiting.delete(name);
|
|
182
|
+
ordered.push(name);
|
|
183
|
+
};
|
|
184
|
+
targets.forEach(visit);
|
|
185
|
+
return ordered;
|
|
173
186
|
}
|
|
174
|
-
function
|
|
175
|
-
|
|
187
|
+
function resolveApplication(root, application) {
|
|
188
|
+
if (!application || typeof application.directory !== "string" || !Object.values(ApplicationType).includes(application.type)) {
|
|
189
|
+
throw new Error("\u5E94\u7528\u5FC5\u987B\u58F0\u660E directory\uFF0C\u4EE5\u53CA node\u3001web\u3001mini \u4E2D\u7684 type");
|
|
190
|
+
}
|
|
191
|
+
const directory = import_node_fs2.default.realpathSync(import_node_path3.default.resolve(root, application.directory));
|
|
192
|
+
const relative = import_node_path3.default.relative(root, directory);
|
|
193
|
+
if (!relative || relative.split(import_node_path3.default.sep)[0] === ".." || import_node_path3.default.isAbsolute(relative)) throw new Error("\u5E94\u7528\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u4ED3\u5E93\u5185");
|
|
194
|
+
return directory;
|
|
176
195
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
196
|
+
function resolveWebProvider({ root, applications }) {
|
|
197
|
+
const application = Object.values(applications).find((application2) => application2.type === "web" /* Web */);
|
|
198
|
+
if (!application) throw new Error("Node \u90E8\u7F72\u9700\u8981\u4ED3\u5E93\u5185\u7684 Web \u6784\u5EFA\u5DE5\u5177\u63D0\u4F9B\u901A\u7528 Helm \u6A21\u677F");
|
|
199
|
+
const directory = resolveApplication(root, application);
|
|
200
|
+
return import_node_path3.default.dirname((0, import_node_module2.createRequire)(import_node_path3.default.join(directory, "package.json")).resolve("@xfe-repo/web-app/package.json"));
|
|
180
201
|
}
|
|
181
|
-
function
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
202
|
+
function packageCommands({
|
|
203
|
+
name,
|
|
204
|
+
relative,
|
|
205
|
+
packageName,
|
|
206
|
+
isWeb
|
|
207
|
+
}) {
|
|
208
|
+
if (typeof packageName !== "string" || !packageName) throw new Error(`\u5E94\u7528 ${name} \u7F3A\u5C11 package.json.name`);
|
|
209
|
+
const root = import_node_path3.default.posix.relative(relative, ".") || ".";
|
|
210
|
+
const commands2 = [
|
|
211
|
+
`packageDirectory="$PWD/${root}/deploy/artifacts/${name}"`,
|
|
212
|
+
`pnpm --dir ${quote(root)} --filter ${quote(packageName)} deploy --legacy --prod "$packageDirectory"`
|
|
213
|
+
];
|
|
214
|
+
const selfReference = packageName.startsWith("@") ? "../../../.." : "../../..";
|
|
215
|
+
commands2.push(
|
|
216
|
+
`selfLink="$packageDirectory/node_modules/.pnpm/node_modules/${packageName}"`,
|
|
217
|
+
`if [ -L "$selfLink" ]; then ln -sfn ${quote(selfReference)} "$selfLink"; fi`
|
|
218
|
+
);
|
|
219
|
+
if (isWeb) {
|
|
220
|
+
commands2.push(
|
|
221
|
+
'mkdir -p "$packageDirectory/deploy"',
|
|
222
|
+
'mv "$packageDirectory/node_modules" "$packageDirectory/deploy/modules"',
|
|
223
|
+
`selfLink="$packageDirectory/deploy/modules/.pnpm/node_modules/${packageName}"`,
|
|
224
|
+
`if [ -L "$selfLink" ]; then ln -sfn ${quote(`../${selfReference}`)} "$selfLink"; fi`,
|
|
225
|
+
'cp -a deploy/static "$packageDirectory/deploy/static"',
|
|
226
|
+
'cp deploy/Dockerfile "$packageDirectory/Dockerfile"'
|
|
227
|
+
);
|
|
228
|
+
return commands2;
|
|
229
|
+
}
|
|
230
|
+
commands2.push('cp Dockerfile "$packageDirectory/Dockerfile"');
|
|
231
|
+
return commands2;
|
|
188
232
|
}
|
|
189
|
-
function
|
|
190
|
-
|
|
191
|
-
return new WrappedRegExp(re, undefined, groups);
|
|
192
|
-
};
|
|
193
|
-
var _super = RegExp.prototype;
|
|
194
|
-
var _groups = new WeakMap();
|
|
195
|
-
function WrappedRegExp(re, flags, groups) {
|
|
196
|
-
var _re = new RegExp(re, flags);
|
|
197
|
-
_groups.set(_re, groups || _groups.get(re));
|
|
198
|
-
return _set_prototype_of(_re, WrappedRegExp.prototype);
|
|
199
|
-
}
|
|
200
|
-
_inherits(WrappedRegExp, RegExp);
|
|
201
|
-
WrappedRegExp.prototype.exec = function(str) {
|
|
202
|
-
var result = _super.exec.call(this, str);
|
|
203
|
-
if (result) {
|
|
204
|
-
result.groups = buildGroups(result, this);
|
|
205
|
-
var indices = result.indices;
|
|
206
|
-
if (indices) indices.groups = buildGroups(indices, this);
|
|
207
|
-
}
|
|
208
|
-
return result;
|
|
209
|
-
};
|
|
210
|
-
WrappedRegExp.prototype[Symbol.replace] = function(str, substitution) {
|
|
211
|
-
if (typeof substitution === "string") {
|
|
212
|
-
var groups = _groups.get(this);
|
|
213
|
-
return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function(_, name) {
|
|
214
|
-
var group = groups ? groups[name] : undefined;
|
|
215
|
-
if (group === undefined) return "";
|
|
216
|
-
return "$" + (Array.isArray(group) ? group.join("$") : group);
|
|
217
|
-
}));
|
|
218
|
-
}
|
|
219
|
-
if (typeof substitution === "function") {
|
|
220
|
-
var _this = this;
|
|
221
|
-
return _super[Symbol.replace].call(this, str, function() {
|
|
222
|
-
var args = arguments;
|
|
223
|
-
if (typeof args[args.length - 1] !== "object") {
|
|
224
|
-
args = [].slice.call(args);
|
|
225
|
-
args.push(buildGroups(args, _this));
|
|
226
|
-
}
|
|
227
|
-
return substitution.apply(this, args);
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return _super[Symbol.replace].call(this, str, substitution);
|
|
231
|
-
};
|
|
232
|
-
function buildGroups(result, re) {
|
|
233
|
-
var g = _groups.get(re);
|
|
234
|
-
return Object.keys(g).reduce(function(groups, name) {
|
|
235
|
-
var i = g[name];
|
|
236
|
-
if (typeof i === "number") groups[name] = result[i];
|
|
237
|
-
else {
|
|
238
|
-
var k = 0;
|
|
239
|
-
while(result[i[k]] === undefined && k + 1 < i.length)k++;
|
|
240
|
-
groups[name] = result[i[k]];
|
|
241
|
-
}
|
|
242
|
-
return groups;
|
|
243
|
-
}, Object.create(null));
|
|
244
|
-
}
|
|
245
|
-
return _wrap_reg_exp.apply(this, arguments);
|
|
233
|
+
function readJson(file) {
|
|
234
|
+
return JSON.parse(import_node_fs2.default.readFileSync(file, "utf8"));
|
|
246
235
|
}
|
|
247
|
-
function
|
|
248
|
-
|
|
249
|
-
label: 0,
|
|
250
|
-
sent: function() {
|
|
251
|
-
if (t[0] & 1) throw t[1];
|
|
252
|
-
return t[1];
|
|
253
|
-
},
|
|
254
|
-
trys: [],
|
|
255
|
-
ops: []
|
|
256
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
257
|
-
return d(g, "next", {
|
|
258
|
-
value: verb(0)
|
|
259
|
-
}), d(g, "throw", {
|
|
260
|
-
value: verb(1)
|
|
261
|
-
}), d(g, "return", {
|
|
262
|
-
value: verb(2)
|
|
263
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
264
|
-
value: function() {
|
|
265
|
-
return this;
|
|
266
|
-
}
|
|
267
|
-
}), g;
|
|
268
|
-
function verb(n) {
|
|
269
|
-
return function(v) {
|
|
270
|
-
return step([
|
|
271
|
-
n,
|
|
272
|
-
v
|
|
273
|
-
]);
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function step(op) {
|
|
277
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
278
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
279
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
280
|
-
if (y = 0, t) op = [
|
|
281
|
-
op[0] & 2,
|
|
282
|
-
t.value
|
|
283
|
-
];
|
|
284
|
-
switch(op[0]){
|
|
285
|
-
case 0:
|
|
286
|
-
case 1:
|
|
287
|
-
t = op;
|
|
288
|
-
break;
|
|
289
|
-
case 4:
|
|
290
|
-
_.label++;
|
|
291
|
-
return {
|
|
292
|
-
value: op[1],
|
|
293
|
-
done: false
|
|
294
|
-
};
|
|
295
|
-
case 5:
|
|
296
|
-
_.label++;
|
|
297
|
-
y = op[1];
|
|
298
|
-
op = [
|
|
299
|
-
0
|
|
300
|
-
];
|
|
301
|
-
continue;
|
|
302
|
-
case 7:
|
|
303
|
-
op = _.ops.pop();
|
|
304
|
-
_.trys.pop();
|
|
305
|
-
continue;
|
|
306
|
-
default:
|
|
307
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
308
|
-
_ = 0;
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
312
|
-
_.label = op[1];
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
316
|
-
_.label = t[1];
|
|
317
|
-
t = op;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
if (t && _.label < t[2]) {
|
|
321
|
-
_.label = t[2];
|
|
322
|
-
_.ops.push(op);
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
if (t[2]) _.ops.pop();
|
|
326
|
-
_.trys.pop();
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
op = body.call(thisArg, _);
|
|
330
|
-
} catch (e) {
|
|
331
|
-
op = [
|
|
332
|
-
6,
|
|
333
|
-
e
|
|
334
|
-
];
|
|
335
|
-
y = 0;
|
|
336
|
-
} finally{
|
|
337
|
-
f = t = 0;
|
|
338
|
-
}
|
|
339
|
-
if (op[0] & 5) throw op[1];
|
|
340
|
-
return {
|
|
341
|
-
value: op[0] ? op[1] : void 0,
|
|
342
|
-
done: true
|
|
343
|
-
};
|
|
344
|
-
}
|
|
236
|
+
function quote(value) {
|
|
237
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
345
238
|
}
|
|
346
|
-
var
|
|
347
|
-
var
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
366
|
-
} catch (err) {
|
|
367
|
-
_didIteratorError = true;
|
|
368
|
-
_iteratorError = err;
|
|
369
|
-
} finally{
|
|
370
|
-
try {
|
|
371
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
372
|
-
_iterator.return();
|
|
373
|
-
}
|
|
374
|
-
} finally{
|
|
375
|
-
if (_didIteratorError) {
|
|
376
|
-
throw _iteratorError;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
return to;
|
|
382
|
-
};
|
|
383
|
-
var __toESM = function __toESM(mod, isNodeMode, target) {
|
|
384
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
385
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
386
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
387
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
388
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
389
|
-
value: mod,
|
|
390
|
-
enumerable: true
|
|
391
|
-
}) : target, mod);
|
|
392
|
-
};
|
|
239
|
+
var import_node_fs2, import_node_path3, import_node_child_process, import_node_module2, ApplicationType, COMMAND_OUTPUT_LIMIT, APPLICATION_NAME;
|
|
240
|
+
var init_workspace = __esm({
|
|
241
|
+
"../../shared/deploy/workspace.ts"() {
|
|
242
|
+
"use strict";
|
|
243
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
244
|
+
import_node_path3 = __toESM(require("path"));
|
|
245
|
+
import_node_child_process = require("child_process");
|
|
246
|
+
import_node_module2 = require("module");
|
|
247
|
+
ApplicationType = /* @__PURE__ */ ((ApplicationType2) => {
|
|
248
|
+
ApplicationType2["Node"] = "node";
|
|
249
|
+
ApplicationType2["Web"] = "web";
|
|
250
|
+
ApplicationType2["Mini"] = "mini";
|
|
251
|
+
return ApplicationType2;
|
|
252
|
+
})(ApplicationType || {});
|
|
253
|
+
COMMAND_OUTPUT_LIMIT = 8 * 1024 * 1024;
|
|
254
|
+
APPLICATION_NAME = /^[a-z][a-z0-9-]*$/;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
393
258
|
// src/cli.ts
|
|
394
259
|
var import_minimist = __toESM(require("minimist"));
|
|
395
|
-
var
|
|
396
|
-
var
|
|
260
|
+
var import_path2 = __toESM(require("path"));
|
|
261
|
+
var import_node_child_process2 = require("child_process");
|
|
262
|
+
|
|
397
263
|
// src/config.ts
|
|
398
|
-
var import_path = __toESM(require("path"));
|
|
399
264
|
var import_fs = __toESM(require("fs"));
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
265
|
+
|
|
266
|
+
// src/config/deploy.ts
|
|
267
|
+
var import_node_path2 = __toESM(require("path"));
|
|
268
|
+
var import_node_url = require("url");
|
|
269
|
+
|
|
270
|
+
// ../../shared/deploy/config.ts
|
|
271
|
+
var import_node_fs = __toESM(require("fs"));
|
|
272
|
+
var import_node_path = __toESM(require("path"));
|
|
273
|
+
var import_node_module = require("module");
|
|
274
|
+
var DeployEnvironment = /* @__PURE__ */ ((DeployEnvironment2) => {
|
|
275
|
+
DeployEnvironment2["Test"] = "test";
|
|
276
|
+
DeployEnvironment2["Stage"] = "stage";
|
|
277
|
+
DeployEnvironment2["Prod"] = "prod";
|
|
278
|
+
DeployEnvironment2["Stable"] = "stable";
|
|
279
|
+
return DeployEnvironment2;
|
|
280
|
+
})(DeployEnvironment || {});
|
|
281
|
+
var generateDeploy = ({
|
|
282
|
+
deploy,
|
|
283
|
+
frameworkRoot,
|
|
284
|
+
isMini = false
|
|
285
|
+
}) => {
|
|
286
|
+
const yaml = (0, import_node_module.createRequire)(import_node_path.default.join(frameworkRoot, "package.json"))("yaml");
|
|
287
|
+
const supportedFields = ["values", "environments", "pushHelmChart", ...isMini ? ["platforms"] : []];
|
|
288
|
+
if (deploy === void 0) return;
|
|
289
|
+
if (!deploy || typeof deploy !== "object" || Array.isArray(deploy) || Object.keys(deploy).some(
|
|
290
|
+
/** 运行参数只能来自 values,流水线开关保留独立入口。 */
|
|
291
|
+
(key) => !supportedFields.includes(key)
|
|
292
|
+
)) {
|
|
293
|
+
throw new Error(`xfe.json.deploy \u4EC5\u652F\u6301 ${supportedFields.join("\u3001")}\uFF1B\u8FD0\u884C\u53C2\u6570\u8BF7\u653E\u5165 values`);
|
|
294
|
+
}
|
|
295
|
+
const environments = deploy.environments === void 0 ? Object.values(DeployEnvironment) : deploy.environments;
|
|
296
|
+
if (!Array.isArray(environments) || environments.some(
|
|
297
|
+
/** 只接受已知的环境名称,非法值不能误开启发布。 */
|
|
298
|
+
(environment) => !Object.values(DeployEnvironment).includes(environment)
|
|
299
|
+
))
|
|
300
|
+
throw new Error("deploy.environments \u5FC5\u987B\u662F test\u3001stage\u3001prod\u3001stable \u7EC4\u6210\u7684\u6570\u7EC4\uFF1B\u7A7A\u6570\u7EC4\u5173\u95ED\u5168\u90E8\u90E8\u7F72");
|
|
301
|
+
if (deploy.pushHelmChart !== void 0 && typeof deploy.pushHelmChart !== "boolean") throw new Error("deploy.pushHelmChart \u5FC5\u987B\u662F\u5E03\u5C14\u503C");
|
|
302
|
+
const platforms = deploy.platforms === void 0 ? ["weapp", "h5"] : deploy.platforms;
|
|
303
|
+
if (!Array.isArray(platforms) || platforms.some((platform) => !["weapp", "h5"].includes(platform))) {
|
|
304
|
+
throw new Error("deploy.platforms \u5FC5\u987B\u662F weapp\u3001h5 \u7EC4\u6210\u7684\u6570\u7EC4\uFF1B\u7A7A\u6570\u7EC4\u5173\u95ED\u5168\u90E8\u53D1\u5E03");
|
|
305
|
+
}
|
|
306
|
+
const h5Environments = platforms.includes("h5") ? environments : [];
|
|
307
|
+
const miniEnvironments = platforms.includes("weapp") ? environments : [];
|
|
308
|
+
const pushHelmChart = deploy.pushHelmChart !== false && h5Environments.includes("prod" /* Prod */);
|
|
309
|
+
const source = import_node_path.default.join(frameworkRoot, "deploy");
|
|
310
|
+
const target = import_node_path.default.join(process.cwd(), "deploy");
|
|
311
|
+
let overrides = deploy.values === void 0 ? {} : deploy.values;
|
|
312
|
+
if (typeof overrides === "string") {
|
|
313
|
+
const valuesPath = import_node_fs.default.realpathSync(import_node_path.default.resolve(overrides));
|
|
314
|
+
if (valuesPath.startsWith(target + import_node_path.default.sep) && valuesPath !== import_node_path.default.join(target, "values.yaml")) {
|
|
315
|
+
throw new Error("\u9879\u76EE values \u6587\u4EF6\u4E0D\u80FD\u653E\u5728\u751F\u6210\u5B50\u76EE\u5F55\u4E2D\uFF0C\u8BF7\u4F7F\u7528 deploy/values.yaml \u6216\u9879\u76EE\u6839\u76EE\u5F55\u7684 values.yaml");
|
|
405
316
|
}
|
|
406
|
-
|
|
407
|
-
|
|
317
|
+
overrides = yaml.parse(import_node_fs.default.readFileSync(valuesPath, "utf8"));
|
|
318
|
+
}
|
|
319
|
+
if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) {
|
|
320
|
+
throw new Error("deploy.values \u5FC5\u987B\u662F\u5BF9\u8C61\u6216\u6307\u5411 YAML \u5BF9\u8C61\u6587\u4EF6\u7684\u8DEF\u5F84");
|
|
321
|
+
}
|
|
322
|
+
if (Object.hasOwn(overrides, "environments") || Object.hasOwn(overrides, "pushHelmChart"))
|
|
323
|
+
throw new Error("values \u4E0D\u518D\u652F\u6301 environments \u6216 pushHelmChart\uFF1B\u8BF7\u8FC1\u5165 xfe.json.deploy\uFF0C\u73AF\u5883\u5F00\u5173\u4F7F\u7528\u6570\u7EC4");
|
|
324
|
+
const defaults = yaml.parse(import_node_fs.default.readFileSync(import_node_path.default.join(source, "helm/values.yaml"), "utf8"));
|
|
325
|
+
const values = mergeDeployValues(defaults, overrides);
|
|
326
|
+
if (typeof values.host !== "string" || /[\\/?#@:\s]/.test(values.host)) {
|
|
327
|
+
throw new Error("values.host \u5FC5\u987B\u662F\u4E0D\u542B\u534F\u8BAE\u3001\u7AEF\u53E3\u548C\u8DEF\u5F84\u7684\u4E3B\u673A\u540D\uFF0C\u4F8B\u5982 specdoc.example.com");
|
|
328
|
+
}
|
|
329
|
+
if (!["saas", "infra"].includes(values.targetK8s)) throw new Error("deploy.values.targetK8s \u53EA\u80FD\u4E3A saas \u6216 infra");
|
|
330
|
+
if (target === source) throw new Error("\u90E8\u7F72\u8F93\u51FA\u4E0D\u80FD\u8986\u76D6\u6846\u67B6\u6A21\u677F\u76EE\u5F55");
|
|
331
|
+
if (import_node_fs.default.lstatSync(target, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("deploy \u4E0D\u80FD\u4E3A\u7B26\u53F7\u94FE\u63A5\uFF0C\u4EE5\u514D\u8986\u76D6\u5916\u90E8\u76EE\u5F55");
|
|
332
|
+
const disabledEvents = "[custom, tag]";
|
|
333
|
+
const drone = import_node_fs.default.readFileSync(import_node_path.default.join(source, ".drone.yml"), "utf8").replaceAll("<<TARGET_K8S>>", values.targetK8s).replaceAll("<<EXCLUDE_EVENTS_deploy>>", h5Environments.length ? "[]" : disabledEvents).replaceAll("<<EXCLUDE_EVENTS_h5>>", h5Environments.length ? "[]" : disabledEvents).replaceAll(
|
|
334
|
+
"<<EXCLUDE_EVENTS_weapp>>",
|
|
335
|
+
miniEnvironments.some((environment) => environment !== "stable" /* Stable */) ? "[]" : disabledEvents
|
|
336
|
+
).replace(
|
|
337
|
+
/<<EXCLUDE_EVENTS_weapp_(test|stage|prod)>>/g,
|
|
338
|
+
(_placeholder, environment) => miniEnvironments.includes(environment) ? "[]" : disabledEvents
|
|
339
|
+
).replaceAll("<<EXCLUDE_EVENTS_push_helm_chart>>", pushHelmChart ? "[]" : disabledEvents).replace(
|
|
340
|
+
/<<EXCLUDE_EVENTS_(test|stage|prod|stable)>>/g,
|
|
341
|
+
/** 开启时不排除事件,关闭时由 Drone 原生 when 跳过该步骤。 */
|
|
342
|
+
(_placeholder, environment) => h5Environments.includes(environment) ? "[]" : disabledEvents
|
|
343
|
+
);
|
|
344
|
+
import_node_fs.default.cpSync(source, target, { recursive: true });
|
|
345
|
+
import_node_fs.default.writeFileSync(
|
|
346
|
+
import_node_path.default.join(target, "helm/values.yaml"),
|
|
347
|
+
yaml.stringify(values, {
|
|
348
|
+
defaultStringType: "QUOTE_SINGLE",
|
|
349
|
+
defaultKeyType: "PLAIN"
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(target, ".drone.yml"), drone);
|
|
408
353
|
};
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
valuesYaml.virtualService.hosts.test = hostsTest;
|
|
432
|
-
valuesYaml.targetK8s = targetK8s;
|
|
433
|
-
valuesYaml.namespace = targetNamespace;
|
|
434
|
-
var valuesYamlStr = import_yaml.default.stringify(valuesYaml, {
|
|
435
|
-
defaultStringType: "QUOTE_SINGLE",
|
|
436
|
-
defaultKeyType: "PLAIN"
|
|
437
|
-
});
|
|
438
|
-
import_fs.default.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
|
|
354
|
+
function mergeDeployValues(base, overrides) {
|
|
355
|
+
return Object.fromEntries(
|
|
356
|
+
Object.entries({ ...base, ...overrides }).map(
|
|
357
|
+
/** 仅合并普通对象,列表保持声明的顺序。 */
|
|
358
|
+
([key, value]) => {
|
|
359
|
+
const previous = base[key];
|
|
360
|
+
const previousObject = previous && typeof previous === "object" && !Array.isArray(previous);
|
|
361
|
+
if (value === true && previousObject) {
|
|
362
|
+
return [key, Object.hasOwn(previous, "enabled") ? { ...previous, enabled: true } : previous];
|
|
363
|
+
}
|
|
364
|
+
const mergeable = value && previousObject && typeof value === "object" && !Array.isArray(value);
|
|
365
|
+
return [key, mergeable ? mergeDeployValues(previous, value) : value];
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/config/deploy.ts
|
|
372
|
+
var import_meta = {};
|
|
373
|
+
var generateDeploy2 = (deploy) => {
|
|
374
|
+
const directory = typeof __dirname === "string" ? __dirname : import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
375
|
+
generateDeploy({ deploy, frameworkRoot: import_node_path2.default.resolve(directory, ".."), isMini: true });
|
|
439
376
|
};
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
if (!aud) throw new Error("xfe.json \u4E2D\u7684 jwt \u914D\u7F6E\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u786E\u4FDD\u5305\u542B aud \u5B57\u6BB5\u3002");
|
|
450
|
-
return [
|
|
451
|
-
4,
|
|
452
|
-
fetch("https://app.eshetang.com/jwk?appId=".concat(aud))
|
|
453
|
-
];
|
|
454
|
-
case 1:
|
|
455
|
-
jwkRes = _state.sent();
|
|
456
|
-
if (!jwkRes.ok) {
|
|
457
|
-
throw new Error("远程获取密钥失败: ".concat(jwkRes.status, " ").concat(jwkRes.statusText));
|
|
458
|
-
}
|
|
459
|
-
_state.label = 2;
|
|
460
|
-
case 2:
|
|
461
|
-
_state.trys.push([
|
|
462
|
-
2,
|
|
463
|
-
4,
|
|
464
|
-
,
|
|
465
|
-
6
|
|
466
|
-
]);
|
|
467
|
-
return [
|
|
468
|
-
4,
|
|
469
|
-
jwkRes.json()
|
|
470
|
-
];
|
|
471
|
-
case 3:
|
|
472
|
-
JwkResponseJson = _state.sent();
|
|
473
|
-
return [
|
|
474
|
-
3,
|
|
475
|
-
6
|
|
476
|
-
];
|
|
477
|
-
case 4:
|
|
478
|
-
err = _state.sent();
|
|
479
|
-
_ = Error.bind;
|
|
480
|
-
_2 = (_1 = "远程获取密钥失败,响应解析错误: ".concat(err.message, ", response text: ")).concat;
|
|
481
|
-
return [
|
|
482
|
-
4,
|
|
483
|
-
jwkRes.text()
|
|
484
|
-
];
|
|
485
|
-
case 5:
|
|
486
|
-
throw new (_.apply(Error, [
|
|
487
|
-
void 0,
|
|
488
|
-
_2.apply(_1, [
|
|
489
|
-
_state.sent()
|
|
490
|
-
])
|
|
491
|
-
]));
|
|
492
|
-
case 6:
|
|
493
|
-
_ref = (JwkResponseJson === null || JwkResponseJson === void 0 ? void 0 : JwkResponseJson.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
|
|
494
|
-
if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
|
|
495
|
-
return [
|
|
496
|
-
2,
|
|
497
|
-
{
|
|
498
|
-
XFE_JWT_AUD: aud,
|
|
499
|
-
XFE_JWT_KEY_ID: keyId,
|
|
500
|
-
XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
|
|
501
|
-
}
|
|
502
|
-
];
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
})();
|
|
377
|
+
|
|
378
|
+
// src/config.ts
|
|
379
|
+
var loadXfeConfig = () => {
|
|
380
|
+
const xfeConfigPath = "./xfe.json";
|
|
381
|
+
if (!import_fs.default.existsSync(xfeConfigPath)) {
|
|
382
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
383
|
+
}
|
|
384
|
+
const xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
|
|
385
|
+
return JSON.parse(xfeConfigContent);
|
|
506
386
|
};
|
|
387
|
+
var configDeploy = () => generateDeploy2(loadXfeConfig().deploy);
|
|
388
|
+
var getJwtEnv = async () => {
|
|
389
|
+
const xfeConfig = loadXfeConfig();
|
|
390
|
+
if (!xfeConfig?.jwt) return {};
|
|
391
|
+
const { aud = "" } = xfeConfig.jwt;
|
|
392
|
+
if (!aud) throw new Error("xfe.json \u4E2D\u7684 jwt \u914D\u7F6E\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u786E\u4FDD\u5305\u542B aud \u5B57\u6BB5\u3002");
|
|
393
|
+
const jwkRes = await fetch(`https://app.eshetang.com/jwk?appId=${aud}`);
|
|
394
|
+
if (!jwkRes.ok) {
|
|
395
|
+
throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25: ${jwkRes.status} ${jwkRes.statusText}`);
|
|
396
|
+
}
|
|
397
|
+
let JwkResponseJson;
|
|
398
|
+
try {
|
|
399
|
+
JwkResponseJson = await jwkRes.json();
|
|
400
|
+
} catch (err) {
|
|
401
|
+
throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25\uFF0C\u54CD\u5E94\u89E3\u6790\u9519\u8BEF: ${err.message}, response text: ${await jwkRes.text()}`);
|
|
402
|
+
}
|
|
403
|
+
const { keyId, privateKeyPkcs8 } = JwkResponseJson?.data || {};
|
|
404
|
+
if (!keyId || !privateKeyPkcs8) throw new Error(`\u672A\u83B7\u53D6\u5230\u9879\u76EE\u7B7E\u540D\u5BC6\u94A5, \u8BF7\u68C0\u67E5aud\u662F\u5426\u6B63\u786E: ${aud}`);
|
|
405
|
+
return {
|
|
406
|
+
XFE_JWT_AUD: aud,
|
|
407
|
+
XFE_JWT_KEY_ID: keyId,
|
|
408
|
+
XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
|
|
507
412
|
// src/upload.ts
|
|
508
413
|
var import_miniprogram_ci2 = require("miniprogram-ci");
|
|
414
|
+
|
|
509
415
|
// src/preview.ts
|
|
510
416
|
var import_fs2 = __toESM(require("fs"));
|
|
511
|
-
var
|
|
417
|
+
var import_path = __toESM(require("path"));
|
|
512
418
|
var import_miniprogram_ci = require("miniprogram-ci");
|
|
513
|
-
var getProject =
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
]
|
|
537
|
-
});
|
|
419
|
+
var getProject = () => {
|
|
420
|
+
let rwaPrivateKey = "", rawProjectConfig = "";
|
|
421
|
+
const projectRoot = process.cwd();
|
|
422
|
+
try {
|
|
423
|
+
rwaPrivateKey = import_fs2.default.readFileSync(import_path.default.join(projectRoot, "private.key")).toString();
|
|
424
|
+
} catch {
|
|
425
|
+
console.error("Error: \u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA private.key \u6587\u4EF6\uFF0C\u5185\u5BB9\u4E3A\u5C0F\u7A0B\u5E8F\u7684\u79C1\u94A5");
|
|
426
|
+
process.exit(1);
|
|
427
|
+
}
|
|
428
|
+
try {
|
|
429
|
+
rawProjectConfig = import_fs2.default.readFileSync(import_path.default.join(projectRoot, "project.config.json")).toString();
|
|
430
|
+
} catch {
|
|
431
|
+
console.error("Error: \u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA project.config.json \u6587\u4EF6\uFF0C\u5185\u5BB9\u4E3A\u5C0F\u7A0B\u5E8F\u7684\u914D\u7F6E");
|
|
432
|
+
process.exit(1);
|
|
433
|
+
}
|
|
434
|
+
const projectConfig = JSON.parse(rawProjectConfig);
|
|
435
|
+
return new import_miniprogram_ci.Project({
|
|
436
|
+
appid: projectConfig.appid,
|
|
437
|
+
projectPath: projectConfig.miniprogramRoot,
|
|
438
|
+
privateKey: rwaPrivateKey,
|
|
439
|
+
type: "miniProgram",
|
|
440
|
+
ignores: ["node_modules/**/*"]
|
|
441
|
+
});
|
|
538
442
|
};
|
|
539
|
-
function previewMini(version) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
qrcodeFormat: "terminal",
|
|
555
|
-
qrcodeOutputDest: "deploy/preview.qrcode.jpg",
|
|
556
|
-
pagePath: pagePath,
|
|
557
|
-
searchQuery: searchQuery,
|
|
558
|
-
desc: desc,
|
|
559
|
-
robot: robot,
|
|
560
|
-
scene: scene
|
|
561
|
-
})
|
|
562
|
-
];
|
|
563
|
-
case 1:
|
|
564
|
-
_state.sent();
|
|
565
|
-
return [
|
|
566
|
-
2
|
|
567
|
-
];
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
})();
|
|
443
|
+
async function previewMini(version, pageUrl = "", desc = "", scene = 1011, progress = false) {
|
|
444
|
+
const [pagePath, searchQuery] = pageUrl.split("?");
|
|
445
|
+
const project = getProject();
|
|
446
|
+
const robot = choiceRobot();
|
|
447
|
+
await (0, import_miniprogram_ci.preview)({
|
|
448
|
+
project,
|
|
449
|
+
version,
|
|
450
|
+
qrcodeFormat: "terminal",
|
|
451
|
+
qrcodeOutputDest: "deploy/preview.qrcode.jpg",
|
|
452
|
+
pagePath,
|
|
453
|
+
searchQuery,
|
|
454
|
+
desc,
|
|
455
|
+
robot,
|
|
456
|
+
scene
|
|
457
|
+
});
|
|
571
458
|
}
|
|
572
|
-
var choiceRobot =
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
console.log("将使用CI".concat(robot, "机器人"));
|
|
597
|
-
return robot;
|
|
459
|
+
var choiceRobot = () => {
|
|
460
|
+
const { API_ENV = "" } = process.env;
|
|
461
|
+
const { groups } = API_ENV.match(/^(?<env>prod|beta|stage|test)(?<sn>.*)/) || {};
|
|
462
|
+
const env2 = groups?.env || "other";
|
|
463
|
+
const sn = Number(groups?.sn) || 0;
|
|
464
|
+
let robot;
|
|
465
|
+
switch (env2) {
|
|
466
|
+
case "prod":
|
|
467
|
+
case "beta":
|
|
468
|
+
robot = 1;
|
|
469
|
+
break;
|
|
470
|
+
case "stage":
|
|
471
|
+
robot = 2;
|
|
472
|
+
break;
|
|
473
|
+
case "test":
|
|
474
|
+
robot = sn % 29 >= 3 ? sn % 29 : 3;
|
|
475
|
+
break;
|
|
476
|
+
case "other":
|
|
477
|
+
robot = 30;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
console.log(`\u5C06\u4F7F\u7528CI${robot}\u673A\u5668\u4EBA`);
|
|
481
|
+
return robot;
|
|
598
482
|
};
|
|
483
|
+
|
|
599
484
|
// src/upload.ts
|
|
600
|
-
function uploadMini(version) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
return [
|
|
614
|
-
4,
|
|
615
|
-
(0, import_miniprogram_ci2.upload)({
|
|
616
|
-
project: project,
|
|
617
|
-
version: version,
|
|
618
|
-
robot: robot,
|
|
619
|
-
desc: desc,
|
|
620
|
-
onProgressUpdate: onProgressUpdate,
|
|
621
|
-
setting: {
|
|
622
|
-
es6: true
|
|
623
|
-
}
|
|
624
|
-
})
|
|
625
|
-
];
|
|
626
|
-
case 1:
|
|
627
|
-
_state.sent();
|
|
628
|
-
return [
|
|
629
|
-
2
|
|
630
|
-
];
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
})();
|
|
485
|
+
async function uploadMini(version, desc = "", progress = false) {
|
|
486
|
+
if (!version) throw new Error("\u8BF7\u4F20\u9012\u7248\u672C\u53F7\uFF01 -v \u6216\u8005 --version");
|
|
487
|
+
const project = getProject();
|
|
488
|
+
const robot = choiceRobot();
|
|
489
|
+
const onProgressUpdate = progress ? console.log : () => null;
|
|
490
|
+
await (0, import_miniprogram_ci2.upload)({
|
|
491
|
+
project,
|
|
492
|
+
version,
|
|
493
|
+
robot,
|
|
494
|
+
desc,
|
|
495
|
+
onProgressUpdate,
|
|
496
|
+
setting: { es6: true }
|
|
497
|
+
});
|
|
634
498
|
}
|
|
499
|
+
|
|
635
500
|
// src/cli.ts
|
|
636
501
|
var argv = (0, import_minimist.default)(process.argv.slice(2));
|
|
637
|
-
var
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
var _commands = _sliced_to_array(commands, 1), command = _commands[0];
|
|
641
|
-
var appPackageRoot = import_path3.default.resolve(__dirname, "../");
|
|
502
|
+
var { _: commands, ...args } = argv;
|
|
503
|
+
var [command] = commands;
|
|
504
|
+
var appPackageRoot = import_path2.default.resolve(__dirname, "../");
|
|
642
505
|
var appProjectRoot = process.cwd();
|
|
643
|
-
var env =
|
|
644
|
-
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
3,
|
|
678
|
-
4
|
|
679
|
-
];
|
|
680
|
-
return [
|
|
681
|
-
4,
|
|
682
|
-
getJwtEnv()
|
|
683
|
-
];
|
|
684
|
-
case 3:
|
|
685
|
-
jwtEnv1 = _state.sent();
|
|
686
|
-
(0, import_child_process.execSync)("taro build ".concat(argsString), {
|
|
687
|
-
stdio: "inherit",
|
|
688
|
-
cwd: appPackageRoot,
|
|
689
|
-
env: _object_spread({}, env, jwtEnv1)
|
|
690
|
-
});
|
|
691
|
-
return [
|
|
692
|
-
3,
|
|
693
|
-
5
|
|
694
|
-
];
|
|
695
|
-
case 4:
|
|
696
|
-
if (command === "config") {
|
|
697
|
-
configDeploy();
|
|
698
|
-
} else if (command === "upload") {
|
|
699
|
-
v = argv.v, version = argv.version, d = argv.d, desc = argv.desc, P = argv.P, progress = argv.progress;
|
|
700
|
-
void uploadMini(v || version, d || desc, P || progress).catch(console.error).finally(function() {
|
|
701
|
-
return process.exit(0);
|
|
702
|
-
});
|
|
703
|
-
} else if (command === "preview") {
|
|
704
|
-
v1 = argv.v, version1 = argv.version, p = argv.p, previewPath = argv.path, d1 = argv.d, desc1 = argv.desc, s = argv.s, scene = argv.scene, P1 = argv.P, progress1 = argv.progress;
|
|
705
|
-
void previewMini(v1 || version1, p || previewPath, d1 || desc1, s || scene, P1 || progress1).finally(function() {
|
|
706
|
-
return process.exit(0);
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
_state.label = 5;
|
|
710
|
-
case 5:
|
|
711
|
-
return [
|
|
712
|
-
2
|
|
713
|
-
];
|
|
714
|
-
}
|
|
715
|
-
});
|
|
716
|
-
})();
|
|
506
|
+
var env = { ...process.env, APP_PROJECT_ROOT: appProjectRoot };
|
|
507
|
+
var taroBin = require.resolve("@tarojs/cli/bin/taro");
|
|
508
|
+
var taroArgs = Object.entries(args).map(([key, value]) => `--${key}=${value}`);
|
|
509
|
+
async function main() {
|
|
510
|
+
if (command === "dev") {
|
|
511
|
+
const jwtEnv = await getJwtEnv();
|
|
512
|
+
(0, import_node_child_process2.execFileSync)(process.execPath, [taroBin, "build", "--watch", ...taroArgs], {
|
|
513
|
+
stdio: "inherit",
|
|
514
|
+
cwd: appPackageRoot,
|
|
515
|
+
env: { ...env, ...jwtEnv }
|
|
516
|
+
});
|
|
517
|
+
} else if (command === "build") {
|
|
518
|
+
const jwtEnv = await getJwtEnv();
|
|
519
|
+
(0, import_node_child_process2.execFileSync)(process.execPath, [taroBin, "build", ...taroArgs], {
|
|
520
|
+
stdio: "inherit",
|
|
521
|
+
cwd: appPackageRoot,
|
|
522
|
+
env: { ...env, ...jwtEnv }
|
|
523
|
+
});
|
|
524
|
+
} else if (command === "config") {
|
|
525
|
+
const { configWorkspace: configWorkspace2, printDeployment: printDeployment2 } = await Promise.resolve().then(() => (init_workspace(), workspace_exports));
|
|
526
|
+
if (argv.workspace)
|
|
527
|
+
return configWorkspace2({
|
|
528
|
+
workspaceRoot: import_path2.default.resolve(argv.workspace),
|
|
529
|
+
frameworkRoot: appPackageRoot
|
|
530
|
+
});
|
|
531
|
+
configDeploy();
|
|
532
|
+
if (argv.json) printDeployment2(appPackageRoot);
|
|
533
|
+
} else if (command === "upload") {
|
|
534
|
+
const { v, version, d, desc, P, progress } = argv;
|
|
535
|
+
await uploadMini(v || version, d || desc, P || progress);
|
|
536
|
+
} else if (command === "preview") {
|
|
537
|
+
const { v, version, p, path: previewPath, d, desc, s, scene, P, progress } = argv;
|
|
538
|
+
await previewMini(v || version, p || previewPath, d || desc, s || scene, P || progress);
|
|
539
|
+
}
|
|
717
540
|
}
|
|
718
|
-
main().catch(
|
|
719
|
-
|
|
720
|
-
|
|
541
|
+
main().catch((err) => {
|
|
542
|
+
console.error("XFE Mini CLI \u6267\u884C\u51FA\u9519:", err);
|
|
543
|
+
process.exit(1);
|
|
721
544
|
});
|