@konomi-app/k2 3.4.0 → 4.0.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/dist/index.js +351 -338
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +571 -576
- package/dist/plugin.js.map +1 -1
- package/package.json +36 -35
package/dist/index.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
2
|
|
|
9
3
|
// src/index.ts
|
|
10
|
-
import { program as
|
|
4
|
+
import { program as program5 } from "commander";
|
|
11
5
|
|
|
12
6
|
// src/commands/build.ts
|
|
13
7
|
import { program } from "commander";
|
|
14
|
-
import "fs-extra";
|
|
15
8
|
import path6 from "path";
|
|
16
|
-
import
|
|
9
|
+
import chalk from "chalk";
|
|
17
10
|
|
|
18
11
|
// src/lib/constants.ts
|
|
19
12
|
import path from "path";
|
|
@@ -143,189 +136,131 @@ var getDefaultK2Config = () => {
|
|
|
143
136
|
};
|
|
144
137
|
};
|
|
145
138
|
|
|
146
|
-
// src/lib/
|
|
147
|
-
import
|
|
148
|
-
import fs2 from "fs-extra";
|
|
149
|
-
import os from "os";
|
|
139
|
+
// src/lib/rsbuild.ts
|
|
140
|
+
import { createRsbuild } from "@rsbuild/core";
|
|
150
141
|
import path5 from "path";
|
|
151
|
-
import
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
142
|
+
import fs2 from "fs-extra";
|
|
143
|
+
async function buildWithRsbuild(params) {
|
|
144
|
+
const { entries, outDir, minify = true, sourcemap = false, injectStyles = true } = params;
|
|
145
|
+
const sourceMapConfig = sourcemap === "inline" ? "cheap-module-source-map" : sourcemap ? "source-map" : false;
|
|
146
|
+
const rsbuild = await createRsbuild({
|
|
147
|
+
rsbuildConfig: {
|
|
148
|
+
source: { entry: entries },
|
|
149
|
+
output: {
|
|
150
|
+
target: "web",
|
|
151
|
+
distPath: { root: outDir, js: "" },
|
|
152
|
+
filename: { js: "[name].js" },
|
|
153
|
+
filenameHash: false,
|
|
154
|
+
cleanDistPath: true,
|
|
155
|
+
injectStyles,
|
|
156
|
+
sourceMap: { js: sourceMapConfig },
|
|
157
|
+
minify
|
|
158
|
+
},
|
|
159
|
+
performance: {
|
|
160
|
+
chunkSplit: { strategy: "all-in-one" }
|
|
161
|
+
},
|
|
162
|
+
tools: {
|
|
163
|
+
htmlPlugin: false
|
|
164
|
+
}
|
|
166
165
|
}
|
|
167
|
-
}
|
|
168
|
-
await
|
|
169
|
-
return results;
|
|
166
|
+
});
|
|
167
|
+
await rsbuild.build();
|
|
170
168
|
}
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// ブラウザ向けにNode.js固有のオブジェクトをビルド時に解決
|
|
185
|
-
define: {
|
|
186
|
-
"process.env.NODE_ENV": JSON.stringify(mode),
|
|
187
|
-
"process.env": JSON.stringify({}),
|
|
188
|
-
...config.define
|
|
169
|
+
async function startRsbuildDevServer(params) {
|
|
170
|
+
const { entries, outDir, port, https, publicDir, onFirstCompile, onRecompile } = params;
|
|
171
|
+
const rsbuildConfig = {
|
|
172
|
+
source: { entry: entries },
|
|
173
|
+
output: {
|
|
174
|
+
target: "web",
|
|
175
|
+
distPath: { root: outDir, js: "" },
|
|
176
|
+
filename: { js: "[name].js" },
|
|
177
|
+
filenameHash: false,
|
|
178
|
+
cleanDistPath: false,
|
|
179
|
+
injectStyles: true,
|
|
180
|
+
sourceMap: { js: "cheap-module-source-map" },
|
|
181
|
+
minify: false
|
|
189
182
|
},
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// ブラウザ向けターゲット
|
|
193
|
-
target: config.build?.target ?? "es2020",
|
|
194
|
-
cssCodeSplit: false,
|
|
195
|
-
rollupOptions: {
|
|
196
|
-
...config.build?.rollupOptions,
|
|
197
|
-
onwarn: (warning, warn) => {
|
|
198
|
-
if (["MODULE_LEVEL_DIRECTIVE"].includes(warning.code ?? "")) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (warning.message?.includes("sourcemap") || warning.code === "SOURCEMAP_ERROR") {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
warn(warning);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
183
|
+
performance: {
|
|
184
|
+
chunkSplit: { strategy: "all-in-one" }
|
|
207
185
|
},
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
186
|
+
tools: {
|
|
187
|
+
htmlPlugin: false
|
|
188
|
+
},
|
|
189
|
+
server: {
|
|
190
|
+
port,
|
|
191
|
+
host: "0.0.0.0",
|
|
192
|
+
...https ? { https } : {},
|
|
193
|
+
...publicDir && fs2.existsSync(publicDir) ? { publicDir: { name: publicDir } } : {}
|
|
194
|
+
},
|
|
195
|
+
dev: {
|
|
196
|
+
writeToDisk: true
|
|
215
197
|
}
|
|
216
198
|
};
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const name = entryNames[0];
|
|
231
|
-
await buildSingleEntry({
|
|
232
|
-
name,
|
|
233
|
-
entryPath: entries[name],
|
|
234
|
-
outDir,
|
|
235
|
-
mode,
|
|
236
|
-
sourcemap,
|
|
237
|
-
minify,
|
|
238
|
-
viteConfig
|
|
239
|
-
});
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
await parallelLimit(entryNames, concurrency, async (name) => {
|
|
243
|
-
await buildSingleEntry({
|
|
244
|
-
name,
|
|
245
|
-
entryPath: entries[name],
|
|
246
|
-
outDir,
|
|
247
|
-
mode,
|
|
248
|
-
sourcemap,
|
|
249
|
-
minify,
|
|
250
|
-
viteConfig
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
async function buildSingleEntry(params) {
|
|
255
|
-
const { name, entryPath, outDir, mode, sourcemap, minify, viteConfig } = params;
|
|
256
|
-
const config = createViteConfig({
|
|
257
|
-
...viteConfig,
|
|
258
|
-
mode,
|
|
259
|
-
build: {
|
|
260
|
-
...viteConfig.build,
|
|
261
|
-
rollupOptions: {
|
|
262
|
-
...viteConfig.build?.rollupOptions,
|
|
263
|
-
input: entryPath,
|
|
264
|
-
output: {
|
|
265
|
-
entryFileNames: `${name}.js`,
|
|
266
|
-
assetFileNames: `${name}.[ext]`,
|
|
267
|
-
// 外部ライブラリのソースマップを無視して警告を抑制
|
|
268
|
-
sourcemapIgnoreList: (relativeSourcePath) => {
|
|
269
|
-
return relativeSourcePath.includes("node_modules");
|
|
270
|
-
},
|
|
271
|
-
...viteConfig.build?.rollupOptions?.output
|
|
199
|
+
const rsbuild = await createRsbuild({ rsbuildConfig });
|
|
200
|
+
if (onFirstCompile || onRecompile) {
|
|
201
|
+
rsbuild.addPlugins([
|
|
202
|
+
{
|
|
203
|
+
name: "k2-dev-hooks",
|
|
204
|
+
setup(api) {
|
|
205
|
+
api.onDevCompileDone(async ({ isFirstCompile }) => {
|
|
206
|
+
if (isFirstCompile && onFirstCompile) {
|
|
207
|
+
await onFirstCompile();
|
|
208
|
+
} else if (!isFirstCompile && onRecompile) {
|
|
209
|
+
await onRecompile();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
272
212
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
await viteBuild(config);
|
|
213
|
+
}
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
const result = await rsbuild.startDevServer();
|
|
217
|
+
return {
|
|
218
|
+
port: result.port,
|
|
219
|
+
close: result.server.close
|
|
220
|
+
};
|
|
282
221
|
}
|
|
283
|
-
|
|
284
|
-
function getEntryPointsFromDir(inputDir) {
|
|
285
|
-
const entries = {};
|
|
222
|
+
function getAppEntryPoints(inputDir) {
|
|
286
223
|
if (!fs2.existsSync(inputDir)) {
|
|
287
|
-
|
|
224
|
+
return {};
|
|
288
225
|
}
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
entries[dirName] = entryPath;
|
|
298
|
-
break;
|
|
226
|
+
const allProjects = fs2.readdirSync(inputDir);
|
|
227
|
+
return allProjects.reduce((acc, dir) => {
|
|
228
|
+
const dirPath = path5.join(inputDir, dir);
|
|
229
|
+
if (!fs2.statSync(dirPath).isDirectory()) return acc;
|
|
230
|
+
for (const filename of ["index.ts", "index.tsx", "index.js", "index.jsx", "index.mjs"]) {
|
|
231
|
+
const filePath = path5.join(inputDir, dir, filename);
|
|
232
|
+
if (fs2.existsSync(filePath)) {
|
|
233
|
+
return { ...acc, [dir]: filePath };
|
|
299
234
|
}
|
|
300
235
|
}
|
|
301
|
-
|
|
302
|
-
|
|
236
|
+
return acc;
|
|
237
|
+
}, {});
|
|
303
238
|
}
|
|
304
239
|
|
|
305
240
|
// src/commands/build.ts
|
|
306
241
|
function command() {
|
|
307
|
-
program.command("build").option("-o, --outdir <outdir>", "Output directory.", path6.join(WORKSPACE_DIRECTORY, "prod")).option("-i, --input <input>", "Input directory.", path6.join("src", "apps")).option("--config <config>", "k2 config file path").description("Build the project for production with
|
|
242
|
+
program.command("build").option("-o, --outdir <outdir>", "Output directory.", path6.join(WORKSPACE_DIRECTORY, "prod")).option("-i, --input <input>", "Input directory.", path6.join("src", "apps")).option("--config <config>", "k2 config file path").description("Build the project for production with rsbuild.").action(action);
|
|
308
243
|
}
|
|
309
244
|
async function action(options) {
|
|
310
245
|
console.group("\u{1F373} Build the project for production");
|
|
311
246
|
try {
|
|
312
247
|
const { outdir, input, config } = options;
|
|
313
248
|
const outDir = path6.resolve(outdir);
|
|
314
|
-
const entries =
|
|
249
|
+
const entries = getAppEntryPoints(path6.resolve(input));
|
|
315
250
|
const entryNames = Object.keys(entries);
|
|
316
251
|
if (entryNames.length === 0) {
|
|
317
252
|
throw new Error(`No entry points found in ${input}`);
|
|
318
253
|
}
|
|
319
|
-
console.log(
|
|
254
|
+
console.log(chalk.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
320
255
|
const k2Config = config ? await importK2Config(config) : getDefaultK2Config();
|
|
321
256
|
const fullConfig = { ...k2Config, outDir };
|
|
322
257
|
const results = await Promise.allSettled([
|
|
323
|
-
|
|
258
|
+
buildWithRsbuild({
|
|
324
259
|
entries,
|
|
325
260
|
outDir,
|
|
326
|
-
|
|
261
|
+
minify: true,
|
|
327
262
|
sourcemap: false,
|
|
328
|
-
|
|
263
|
+
injectStyles: true
|
|
329
264
|
}),
|
|
330
265
|
buildTailwind(fullConfig)
|
|
331
266
|
]);
|
|
@@ -344,15 +279,14 @@ async function action(options) {
|
|
|
344
279
|
|
|
345
280
|
// src/commands/dev/index.ts
|
|
346
281
|
import { program as program2 } from "commander";
|
|
347
|
-
import
|
|
348
|
-
import
|
|
349
|
-
import
|
|
350
|
-
import chalk4 from "chalk";
|
|
282
|
+
import "fs-extra";
|
|
283
|
+
import path10 from "path";
|
|
284
|
+
import chalk3 from "chalk";
|
|
351
285
|
|
|
352
286
|
// src/commands/dev/tailwind.ts
|
|
353
287
|
import path7 from "path";
|
|
354
|
-
import
|
|
355
|
-
import
|
|
288
|
+
import chalk2 from "chalk";
|
|
289
|
+
import fs3 from "fs-extra";
|
|
356
290
|
var watchCss = async (params) => {
|
|
357
291
|
const { k2Config, outdir } = params;
|
|
358
292
|
if (!k2Config.tailwind?.css || !k2Config.tailwind?.config) {
|
|
@@ -362,8 +296,8 @@ var watchCss = async (params) => {
|
|
|
362
296
|
const tailwindConfig = await getTailwindConfigFromK2Config(k2Config.tailwind);
|
|
363
297
|
const input = path7.resolve(k2Config.tailwind.css);
|
|
364
298
|
const output = path7.join(outdir, "tailwind.css");
|
|
365
|
-
if (!await
|
|
366
|
-
await
|
|
299
|
+
if (!await fs3.pathExists(output)) {
|
|
300
|
+
await fs3.outputFile(output, "");
|
|
367
301
|
}
|
|
368
302
|
return watchTailwindCSS({
|
|
369
303
|
input,
|
|
@@ -372,50 +306,239 @@ var watchCss = async (params) => {
|
|
|
372
306
|
onChanges: ({ output: output2, type }) => {
|
|
373
307
|
const outputFileName = path7.basename(output2);
|
|
374
308
|
console.log(
|
|
375
|
-
|
|
309
|
+
chalk2.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk2.cyan(`[css] `) + outputFileName + (type === "init" ? " init" : ` rebuilt(${type})`)
|
|
376
310
|
);
|
|
377
311
|
}
|
|
378
312
|
});
|
|
379
313
|
};
|
|
380
314
|
|
|
381
|
-
// src/lib/
|
|
382
|
-
import
|
|
383
|
-
import
|
|
384
|
-
|
|
315
|
+
// src/lib/cert/index.ts
|
|
316
|
+
import fs4 from "fs-extra";
|
|
317
|
+
import path9 from "path";
|
|
318
|
+
|
|
319
|
+
// src/lib/cert/cert.ts
|
|
320
|
+
import forge from "node-forge";
|
|
321
|
+
import net from "net";
|
|
322
|
+
var { md, pki } = forge;
|
|
323
|
+
function createCertificate(serial, publicKey, subject, issuer, extensions, validity, signWith) {
|
|
324
|
+
const cert = pki.createCertificate();
|
|
325
|
+
cert.serialNumber = Buffer.from(serial).toString("hex");
|
|
326
|
+
cert.publicKey = publicKey;
|
|
327
|
+
cert.setSubject(subject);
|
|
328
|
+
cert.setIssuer(issuer);
|
|
329
|
+
cert.setExtensions(extensions);
|
|
330
|
+
cert.validity.notBefore = /* @__PURE__ */ new Date();
|
|
331
|
+
cert.validity.notAfter = /* @__PURE__ */ new Date();
|
|
332
|
+
cert.validity.notAfter.setDate(cert.validity.notAfter.getDate() + validity);
|
|
333
|
+
cert.sign(signWith, md.sha256.create());
|
|
334
|
+
return cert;
|
|
335
|
+
}
|
|
336
|
+
function generateCertInternal(params) {
|
|
337
|
+
const { subject, issuer, extensions, validity, signWith } = params;
|
|
338
|
+
const serial = Math.floor(Math.random() * 95e3 + 5e4).toString();
|
|
339
|
+
const keyPair = pki.rsa.generateKeyPair(2048);
|
|
340
|
+
const privateKey = signWith ? pki.privateKeyFromPem(signWith) : keyPair.privateKey;
|
|
341
|
+
const cert = createCertificate(
|
|
342
|
+
serial,
|
|
343
|
+
keyPair.publicKey,
|
|
344
|
+
subject,
|
|
345
|
+
issuer,
|
|
346
|
+
extensions,
|
|
347
|
+
validity,
|
|
348
|
+
privateKey
|
|
349
|
+
);
|
|
350
|
+
return {
|
|
351
|
+
key: pki.privateKeyToPem(keyPair.privateKey),
|
|
352
|
+
cert: pki.certificateToPem(cert)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function createCA(params = {}) {
|
|
356
|
+
const {
|
|
357
|
+
organization = "K2 Development CA",
|
|
358
|
+
countryCode = "JP",
|
|
359
|
+
state = "Tokyo",
|
|
360
|
+
locality = "Tokyo",
|
|
361
|
+
validity = 7300
|
|
362
|
+
} = params;
|
|
363
|
+
const attributes = [
|
|
364
|
+
{ name: "commonName", value: organization },
|
|
365
|
+
{ name: "countryName", value: countryCode },
|
|
366
|
+
{ name: "stateOrProvinceName", value: state },
|
|
367
|
+
{ name: "localityName", value: locality },
|
|
368
|
+
{ name: "organizationName", value: organization }
|
|
369
|
+
];
|
|
370
|
+
const extensions = [
|
|
371
|
+
{ name: "basicConstraints", cA: true, critical: true },
|
|
372
|
+
{ name: "keyUsage", keyCertSign: true, critical: true }
|
|
373
|
+
];
|
|
374
|
+
return generateCertInternal({
|
|
375
|
+
subject: attributes,
|
|
376
|
+
issuer: attributes,
|
|
377
|
+
extensions,
|
|
378
|
+
validity
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
function createCert(params) {
|
|
382
|
+
const { ca, domains, validity = 7300 } = params;
|
|
383
|
+
const attributes = [{ name: "commonName", value: domains[0] }];
|
|
384
|
+
const extensions = [
|
|
385
|
+
{ name: "basicConstraints", cA: false, critical: true },
|
|
386
|
+
{
|
|
387
|
+
name: "keyUsage",
|
|
388
|
+
digitalSignature: true,
|
|
389
|
+
keyEncipherment: true,
|
|
390
|
+
critical: true
|
|
391
|
+
},
|
|
392
|
+
{ name: "extKeyUsage", serverAuth: true, clientAuth: true },
|
|
393
|
+
{
|
|
394
|
+
name: "subjectAltName",
|
|
395
|
+
altNames: domains.map((domain) => {
|
|
396
|
+
const TYPE_DOMAIN = 2;
|
|
397
|
+
const TYPE_IP = 7;
|
|
398
|
+
return net.isIP(domain) ? { type: TYPE_IP, ip: domain } : { type: TYPE_DOMAIN, value: domain };
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
];
|
|
402
|
+
const caCert = pki.certificateFromPem(ca.cert.toString());
|
|
403
|
+
return generateCertInternal({
|
|
404
|
+
subject: attributes,
|
|
405
|
+
issuer: caCert.subject.attributes,
|
|
406
|
+
extensions,
|
|
407
|
+
validity,
|
|
408
|
+
signWith: ca.key.toString()
|
|
409
|
+
});
|
|
410
|
+
}
|
|
385
411
|
|
|
386
|
-
// src/lib/cert.ts
|
|
387
|
-
import fs5 from "fs-extra";
|
|
412
|
+
// src/lib/cert/constants.ts
|
|
388
413
|
import path8 from "path";
|
|
414
|
+
var PKG_NAME = "k2";
|
|
415
|
+
var isSupported = process.platform === "darwin" || process.platform === "linux" || process.platform === "win32";
|
|
416
|
+
function getApplicationConfigPath(name) {
|
|
417
|
+
if (process.platform === "darwin") {
|
|
418
|
+
return path8.join(process.env.HOME, "Library", "Application Support", name);
|
|
419
|
+
}
|
|
420
|
+
if (process.platform === "win32") {
|
|
421
|
+
return process.env.LOCALAPPDATA ? path8.join(process.env.LOCALAPPDATA, name) : path8.join(process.env.USERPROFILE, "Local Settings", "Application Data", name);
|
|
422
|
+
}
|
|
423
|
+
return process.env.XDG_CONFIG_HOME ? path8.join(process.env.XDG_CONFIG_HOME, name) : path8.join(process.env.HOME, ".config", name);
|
|
424
|
+
}
|
|
425
|
+
var pkgDir = getApplicationConfigPath(PKG_NAME);
|
|
426
|
+
var rootCAPath = path8.resolve(pkgDir, "rootCA.pem");
|
|
427
|
+
var rootCAKeyPath = path8.resolve(pkgDir, "rootCA-key.pem");
|
|
428
|
+
|
|
429
|
+
// src/lib/cert/platforms.ts
|
|
430
|
+
import { spawnSync } from "child_process";
|
|
431
|
+
|
|
432
|
+
// src/lib/logger.ts
|
|
433
|
+
var PKG_NAME2 = "@konomi-app/k2";
|
|
434
|
+
function createLogger(prefix = PKG_NAME2) {
|
|
435
|
+
return {
|
|
436
|
+
log: (...args) => console.log(`[${prefix}]`, ...args),
|
|
437
|
+
info: (...args) => console.info(`[${prefix}]`, ...args),
|
|
438
|
+
warn: (...args) => console.warn(`[${prefix}]`, ...args),
|
|
439
|
+
error: (...args) => console.error(`[${prefix}]`, ...args)
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
var logger_default = createLogger();
|
|
443
|
+
|
|
444
|
+
// src/lib/cert/platforms.ts
|
|
445
|
+
function addToTrustStoresDarwin(certPath) {
|
|
446
|
+
logger_default.log("Adding certificate to trusted store. Admin rights may be required.");
|
|
447
|
+
spawnSync(
|
|
448
|
+
"sudo",
|
|
449
|
+
[
|
|
450
|
+
"security",
|
|
451
|
+
"add-trusted-cert",
|
|
452
|
+
"-d",
|
|
453
|
+
"-r",
|
|
454
|
+
"trustRoot",
|
|
455
|
+
"-k",
|
|
456
|
+
"/Library/Keychains/System.keychain",
|
|
457
|
+
"-p",
|
|
458
|
+
"ssl",
|
|
459
|
+
"-p",
|
|
460
|
+
"basic",
|
|
461
|
+
certPath
|
|
462
|
+
],
|
|
463
|
+
{ stdio: "inherit" }
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
var targetCA = `/usr/local/share/ca-certificates/${PKG_NAME}.crt`;
|
|
467
|
+
function addToTrustStoresLinux(certPath) {
|
|
468
|
+
logger_default.log("Adding certificate to trusted store. Admin rights may be required.");
|
|
469
|
+
spawnSync("sudo", ["cp", certPath, targetCA]);
|
|
470
|
+
spawnSync("sudo", ["update-ca-certificates"]);
|
|
471
|
+
}
|
|
472
|
+
function addToTrustStoresWin32(certPath) {
|
|
473
|
+
spawnSync("certutil", ["-addstore", "-user", "root", certPath], {
|
|
474
|
+
stdio: "inherit"
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function addToTrustStores(certPath) {
|
|
478
|
+
switch (process.platform) {
|
|
479
|
+
case "darwin":
|
|
480
|
+
return addToTrustStoresDarwin(certPath);
|
|
481
|
+
case "linux":
|
|
482
|
+
return addToTrustStoresLinux(certPath);
|
|
483
|
+
case "win32":
|
|
484
|
+
return addToTrustStoresWin32(certPath);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// src/lib/cert/index.ts
|
|
389
489
|
var CERT_KEY_FILENAME = "localhost-key.pem";
|
|
390
490
|
var CERT_FILENAME = "localhost-cert.pem";
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
491
|
+
function install(options = {}) {
|
|
492
|
+
const { validity = 7300 } = options;
|
|
493
|
+
if (!isSupported) {
|
|
494
|
+
throw new Error(`Platform not supported: "${process.platform}"`);
|
|
495
|
+
}
|
|
496
|
+
if (!fs4.existsSync(rootCAPath) && !fs4.existsSync(rootCAKeyPath)) {
|
|
497
|
+
const ca = createCA({ validity });
|
|
498
|
+
fs4.outputFileSync(rootCAPath, ca.cert);
|
|
499
|
+
fs4.outputFileSync(rootCAKeyPath, ca.key);
|
|
500
|
+
try {
|
|
501
|
+
addToTrustStores(rootCAPath);
|
|
502
|
+
} catch {
|
|
503
|
+
console.warn(
|
|
504
|
+
"\u26A0 Failed to add CA to system trust store. You may need to trust the certificate manually."
|
|
505
|
+
);
|
|
402
506
|
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function certificateFor(requestedDomains = []) {
|
|
510
|
+
const validity = 7300;
|
|
511
|
+
install({ validity });
|
|
512
|
+
const requests = Array.isArray(requestedDomains) ? requestedDomains : [requestedDomains];
|
|
513
|
+
const domains = [
|
|
514
|
+
.../* @__PURE__ */ new Set(["localhost", "localhost.localdomain", "127.0.0.1", "0.0.0.0", "::1", ...requests])
|
|
515
|
+
];
|
|
516
|
+
const ca = {
|
|
517
|
+
cert: fs4.readFileSync(rootCAPath),
|
|
518
|
+
key: fs4.readFileSync(rootCAKeyPath)
|
|
519
|
+
};
|
|
520
|
+
return createCert({ ca, domains, validity });
|
|
521
|
+
}
|
|
522
|
+
function generateCert(outDir) {
|
|
523
|
+
fs4.ensureDirSync(outDir);
|
|
524
|
+
const result = certificateFor();
|
|
525
|
+
fs4.outputFileSync(path9.join(outDir, CERT_FILENAME), result.cert);
|
|
526
|
+
fs4.outputFileSync(path9.join(outDir, CERT_KEY_FILENAME), result.key);
|
|
527
|
+
return result;
|
|
528
|
+
}
|
|
406
529
|
function hasCertificates(certDir) {
|
|
407
|
-
return
|
|
530
|
+
return fs4.existsSync(path9.join(certDir, CERT_KEY_FILENAME)) && fs4.existsSync(path9.join(certDir, CERT_FILENAME));
|
|
408
531
|
}
|
|
409
532
|
function loadCertificates(certDir) {
|
|
410
533
|
return {
|
|
411
|
-
key:
|
|
412
|
-
cert:
|
|
534
|
+
key: fs4.readFileSync(path9.join(certDir, CERT_KEY_FILENAME)),
|
|
535
|
+
cert: fs4.readFileSync(path9.join(certDir, CERT_FILENAME))
|
|
413
536
|
};
|
|
414
537
|
}
|
|
415
538
|
|
|
416
539
|
// src/commands/dev/index.ts
|
|
417
540
|
function command2() {
|
|
418
|
-
program2.command("dev").description("Start development server with
|
|
541
|
+
program2.command("dev").description("Start development server with rsbuild.").option("-i, --input <input>", "Input directory", "src/apps").option("-o, --outdir <outdir>", "Output directory.", DEVELOPMENT_DIRECTORY).option("-c, --certdir <certdir>", "Certificate directory", WORKSPACE_DIRECTORY).option("--config <config>", "k2 config file path").option("-p, --port <port>", "Port number").action(action2);
|
|
419
542
|
}
|
|
420
543
|
async function action2(options) {
|
|
421
544
|
const { certdir, outdir, config, port: specifiedPort, input } = options;
|
|
@@ -430,100 +553,45 @@ async function action2(options) {
|
|
|
430
553
|
console.log(`\u2699 ${CONFIG_FILE_NAME} not found. use default settings.`);
|
|
431
554
|
}
|
|
432
555
|
const port = Number(specifiedPort ?? k2Config?.server?.port ?? DEFAULT_PORT);
|
|
433
|
-
const certDirPath =
|
|
434
|
-
const outputDir =
|
|
435
|
-
const inputDir =
|
|
556
|
+
const certDirPath = path10.resolve(certdir);
|
|
557
|
+
const outputDir = path10.resolve(outdir);
|
|
558
|
+
const inputDir = path10.resolve(input);
|
|
436
559
|
if (!hasCertificates(certDirPath)) {
|
|
437
|
-
console.log(
|
|
560
|
+
console.log(chalk3.yellow("\u{1F4DC} SSL certificates not found. Generating with node-forge..."));
|
|
438
561
|
try {
|
|
439
|
-
|
|
440
|
-
console.log(
|
|
562
|
+
generateCert(certDirPath);
|
|
563
|
+
console.log(chalk3.green("\u2705 SSL certificates generated successfully"));
|
|
441
564
|
} catch (error) {
|
|
442
|
-
console.log(
|
|
443
|
-
chalk4.red("\u274C Failed to generate SSL certificates. Make sure mkcert is installed.")
|
|
444
|
-
);
|
|
445
|
-
console.log(chalk4.gray(" Install mkcert: https://github.com/FiloSottile/mkcert"));
|
|
565
|
+
console.log(chalk3.red("\u274C Failed to generate SSL certificates."));
|
|
446
566
|
throw error;
|
|
447
567
|
}
|
|
448
568
|
}
|
|
449
|
-
const entries =
|
|
569
|
+
const entries = getAppEntryPoints(inputDir);
|
|
450
570
|
const entryNames = Object.keys(entries);
|
|
451
571
|
if (entryNames.length === 0) {
|
|
452
572
|
throw new Error(`No entry points found in ${input}`);
|
|
453
573
|
}
|
|
454
|
-
console.log(
|
|
455
|
-
await fs6.emptyDir(outputDir);
|
|
574
|
+
console.log(chalk3.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
456
575
|
const { key, cert } = loadCertificates(certDirPath);
|
|
457
|
-
|
|
458
|
-
await buildEntriesWithVite({
|
|
576
|
+
const { port: actualPort } = await startRsbuildDevServer({
|
|
459
577
|
entries,
|
|
460
578
|
outDir: outputDir,
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
root: outputDir,
|
|
467
|
-
server: {
|
|
468
|
-
port,
|
|
469
|
-
https: { key, cert }
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
const server = await createServer(serverConfig);
|
|
473
|
-
await server.listen();
|
|
474
|
-
console.log(chalk4.green(`
|
|
579
|
+
port,
|
|
580
|
+
https: { key, cert },
|
|
581
|
+
publicDir: outputDir,
|
|
582
|
+
onFirstCompile: () => {
|
|
583
|
+
console.log(chalk3.green(`
|
|
475
584
|
\u2728 Development server ready!`));
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
persistent: true,
|
|
485
|
-
ignoreInitial: true
|
|
486
|
-
});
|
|
487
|
-
const watchExtensions = [".ts", ".tsx", ".js", ".jsx", ".css", ".scss"];
|
|
488
|
-
const shouldRebuild = (filePath) => {
|
|
489
|
-
const ext = path9.extname(filePath).toLowerCase();
|
|
490
|
-
return watchExtensions.includes(ext);
|
|
491
|
-
};
|
|
492
|
-
const rebuild = async () => {
|
|
493
|
-
console.log(chalk4.gray(` ${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Rebuilding...`));
|
|
494
|
-
await buildEntriesWithVite({
|
|
495
|
-
entries,
|
|
496
|
-
outDir: outputDir,
|
|
497
|
-
mode: "development",
|
|
498
|
-
sourcemap: "inline",
|
|
499
|
-
minify: false
|
|
500
|
-
});
|
|
501
|
-
console.log(chalk4.gray(` ${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Rebuild complete`));
|
|
502
|
-
};
|
|
503
|
-
watcher.on("ready", () => {
|
|
504
|
-
console.log(chalk4.green(" \u2713 File watcher ready"));
|
|
505
|
-
});
|
|
506
|
-
watcher.on("change", (filePath) => {
|
|
507
|
-
if (shouldRebuild(filePath)) {
|
|
508
|
-
console.log(chalk4.cyan(` [change] ${filePath}`));
|
|
509
|
-
rebuild();
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
watcher.on("add", (filePath) => {
|
|
513
|
-
if (shouldRebuild(filePath)) {
|
|
514
|
-
console.log(chalk4.cyan(` [add] ${filePath}`));
|
|
515
|
-
rebuild();
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
watcher.on("unlink", (filePath) => {
|
|
519
|
-
if (shouldRebuild(filePath)) {
|
|
520
|
-
console.log(chalk4.cyan(` [unlink] ${filePath}`));
|
|
521
|
-
rebuild();
|
|
585
|
+
console.log(chalk3.cyan(` Local: https://localhost:${actualPort}`));
|
|
586
|
+
console.log(chalk3.gray(` Output: ${outputDir}`));
|
|
587
|
+
console.log(chalk3.gray("\n Watching for changes...\n"));
|
|
588
|
+
},
|
|
589
|
+
onRecompile: () => {
|
|
590
|
+
console.log(
|
|
591
|
+
chalk3.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk3.cyan(`[rsbuild] `) + `rebuild complete`
|
|
592
|
+
);
|
|
522
593
|
}
|
|
523
594
|
});
|
|
524
|
-
watcher.on("error", (error) => {
|
|
525
|
-
console.error(chalk4.red(` Watcher error: ${error}`));
|
|
526
|
-
});
|
|
527
595
|
if (k2Config) {
|
|
528
596
|
await watchCss({ k2Config, outdir });
|
|
529
597
|
}
|
|
@@ -536,69 +604,15 @@ async function action2(options) {
|
|
|
536
604
|
|
|
537
605
|
// src/commands/genkey.ts
|
|
538
606
|
import { program as program3 } from "commander";
|
|
539
|
-
|
|
540
|
-
// src/commands/genkey-base.ts
|
|
541
|
-
async function action3(options) {
|
|
542
|
-
const { output } = options;
|
|
543
|
-
console.group("\u{1F373} Generate SSL key for localhost");
|
|
544
|
-
try {
|
|
545
|
-
const { stdout } = await generateCert(output);
|
|
546
|
-
if (stdout) {
|
|
547
|
-
console.log(stdout);
|
|
548
|
-
}
|
|
549
|
-
console.log(`\u{1F511} key generation success. Output to ./${output}`);
|
|
550
|
-
} catch (error) {
|
|
551
|
-
throw error;
|
|
552
|
-
} finally {
|
|
553
|
-
console.groupEnd();
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// src/commands/genkey.ts
|
|
558
607
|
function command3() {
|
|
559
|
-
program3.command("genkey").description("Generate SSL
|
|
560
|
-
}
|
|
561
|
-
async function action4(options) {
|
|
562
|
-
await action3(options);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/commands/build-esbuild.ts
|
|
566
|
-
import { program as program4 } from "commander";
|
|
567
|
-
import "fs-extra";
|
|
568
|
-
import path10 from "path";
|
|
569
|
-
import chalk5 from "chalk";
|
|
570
|
-
function command4() {
|
|
571
|
-
program4.command("esbuild-build").option("-o, --outdir <outdir>", "Output directory.", path10.join(WORKSPACE_DIRECTORY, "prod")).option("-i, --input <input>", "Input directory.", path10.join("src", "apps")).option("--config <config>", "k2 config file path").description("Build the project for production with Vite. (Legacy command name, now uses Vite)").action(action5);
|
|
608
|
+
program3.command("genkey").description("Generate SSL certificate for localhost using node-forge.").option("-o, --output <output>", "Output directory.", WORKSPACE_DIRECTORY).action(action3);
|
|
572
609
|
}
|
|
573
|
-
async function
|
|
574
|
-
|
|
610
|
+
async function action3(options) {
|
|
611
|
+
const { output } = options;
|
|
612
|
+
console.group("\u{1F373} Generate SSL certificate for localhost");
|
|
575
613
|
try {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const entries = getEntryPointsFromDir(path10.resolve(input));
|
|
579
|
-
const entryNames = Object.keys(entries);
|
|
580
|
-
if (entryNames.length === 0) {
|
|
581
|
-
throw new Error(`No entry points found in ${input}`);
|
|
582
|
-
}
|
|
583
|
-
console.log(chalk5.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
584
|
-
const k2Config = config ? await importK2Config(config) : getDefaultK2Config();
|
|
585
|
-
const fullConfig = { ...k2Config, outDir };
|
|
586
|
-
const results = await Promise.allSettled([
|
|
587
|
-
buildEntriesWithVite({
|
|
588
|
-
entries,
|
|
589
|
-
outDir,
|
|
590
|
-
mode: "production",
|
|
591
|
-
sourcemap: false,
|
|
592
|
-
minify: true
|
|
593
|
-
}),
|
|
594
|
-
buildTailwind(fullConfig)
|
|
595
|
-
]);
|
|
596
|
-
for (const result of results) {
|
|
597
|
-
if (result.status === "rejected") {
|
|
598
|
-
throw result.reason;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
console.log("\u2728 Build success.");
|
|
614
|
+
generateCert(output);
|
|
615
|
+
console.log(`\u{1F511} Certificate generated. Output to ./${output}`);
|
|
602
616
|
} catch (error) {
|
|
603
617
|
throw error;
|
|
604
618
|
} finally {
|
|
@@ -607,7 +621,7 @@ async function action5(options) {
|
|
|
607
621
|
}
|
|
608
622
|
|
|
609
623
|
// src/commands/lint.ts
|
|
610
|
-
import { program as
|
|
624
|
+
import { program as program4 } from "commander";
|
|
611
625
|
|
|
612
626
|
// src/lib/lint.ts
|
|
613
627
|
import { ESLint } from "eslint";
|
|
@@ -639,10 +653,10 @@ async function lint() {
|
|
|
639
653
|
}
|
|
640
654
|
|
|
641
655
|
// src/commands/lint.ts
|
|
642
|
-
function
|
|
643
|
-
|
|
656
|
+
function command4() {
|
|
657
|
+
program4.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(action4);
|
|
644
658
|
}
|
|
645
|
-
async function
|
|
659
|
+
async function action4(options) {
|
|
646
660
|
try {
|
|
647
661
|
lint();
|
|
648
662
|
} catch (error) {
|
|
@@ -652,11 +666,10 @@ async function action6(options) {
|
|
|
652
666
|
}
|
|
653
667
|
|
|
654
668
|
// src/index.ts
|
|
655
|
-
|
|
669
|
+
program5.name("k2").version("4.0.0").description("k2 - \u{1F373} kintone kitchen \u{1F373}");
|
|
656
670
|
command();
|
|
657
|
-
command4();
|
|
658
671
|
command2();
|
|
659
672
|
command3();
|
|
660
|
-
|
|
661
|
-
|
|
673
|
+
command4();
|
|
674
|
+
program5.parse(process.argv);
|
|
662
675
|
//# sourceMappingURL=index.js.map
|