Initial commit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dinlo
2026-05-31 18:44:04 +08:00
commit 436a9631fc
8616 changed files with 1389957 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
#! /usr/bin/env node
export {};
+70
View File
@@ -0,0 +1,70 @@
#! /usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const electronVersion_1 = require("app-builder-lib/out/electron/electronVersion");
const load_1 = require("app-builder-lib/out/util/config/load");
const yarn_1 = require("app-builder-lib/out/util/yarn");
const builder_util_1 = require("builder-util");
const chalk = require("chalk");
const fs_extra_1 = require("fs-extra");
const ci_info_1 = require("ci-info");
const path = require("path");
const builder_1 = require("../builder");
const publish_1 = require("../publish");
const create_self_signed_cert_1 = require("./create-self-signed-cert");
const install_app_deps_1 = require("./install-app-deps");
const start_1 = require("./start");
// tslint:disable:no-unused-expression
void (0, builder_1.createYargs)()
.command(["build", "*"], "Build", builder_1.configureBuildCommand, wrap(builder_1.build))
.command("install-app-deps", "Install app deps", install_app_deps_1.configureInstallAppDepsCommand, wrap(install_app_deps_1.installAppDeps))
.command("node-gyp-rebuild", "Rebuild own native code", install_app_deps_1.configureInstallAppDepsCommand /* yes, args the same as for install app deps */, wrap(rebuildAppNativeCode))
.command("publish", "Publish a list of artifacts", publish_1.configurePublishCommand, wrap(publish_1.publish))
.command("create-self-signed-cert", "Create self-signed code signing cert for Windows apps", yargs => yargs
.option("publisher", {
alias: ["p"],
type: "string",
requiresArg: true,
description: "The publisher name",
})
.demandOption("publisher"), wrap(argv => (0, create_self_signed_cert_1.createSelfSignedCert)(argv.publisher)))
.command("start", "Run application in a development mode using electron-webpack", yargs => yargs, wrap(() => (0, start_1.start)()))
.help()
.epilog(`See ${chalk.underline("https://electron.build")} for more documentation.`)
.strict()
.recommendCommands().argv;
function wrap(task) {
return (args) => {
checkIsOutdated().catch((e) => builder_util_1.log.warn({ error: e }, "cannot check updates"));
(0, load_1.loadEnv)(path.join(process.cwd(), "electron-builder.env"))
.then(() => task(args))
.catch(error => {
process.exitCode = 1;
// https://github.com/electron-userland/electron-builder/issues/2940
process.on("exit", () => (process.exitCode = 1));
if (error instanceof builder_util_1.InvalidConfigurationError) {
builder_util_1.log.error(null, error.message);
}
else if (!(error instanceof builder_util_1.ExecError) || !error.alreadyLogged) {
builder_util_1.log.error({ failedTask: task.name, stackTrace: error.stack }, error.message);
}
});
};
}
async function checkIsOutdated() {
if (ci_info_1.isCI || process.env.NO_UPDATE_NOTIFIER != null) {
return;
}
const pkg = await (0, fs_extra_1.readJson)(path.join(__dirname, "..", "..", "package.json"));
if (pkg.version === "0.0.0-semantic-release") {
return;
}
const UpdateNotifier = require("simple-update-notifier");
await UpdateNotifier({ pkg });
}
async function rebuildAppNativeCode(args) {
const projectDir = process.cwd();
// this script must be used only for electron
return (0, yarn_1.nodeGypRebuild)(args.platform, args.arch, { version: await (0, electronVersion_1.getElectronVersion)(projectDir), useCustomDist: true });
}
//# sourceMappingURL=cli.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export {};
+40
View File
@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSelfSignedCert = createSelfSignedCert;
const windows_1 = require("app-builder-lib/out/toolsets/windows");
const builder_util_1 = require("builder-util");
const filename_1 = require("builder-util/out/filename");
const chalk = require("chalk");
const promises_1 = require("fs/promises");
const path = require("path");
/** @internal */
async function createSelfSignedCert(publisher) {
const tmpDir = new builder_util_1.TmpDir("create-self-signed-cert");
const targetDir = process.cwd();
const tempPrefix = path.join(await tmpDir.getTempDir({ prefix: "self-signed-cert-creator" }), (0, filename_1.sanitizeFileName)(publisher));
const cer = `${tempPrefix}.cer`;
const pvk = `${tempPrefix}.pvk`;
builder_util_1.log.info(chalk.bold('When asked to enter a password ("Create Private Key Password"), please select "None".'));
try {
await (0, promises_1.mkdir)(path.dirname(tempPrefix), { recursive: true });
const vendorPath = (await (0, windows_1.getWindowsKitsBundle)({ winCodeSign: null, arch: (0, builder_util_1.archFromString)(process.arch) })).kit;
await (0, builder_util_1.exec)(path.join(vendorPath, "makecert.exe"), ["-r", "-h", "0", "-n", `CN=${quoteString(publisher)}`, "-eku", "1.3.6.1.5.5.7.3.3", "-pe", "-sv", pvk, cer]);
const pfx = path.join(targetDir, `${(0, filename_1.sanitizeFileName)(publisher)}.pfx`);
await (0, builder_util_1.unlinkIfExists)(pfx);
await (0, builder_util_1.exec)(path.join(vendorPath, "pvk2pfx.exe"), ["-pvk", pvk, "-spc", cer, "-pfx", pfx]);
builder_util_1.log.info({ file: pfx }, `created. Please see https://electron.build/code-signing how to use it to sign.`);
const certLocation = "Cert:\\LocalMachine\\TrustedPeople";
builder_util_1.log.info({ file: pfx, certLocation }, `importing. Operation will be succeed only if runned from root. Otherwise import file manually.`);
await (0, builder_util_1.spawn)("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "Import-PfxCertificate", "-FilePath", `"${pfx}"`, "-CertStoreLocation", certLocation]);
}
finally {
await tmpDir.cleanup();
}
}
function quoteString(s) {
if (!s.includes(",") && !s.includes('"')) {
return s;
}
return `"${s.replace(/"/g, '\\"')}"`;
}
//# sourceMappingURL=create-self-signed-cert.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"create-self-signed-cert.js","sourceRoot":"","sources":["../../src/cli/create-self-signed-cert.ts"],"names":[],"mappings":";;AAQA,oDAyBC;AAjCD,kEAA2E;AAC3E,+CAAuF;AACvF,wDAA4D;AAC5D,+BAA8B;AAC9B,0CAAmC;AACnC,6BAA4B;AAE5B,gBAAgB;AACT,KAAK,UAAU,oBAAoB,CAAC,SAAiB;IAC1D,MAAM,MAAM,GAAG,IAAI,qBAAM,CAAC,yBAAyB,CAAC,CAAA;IACpD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,UAAU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C,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,gFAAgF,CAAC,CAAA;QAEzG,MAAM,YAAY,GAAG,oCAAoC,CAAA;QACzD,kBAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,iGAAiG,CAAC,CAAA;QACxI,MAAM,IAAA,oBAAK,EAAC,gBAAgB,EAAE,CAAC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,uBAAuB,EAAE,WAAW,EAAE,IAAI,GAAG,GAAG,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC,CAAA;IACpK,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,CAAS;IAC5B,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAA;AACtC,CAAC","sourcesContent":["import { getWindowsKitsBundle } from \"app-builder-lib/out/toolsets/windows\"\nimport { archFromString, exec, log, spawn, TmpDir, unlinkIfExists } from \"builder-util\"\nimport { sanitizeFileName } from \"builder-util/out/filename\"\nimport * as chalk from \"chalk\"\nimport { mkdir } from \"fs/promises\"\nimport * as path from \"path\"\n\n/** @internal */\nexport async function createSelfSignedCert(publisher: string) {\n const tmpDir = new TmpDir(\"create-self-signed-cert\")\n const targetDir = process.cwd()\n const tempPrefix = path.join(await tmpDir.getTempDir({ prefix: \"self-signed-cert-creator\" }), sanitizeFileName(publisher))\n const cer = `${tempPrefix}.cer`\n const pvk = `${tempPrefix}.pvk`\n\n log.info(chalk.bold('When asked to enter a password (\"Create Private Key Password\"), please select \"None\".'))\n\n try {\n await mkdir(path.dirname(tempPrefix), { recursive: true })\n const vendorPath = (await getWindowsKitsBundle({ winCodeSign: null, arch: archFromString(process.arch) })).kit\n await exec(path.join(vendorPath, \"makecert.exe\"), [\"-r\", \"-h\", \"0\", \"-n\", `CN=${quoteString(publisher)}`, \"-eku\", \"1.3.6.1.5.5.7.3.3\", \"-pe\", \"-sv\", pvk, cer])\n\n const pfx = path.join(targetDir, `${sanitizeFileName(publisher)}.pfx`)\n await unlinkIfExists(pfx)\n await exec(path.join(vendorPath, \"pvk2pfx.exe\"), [\"-pvk\", pvk, \"-spc\", cer, \"-pfx\", pfx])\n log.info({ file: pfx }, `created. Please see https://electron.build/code-signing how to use it to sign.`)\n\n const certLocation = \"Cert:\\\\LocalMachine\\\\TrustedPeople\"\n log.info({ file: pfx, certLocation }, `importing. Operation will be succeed only if runned from root. Otherwise import file manually.`)\n await spawn(\"powershell.exe\", [\"-NoProfile\", \"-NonInteractive\", \"-Command\", \"Import-PfxCertificate\", \"-FilePath\", `\"${pfx}\"`, \"-CertStoreLocation\", certLocation])\n } finally {\n await tmpDir.cleanup()\n }\n}\n\nfunction quoteString(s: string): string {\n if (!s.includes(\",\") && !s.includes('\"')) {\n return s\n }\n\n return `\"${s.replace(/\"/g, '\\\\\"')}\"`\n}\n"]}
+2
View File
@@ -0,0 +1,2 @@
#! /usr/bin/env node
export {};
+73
View File
@@ -0,0 +1,73 @@
#! /usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.configureInstallAppDepsCommand = configureInstallAppDepsCommand;
exports.installAppDeps = installAppDeps;
const electronVersion_1 = require("app-builder-lib/out/electron/electronVersion");
const config_1 = require("app-builder-lib/out/util/config/config");
const load_1 = require("app-builder-lib/out/util/config/load");
const packageDependencies_1 = require("app-builder-lib/out/util/packageDependencies");
const yarn_1 = require("app-builder-lib/out/util/yarn");
const version_1 = require("app-builder-lib/out/version");
const node_module_collector_1 = require("app-builder-lib/out/node-module-collector");
const builder_util_1 = require("builder-util");
const fs_extra_1 = require("fs-extra");
const lazy_val_1 = require("lazy-val");
const path = require("path");
const yargs = require("yargs");
/** @internal */
function configureInstallAppDepsCommand(yargs) {
// https://github.com/yargs/yargs/issues/760
// demandOption is required to be set
return yargs
.parserConfiguration({
"camel-case-expansion": false,
})
.option("platform", {
choices: ["linux", "darwin", "win32"],
default: process.platform,
description: "The target platform",
})
.option("arch", {
choices: (0, builder_util_1.getArchCliNames)().concat("all"),
default: process.arch === "arm" ? "armv7l" : process.arch,
description: "The target arch",
});
}
/** @internal */
async function installAppDeps(args) {
var _a;
try {
builder_util_1.log.info({ version: version_1.PACKAGE_VERSION }, "electron-builder");
}
catch (e) {
// error in dev mode without babel
if (!(e instanceof ReferenceError)) {
throw e;
}
}
const projectDir = process.cwd();
const packageMetadata = new lazy_val_1.Lazy(() => (0, load_1.orNullIfFileNotExist)((0, fs_extra_1.readJson)(path.join(projectDir, "package.json"))));
const config = await (0, config_1.getConfig)(projectDir, null, null, packageMetadata);
const [appDir, version] = await Promise.all([(0, config_1.computeDefaultAppDirectory)(projectDir, (_a = config.directories) === null || _a === void 0 ? void 0 : _a.app), (0, electronVersion_1.getElectronVersion)(projectDir, config)]);
const packageManagerEnv = (0, node_module_collector_1.determinePackageManagerEnv)({ projectDir, appDir, workspaceRoot: undefined });
// if two package.json — force full install (user wants to install/update app deps in addition to dev)
await (0, yarn_1.installOrRebuild)(config, {
appDir,
projectDir,
workspaceRoot: await (await packageManagerEnv.value).workspaceRoot,
}, {
frameworkInfo: { version, useCustomDist: true },
platform: args.platform,
arch: args.arch,
productionDeps: (0, packageDependencies_1.createLazyProductionDeps)(appDir, null, false),
}, appDir !== projectDir, {});
}
function main() {
return installAppDeps(configureInstallAppDepsCommand(yargs).argv);
}
if (require.main === module) {
builder_util_1.log.warn("please use as subcommand: electron-builder install-app-deps");
main().catch(builder_util_1.printErrorAndExit);
}
//# sourceMappingURL=install-app-deps.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export {};
+9
View File
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.start = start;
/** @internal */
function start() {
require("electron-webpack/dev-runner");
return Promise.resolve();
}
//# sourceMappingURL=start.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/cli/start.ts"],"names":[],"mappings":";;AACA,sBAGC;AAJD,gBAAgB;AAChB,SAAgB,KAAK;IACnB,OAAO,CAAC,6BAA6B,CAAC,CAAA;IACtC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["/** @internal */\nexport function start() {\n require(\"electron-webpack/dev-runner\")\n return Promise.resolve()\n}\n"]}