@xfe-repo/mini-app 2.0.0-beta.1 → 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 +35 -0
- package/config/index.ts +2 -0
- package/deploy/.drone.yml +154 -156
- 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 +9 -10
- package/dist/cli.js +503 -703
- package/dist/cli.mjs +53 -367
- package/dist/config.d.mts +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +168 -301
- package/dist/config.mjs +10 -2
- package/dist/preview.js +87 -401
- package/dist/preview.mjs +10 -2
- package/dist/upload.js +83 -349
- package/dist/upload.mjs +6 -2
- package/dist/workspace-7FXUJJOQ.mjs +220 -0
- package/package.json +5 -4
- package/dist/chunk-UC6ZB6VU.mjs +0 -242
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
2
|
+
|
|
3
|
+
// ../../shared/deploy/workspace.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { execFileSync } from "child_process";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
var ApplicationType = /* @__PURE__ */ ((ApplicationType2) => {
|
|
9
|
+
ApplicationType2["Node"] = "node";
|
|
10
|
+
ApplicationType2["Web"] = "web";
|
|
11
|
+
ApplicationType2["Mini"] = "mini";
|
|
12
|
+
return ApplicationType2;
|
|
13
|
+
})(ApplicationType || {});
|
|
14
|
+
var COMMAND_OUTPUT_LIMIT = 8 * 1024 * 1024;
|
|
15
|
+
var APPLICATION_NAME = /^[a-z][a-z0-9-]*$/;
|
|
16
|
+
function configWorkspace({ workspaceRoot, frameworkRoot }) {
|
|
17
|
+
const root = fs.realpathSync(workspaceRoot);
|
|
18
|
+
const configuration = readJson(path.join(root, "xfe.json"));
|
|
19
|
+
const applications = configuration.deploy?.applications;
|
|
20
|
+
const targets = configuration.deploy?.targets ?? Object.keys(applications ?? {});
|
|
21
|
+
if (!applications || typeof applications !== "object" || Array.isArray(applications)) {
|
|
22
|
+
throw new Error("\u6839 xfe.json.deploy.applications \u5FC5\u987B\u58F0\u660E\u5E94\u7528\u76EE\u5F55\u548C type");
|
|
23
|
+
}
|
|
24
|
+
if (!Array.isArray(targets) || targets.some((name) => !Object.hasOwn(applications, name))) {
|
|
25
|
+
throw new Error("deploy.targets \u5FC5\u987B\u662F\u5DF2\u58F0\u660E\u5E94\u7528\u540D\u7EC4\u6210\u7684\u6570\u7EC4");
|
|
26
|
+
}
|
|
27
|
+
const yaml = createRequire(path.join(frameworkRoot, "package.json"))("yaml");
|
|
28
|
+
const order = orderTargets({ applications, targets });
|
|
29
|
+
const output = [];
|
|
30
|
+
const steps = [];
|
|
31
|
+
const deploymentNames = /* @__PURE__ */ new Set();
|
|
32
|
+
let pipeline;
|
|
33
|
+
for (const name of order) {
|
|
34
|
+
if (!APPLICATION_NAME.test(name)) throw new Error(`\u5E94\u7528\u540D\u79F0\u65E0\u6548: ${name}`);
|
|
35
|
+
const application = applications[name];
|
|
36
|
+
const directory = resolveApplication(root, application);
|
|
37
|
+
const packageJson = readJson(path.join(directory, "package.json"));
|
|
38
|
+
const project = readJson(path.join(directory, "xfe.json"));
|
|
39
|
+
if (!project.deploy) throw new Error(`\u5E94\u7528 ${name} \u7F3A\u5C11 xfe.json.deploy`);
|
|
40
|
+
const deploymentName = project.project;
|
|
41
|
+
if (typeof deploymentName !== "string" || !APPLICATION_NAME.test(deploymentName) || deploymentNames.has(deploymentName)) {
|
|
42
|
+
throw new Error(`\u5E94\u7528 ${name} \u5FC5\u987B\u6709\u552F\u4E00\u7684 xfe.json.project \u5C0F\u5199\u53D1\u5E03\u540D\u79F0`);
|
|
43
|
+
}
|
|
44
|
+
deploymentNames.add(deploymentName);
|
|
45
|
+
const provider = application.type === "mini" /* Mini */ ? "@xfe-repo/mini-app" : "@xfe-repo/web-app";
|
|
46
|
+
const providerRoot = application.type === "node" /* Node */ ? resolveWebProvider({ root, applications }) : path.dirname(createRequire(path.join(directory, "package.json")).resolve(`${provider}/package.json`));
|
|
47
|
+
const raw = execFileSync(process.execPath, [path.join(providerRoot, "bin/index.js"), "config", "--json"], {
|
|
48
|
+
cwd: directory,
|
|
49
|
+
encoding: "utf8",
|
|
50
|
+
maxBuffer: COMMAND_OUTPUT_LIMIT
|
|
51
|
+
});
|
|
52
|
+
const documents = JSON.parse(raw);
|
|
53
|
+
const appPipeline = documents.find((document) => document.kind === "pipeline");
|
|
54
|
+
if (!appPipeline) throw new Error(`\u5E94\u7528 ${name} \u672A\u751F\u6210\u6D41\u6C34\u7EBF\uFF0C\u8BF7\u914D\u7F6E xfe.json.deploy`);
|
|
55
|
+
if (!pipeline) {
|
|
56
|
+
pipeline = { ...appPipeline, name: "deploy", steps };
|
|
57
|
+
steps.push(appPipeline.steps.find((step) => step.name === "install"));
|
|
58
|
+
steps.push({
|
|
59
|
+
name: "configure",
|
|
60
|
+
image: steps[0].image,
|
|
61
|
+
pull: "if-not-exists",
|
|
62
|
+
commands: ["pnpm deploy:config", "git diff --exit-code -- deploy/.drone.yml"]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const relative = path.relative(root, directory).split(path.sep).join("/");
|
|
66
|
+
const secrets = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const document of documents.filter((document2) => document2.kind === "secret")) {
|
|
68
|
+
const secretName = document.name === "target-k8s-config" ? `${name}-${document.name}` : document.name;
|
|
69
|
+
const secret = { ...document, name: secretName };
|
|
70
|
+
const existing = output.find((item) => item.name === secretName);
|
|
71
|
+
if (existing && JSON.stringify(existing) !== JSON.stringify(secret)) throw new Error(`\u51ED\u636E\u58F0\u660E\u51B2\u7A81: ${secretName}`);
|
|
72
|
+
secrets.set(document.name, secretName);
|
|
73
|
+
if (!existing) output.push(secret);
|
|
74
|
+
}
|
|
75
|
+
for (const step of appPipeline.steps) {
|
|
76
|
+
if (["install", "configure"].includes(step.name)) continue;
|
|
77
|
+
const next = { ...step, name: `${name}-${step.name}` };
|
|
78
|
+
if (next.depends_on) next.depends_on = next.depends_on.map((dependency) => `${name}-${dependency}`);
|
|
79
|
+
if (next.environment) {
|
|
80
|
+
next.environment = Object.fromEntries(
|
|
81
|
+
Object.entries(next.environment).map(([key, value]) => [
|
|
82
|
+
key,
|
|
83
|
+
value?.from_secret && secrets.has(value.from_secret) ? { from_secret: secrets.get(value.from_secret) } : value
|
|
84
|
+
])
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (step.commands) {
|
|
88
|
+
let commands = step.commands.filter(
|
|
89
|
+
(command) => !["pnpm exec xfe-web config", "git diff --exit-code -- deploy/.drone.yml", "cp -a node_modules deploy/modules"].includes(
|
|
90
|
+
command
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
if (application.type === "node" /* Node */ && step.name === "build") commands = ["pnpm run build:ci"];
|
|
94
|
+
if (step.name === "build" && application.type !== "mini" /* Mini */) {
|
|
95
|
+
commands.push(
|
|
96
|
+
...packageCommands({
|
|
97
|
+
name,
|
|
98
|
+
relative,
|
|
99
|
+
packageName: packageJson.name,
|
|
100
|
+
isWeb: application.type === "web" /* Web */
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
next.commands = [
|
|
105
|
+
`cd ${quote(relative)}`,
|
|
106
|
+
...commands.map(
|
|
107
|
+
(command) => command.replaceAll("$DRONE_REPO_NAME", deploymentName).replaceAll("${DRONE_REPO}", deploymentName).replaceAll("$DRONE_REPO", deploymentName).replaceAll("$CI_COMMIT_SHA", "$DRONE_COMMIT_SHA")
|
|
108
|
+
)
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
if (step.name === "image-build") {
|
|
112
|
+
const context = application.type === "mini" /* Mini */ ? relative : `deploy/artifacts/${name}`;
|
|
113
|
+
next.settings = {
|
|
114
|
+
...step.settings,
|
|
115
|
+
repo_name: deploymentName,
|
|
116
|
+
tags: step.settings.tags.map((tag) => tag.replaceAll("${CI_COMMIT_SHA}", "${DRONE_COMMIT_SHA}")),
|
|
117
|
+
context,
|
|
118
|
+
dockerfile: application.type === "mini" /* Mini */ ? "deploy/Dockerfile" : "Dockerfile"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
steps.push(next);
|
|
122
|
+
}
|
|
123
|
+
if (application.type === "node" /* Node */) {
|
|
124
|
+
fs.copyFileSync(path.join(directory, "migration-job.yaml"), path.join(directory, "deploy/helm/templates/migration-job.yaml"));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!pipeline) throw new Error("deploy.targets \u81F3\u5C11\u9700\u8981\u9009\u62E9\u4E00\u4E2A\u5E94\u7528");
|
|
128
|
+
steps[0].commands = ["pnpm config set registry https://registry.npmmirror.com", "pnpm install --frozen-lockfile"];
|
|
129
|
+
const deployDirectory = path.join(root, "deploy");
|
|
130
|
+
if (fs.lstatSync(deployDirectory, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("\u6839 deploy \u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5");
|
|
131
|
+
fs.mkdirSync(deployDirectory, { recursive: true });
|
|
132
|
+
fs.writeFileSync(
|
|
133
|
+
path.join(deployDirectory, ".drone.yml"),
|
|
134
|
+
[pipeline, ...output].map((document) => yaml.stringify(document, { defaultStringType: "QUOTE_SINGLE", defaultKeyType: "PLAIN", lineWidth: 0 })).join("---\n")
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function printDeployment(frameworkRoot) {
|
|
138
|
+
const yaml = createRequire(path.join(frameworkRoot, "package.json"))("yaml");
|
|
139
|
+
const source = fs.readFileSync(path.join(process.cwd(), "deploy/.drone.yml"), "utf8");
|
|
140
|
+
process.stdout.write(
|
|
141
|
+
JSON.stringify(
|
|
142
|
+
yaml.parseAllDocuments(source).map((document) => document.toJS()).filter(Boolean)
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
function orderTargets({ applications, targets }) {
|
|
147
|
+
const ordered = [];
|
|
148
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
149
|
+
const selected = new Set(targets);
|
|
150
|
+
const visit = (name) => {
|
|
151
|
+
if (ordered.includes(name)) return;
|
|
152
|
+
if (visiting.has(name)) throw new Error(`\u5E94\u7528\u53D1\u5E03\u987A\u5E8F\u5305\u542B\u5FAA\u73AF: ${name}`);
|
|
153
|
+
const dependencies = applications[name].dependsOn ?? [];
|
|
154
|
+
if (!Array.isArray(dependencies) || dependencies.some((dependency) => !Object.hasOwn(applications, dependency))) {
|
|
155
|
+
throw new Error(`\u5E94\u7528 ${name} \u7684 dependsOn \u5305\u542B\u672A\u77E5\u5E94\u7528`);
|
|
156
|
+
}
|
|
157
|
+
visiting.add(name);
|
|
158
|
+
dependencies.filter((dependency) => selected.has(dependency)).forEach(visit);
|
|
159
|
+
visiting.delete(name);
|
|
160
|
+
ordered.push(name);
|
|
161
|
+
};
|
|
162
|
+
targets.forEach(visit);
|
|
163
|
+
return ordered;
|
|
164
|
+
}
|
|
165
|
+
function resolveApplication(root, application) {
|
|
166
|
+
if (!application || typeof application.directory !== "string" || !Object.values(ApplicationType).includes(application.type)) {
|
|
167
|
+
throw new Error("\u5E94\u7528\u5FC5\u987B\u58F0\u660E directory\uFF0C\u4EE5\u53CA node\u3001web\u3001mini \u4E2D\u7684 type");
|
|
168
|
+
}
|
|
169
|
+
const directory = fs.realpathSync(path.resolve(root, application.directory));
|
|
170
|
+
const relative = path.relative(root, directory);
|
|
171
|
+
if (!relative || relative.split(path.sep)[0] === ".." || path.isAbsolute(relative)) throw new Error("\u5E94\u7528\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u4ED3\u5E93\u5185");
|
|
172
|
+
return directory;
|
|
173
|
+
}
|
|
174
|
+
function resolveWebProvider({ root, applications }) {
|
|
175
|
+
const application = Object.values(applications).find((application2) => application2.type === "web" /* Web */);
|
|
176
|
+
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");
|
|
177
|
+
const directory = resolveApplication(root, application);
|
|
178
|
+
return path.dirname(createRequire(path.join(directory, "package.json")).resolve("@xfe-repo/web-app/package.json"));
|
|
179
|
+
}
|
|
180
|
+
function packageCommands({
|
|
181
|
+
name,
|
|
182
|
+
relative,
|
|
183
|
+
packageName,
|
|
184
|
+
isWeb
|
|
185
|
+
}) {
|
|
186
|
+
if (typeof packageName !== "string" || !packageName) throw new Error(`\u5E94\u7528 ${name} \u7F3A\u5C11 package.json.name`);
|
|
187
|
+
const root = path.posix.relative(relative, ".") || ".";
|
|
188
|
+
const commands = [
|
|
189
|
+
`packageDirectory="$PWD/${root}/deploy/artifacts/${name}"`,
|
|
190
|
+
`pnpm --dir ${quote(root)} --filter ${quote(packageName)} deploy --legacy --prod "$packageDirectory"`
|
|
191
|
+
];
|
|
192
|
+
const selfReference = packageName.startsWith("@") ? "../../../.." : "../../..";
|
|
193
|
+
commands.push(
|
|
194
|
+
`selfLink="$packageDirectory/node_modules/.pnpm/node_modules/${packageName}"`,
|
|
195
|
+
`if [ -L "$selfLink" ]; then ln -sfn ${quote(selfReference)} "$selfLink"; fi`
|
|
196
|
+
);
|
|
197
|
+
if (isWeb) {
|
|
198
|
+
commands.push(
|
|
199
|
+
'mkdir -p "$packageDirectory/deploy"',
|
|
200
|
+
'mv "$packageDirectory/node_modules" "$packageDirectory/deploy/modules"',
|
|
201
|
+
`selfLink="$packageDirectory/deploy/modules/.pnpm/node_modules/${packageName}"`,
|
|
202
|
+
`if [ -L "$selfLink" ]; then ln -sfn ${quote(`../${selfReference}`)} "$selfLink"; fi`,
|
|
203
|
+
'cp -a deploy/static "$packageDirectory/deploy/static"',
|
|
204
|
+
'cp deploy/Dockerfile "$packageDirectory/Dockerfile"'
|
|
205
|
+
);
|
|
206
|
+
return commands;
|
|
207
|
+
}
|
|
208
|
+
commands.push('cp Dockerfile "$packageDirectory/Dockerfile"');
|
|
209
|
+
return commands;
|
|
210
|
+
}
|
|
211
|
+
function readJson(file) {
|
|
212
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
213
|
+
}
|
|
214
|
+
function quote(value) {
|
|
215
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
configWorkspace,
|
|
219
|
+
printDeployment
|
|
220
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/mini-app",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"bin": {
|
|
5
5
|
"xfe-mini": "./bin/index.js"
|
|
6
6
|
},
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"typescript": "5.3.3",
|
|
52
52
|
"webpack": "5.91.0",
|
|
53
53
|
"yaml": "^2.3.4",
|
|
54
|
-
"@xfe-repo/
|
|
55
|
-
"@xfe-repo/
|
|
54
|
+
"@xfe-repo/routes-define-webpack-plugin": "2.0.0-beta.1",
|
|
55
|
+
"@xfe-repo/typescript-config": "2.0.0-beta.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": "18.2.0",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"build": "tsup",
|
|
66
66
|
"dev": "tsup --watch",
|
|
67
67
|
"lint": "eslint \"src/**/*.ts*\" --fix",
|
|
68
|
-
"clean": "rm -rf .turbo coverage dist node_modules"
|
|
68
|
+
"clean": "rm -rf .turbo coverage dist node_modules",
|
|
69
|
+
"test": "pnpm build && node --test test/*.test.cjs"
|
|
69
70
|
}
|
|
70
71
|
}
|
package/dist/chunk-UC6ZB6VU.mjs
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
40
|
-
return d(g, "next", {
|
|
41
|
-
value: verb(0)
|
|
42
|
-
}), d(g, "throw", {
|
|
43
|
-
value: verb(1)
|
|
44
|
-
}), d(g, "return", {
|
|
45
|
-
value: verb(2)
|
|
46
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
47
|
-
value: function() {
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
}), g;
|
|
51
|
-
function verb(n) {
|
|
52
|
-
return function(v) {
|
|
53
|
-
return step([
|
|
54
|
-
n,
|
|
55
|
-
v
|
|
56
|
-
]);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function step(op) {
|
|
60
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
62
|
-
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;
|
|
63
|
-
if (y = 0, t) op = [
|
|
64
|
-
op[0] & 2,
|
|
65
|
-
t.value
|
|
66
|
-
];
|
|
67
|
-
switch(op[0]){
|
|
68
|
-
case 0:
|
|
69
|
-
case 1:
|
|
70
|
-
t = op;
|
|
71
|
-
break;
|
|
72
|
-
case 4:
|
|
73
|
-
_.label++;
|
|
74
|
-
return {
|
|
75
|
-
value: op[1],
|
|
76
|
-
done: false
|
|
77
|
-
};
|
|
78
|
-
case 5:
|
|
79
|
-
_.label++;
|
|
80
|
-
y = op[1];
|
|
81
|
-
op = [
|
|
82
|
-
0
|
|
83
|
-
];
|
|
84
|
-
continue;
|
|
85
|
-
case 7:
|
|
86
|
-
op = _.ops.pop();
|
|
87
|
-
_.trys.pop();
|
|
88
|
-
continue;
|
|
89
|
-
default:
|
|
90
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
91
|
-
_ = 0;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
95
|
-
_.label = op[1];
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
99
|
-
_.label = t[1];
|
|
100
|
-
t = op;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (t && _.label < t[2]) {
|
|
104
|
-
_.label = t[2];
|
|
105
|
-
_.ops.push(op);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (t[2]) _.ops.pop();
|
|
109
|
-
_.trys.pop();
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
op = body.call(thisArg, _);
|
|
113
|
-
} catch (e) {
|
|
114
|
-
op = [
|
|
115
|
-
6,
|
|
116
|
-
e
|
|
117
|
-
];
|
|
118
|
-
y = 0;
|
|
119
|
-
} finally{
|
|
120
|
-
f = t = 0;
|
|
121
|
-
}
|
|
122
|
-
if (op[0] & 5) throw op[1];
|
|
123
|
-
return {
|
|
124
|
-
value: op[0] ? op[1] : void 0,
|
|
125
|
-
done: true
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// src/config.ts
|
|
130
|
-
import path from "path";
|
|
131
|
-
import fs from "fs";
|
|
132
|
-
import yaml from "yaml";
|
|
133
|
-
var loadXfeConfig = function loadXfeConfig() {
|
|
134
|
-
var xfeConfigPath = "./xfe.json";
|
|
135
|
-
if (!fs.existsSync(xfeConfigPath)) {
|
|
136
|
-
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");
|
|
137
|
-
}
|
|
138
|
-
var xfeConfigContent = fs.readFileSync(xfeConfigPath, "utf8");
|
|
139
|
-
return JSON.parse(xfeConfigContent);
|
|
140
|
-
};
|
|
141
|
-
var configDeploy = function configDeploy() {
|
|
142
|
-
var xfeConfig = loadXfeConfig();
|
|
143
|
-
if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.deploy)) return;
|
|
144
|
-
var droneConfigFilePath = path.resolve(__dirname, "../deploy/.drone.yml");
|
|
145
|
-
fs.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
|
|
146
|
-
var valuesYamlFilePath = path.resolve(__dirname, "../deploy/helm/values.yaml");
|
|
147
|
-
var valuesYamlFile = fs.readFileSync(valuesYamlFilePath, "utf8");
|
|
148
|
-
var valuesYaml = yaml.parse(valuesYamlFile);
|
|
149
|
-
if (!valuesYaml.virtualService) valuesYaml.virtualService = {};
|
|
150
|
-
if (!valuesYaml.virtualService.hosts) valuesYaml.virtualService.hosts = {
|
|
151
|
-
test: [],
|
|
152
|
-
stage: [],
|
|
153
|
-
prod: []
|
|
154
|
-
};
|
|
155
|
-
var _xfeConfig_deploy = xfeConfig.deploy, _xfeConfig_deploy_virtualServiceEnabled = _xfeConfig_deploy.virtualServiceEnabled, virtualServiceEnabled = _xfeConfig_deploy_virtualServiceEnabled === void 0 ? true : _xfeConfig_deploy_virtualServiceEnabled, _xfeConfig_deploy_hostsProd = _xfeConfig_deploy.hostsProd, hostsProd = _xfeConfig_deploy_hostsProd === void 0 ? [] : _xfeConfig_deploy_hostsProd, _xfeConfig_deploy_hostsStage = _xfeConfig_deploy.hostsStage, hostsStage = _xfeConfig_deploy_hostsStage === void 0 ? [] : _xfeConfig_deploy_hostsStage, _xfeConfig_deploy_hostsTest = _xfeConfig_deploy.hostsTest, hostsTest = _xfeConfig_deploy_hostsTest === void 0 ? [] : _xfeConfig_deploy_hostsTest, _xfeConfig_deploy_gateways = _xfeConfig_deploy.gateways, gateways = _xfeConfig_deploy_gateways === void 0 ? [
|
|
156
|
-
"common-gateway-eshetang"
|
|
157
|
-
] : _xfeConfig_deploy_gateways;
|
|
158
|
-
var _xfeConfig_deploy1 = xfeConfig.deploy, _xfeConfig_deploy_targetK8s = _xfeConfig_deploy1.targetK8s, targetK8s = _xfeConfig_deploy_targetK8s === void 0 ? "saas" : _xfeConfig_deploy_targetK8s, _xfeConfig_deploy_targetNamespace = _xfeConfig_deploy1.targetNamespace, targetNamespace = _xfeConfig_deploy_targetNamespace === void 0 ? "" : _xfeConfig_deploy_targetNamespace;
|
|
159
|
-
valuesYaml.virtualService.enabled = virtualServiceEnabled;
|
|
160
|
-
valuesYaml.virtualService.gateways = gateways;
|
|
161
|
-
valuesYaml.virtualService.hosts.prod = hostsProd;
|
|
162
|
-
valuesYaml.virtualService.hosts.stage = hostsStage;
|
|
163
|
-
valuesYaml.virtualService.hosts.test = hostsTest;
|
|
164
|
-
valuesYaml.targetK8s = targetK8s;
|
|
165
|
-
valuesYaml.namespace = targetNamespace;
|
|
166
|
-
var valuesYamlStr = yaml.stringify(valuesYaml, {
|
|
167
|
-
defaultStringType: "QUOTE_SINGLE",
|
|
168
|
-
defaultKeyType: "PLAIN"
|
|
169
|
-
});
|
|
170
|
-
fs.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
|
|
171
|
-
};
|
|
172
|
-
var getJwtEnv = function getJwtEnv() {
|
|
173
|
-
return _async_to_generator(function() {
|
|
174
|
-
var xfeConfig, _xfeConfig_jwt, _xfeConfig_jwt_aud, aud, jwkRes, JwkResponseJson, err, _, _1, _2, _ref, keyId, privateKeyPkcs8;
|
|
175
|
-
return _ts_generator(this, function(_state) {
|
|
176
|
-
switch(_state.label){
|
|
177
|
-
case 0:
|
|
178
|
-
xfeConfig = loadXfeConfig();
|
|
179
|
-
if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.jwt)) return [
|
|
180
|
-
2,
|
|
181
|
-
{}
|
|
182
|
-
];
|
|
183
|
-
_xfeConfig_jwt = xfeConfig.jwt, _xfeConfig_jwt_aud = _xfeConfig_jwt.aud, aud = _xfeConfig_jwt_aud === void 0 ? "" : _xfeConfig_jwt_aud;
|
|
184
|
-
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");
|
|
185
|
-
return [
|
|
186
|
-
4,
|
|
187
|
-
fetch("https://app.eshetang.com/jwk?appId=".concat(aud))
|
|
188
|
-
];
|
|
189
|
-
case 1:
|
|
190
|
-
jwkRes = _state.sent();
|
|
191
|
-
if (!jwkRes.ok) {
|
|
192
|
-
throw new Error("远程获取密钥失败: ".concat(jwkRes.status, " ").concat(jwkRes.statusText));
|
|
193
|
-
}
|
|
194
|
-
_state.label = 2;
|
|
195
|
-
case 2:
|
|
196
|
-
_state.trys.push([
|
|
197
|
-
2,
|
|
198
|
-
4,
|
|
199
|
-
,
|
|
200
|
-
6
|
|
201
|
-
]);
|
|
202
|
-
return [
|
|
203
|
-
4,
|
|
204
|
-
jwkRes.json()
|
|
205
|
-
];
|
|
206
|
-
case 3:
|
|
207
|
-
JwkResponseJson = _state.sent();
|
|
208
|
-
return [
|
|
209
|
-
3,
|
|
210
|
-
6
|
|
211
|
-
];
|
|
212
|
-
case 4:
|
|
213
|
-
err = _state.sent();
|
|
214
|
-
_ = Error.bind;
|
|
215
|
-
_2 = (_1 = "远程获取密钥失败,响应解析错误: ".concat(err.message, ", response text: ")).concat;
|
|
216
|
-
return [
|
|
217
|
-
4,
|
|
218
|
-
jwkRes.text()
|
|
219
|
-
];
|
|
220
|
-
case 5:
|
|
221
|
-
throw new (_.apply(Error, [
|
|
222
|
-
void 0,
|
|
223
|
-
_2.apply(_1, [
|
|
224
|
-
_state.sent()
|
|
225
|
-
])
|
|
226
|
-
]));
|
|
227
|
-
case 6:
|
|
228
|
-
_ref = (JwkResponseJson === null || JwkResponseJson === void 0 ? void 0 : JwkResponseJson.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
|
|
229
|
-
if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
|
|
230
|
-
return [
|
|
231
|
-
2,
|
|
232
|
-
{
|
|
233
|
-
XFE_JWT_AUD: aud,
|
|
234
|
-
XFE_JWT_KEY_ID: keyId,
|
|
235
|
-
XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
|
|
236
|
-
}
|
|
237
|
-
];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
})();
|
|
241
|
-
};
|
|
242
|
-
export { loadXfeConfig, configDeploy, getJwtEnv };
|