本文整理汇总了TypeScript中@electron-forge/core.api类的典型用法代码示例。如果您正苦于以下问题:TypeScript api类的具体用法?TypeScript api怎么用?TypeScript api使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了api类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: files
(async () => {
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[name]')
.option('-t, --template [name]', 'Name of the forge template to use')
.option('-c, --copy-ci-files', 'Whether to copy the templated CI files (defaults to false)', false)
.action((name) => {
if (!name) return;
if (path.isAbsolute(name)) {
dir = name;
} else {
dir = path.resolve(dir, name);
}
})
.parse(process.argv);
const initOpts: InitOptions = {
dir,
interactive: true,
copyCIFiles: !!program.copyCiFiles,
};
if (program.template) initOpts.template = program.template;
await api.init(initOpts);
})();
示例2: async
(async () => {
let repo!: string;
program
.version(require('../package.json').version)
.arguments('[repository]')
.option('--prerelease', 'Fetch prerelease versions')
.action((repository) => {
repo = repository;
})
.parse(process.argv);
const chooseAsset = async (assets: InstallAsset[]) => {
const choices: { name: string, value: string }[] = [];
assets.forEach((asset) => {
choices.push({ name: asset.name, value: asset.id });
});
const { assetID } = await inquirer.createPromptModule()<{ assetID: string }>({
choices,
type: 'list',
name: 'assetID',
message: 'Multiple potential assets found, please choose one from the list below:'.cyan,
});
return assets.find(asset => asset.id === assetID)!;
};
await api.install({
chooseAsset,
repo,
interactive: true,
prerelease: program.prerelease,
});
})();
示例3: if
(async () => {
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[cwd]')
.option('-a, --arch [arch]', 'Target architecture')
.option('-p, --platform [platform]', 'Target build platform')
.action((cwd) => {
if (!cwd) return;
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
dir = cwd;
} else if (fs.existsSync(path.resolve(dir, cwd))) {
dir = path.resolve(dir, cwd);
}
})
.parse(process.argv);
const packageOpts: PackageOptions = {
dir,
interactive: true,
};
if (program.arch) packageOpts.arch = program.arch;
if (program.platform) packageOpts.platform = program.platform;
await api.package(packageOpts);
})();
示例4: if
(async () => {
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[cwd]')
.option('--target [target[,target...]]', 'The comma-separated deployment targets, defaults to "github"')
.option('--dry-run', 'Triggers a publish dry run which saves state and doesn\'t upload anything')
.option('--from-dry-run', 'Attempts to publish artifacts from the last saved dry run')
.allowUnknownOption(true)
.action((cwd) => {
if (!cwd) return;
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
dir = cwd;
} else if (fs.existsSync(path.resolve(dir, cwd))) {
dir = path.resolve(dir, cwd);
}
})
.parse(process.argv);
const publishOpts: PublishOptions = {
dir,
interactive: true,
dryRun: program.dryRun,
dryRunResume: program.fromDryRun,
};
if (program.target) publishOpts.publishTargets = program.target.split(',');
publishOpts.makeOptions = getMakeOptions();
await api.publish(publishOpts);
})();
示例5: if
(async () => {
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[cwd]')
.action((cwd) => {
if (!cwd) return;
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
dir = cwd;
} else if (fs.existsSync(path.resolve(dir, cwd))) {
dir = path.resolve(dir, cwd);
}
})
.parse(process.argv);
await api.lint({
dir,
interactive: true,
});
})();
示例6:
(async () => {
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[name]')
.action((name) => {
if (!name) return;
if (path.isAbsolute(name)) {
dir = name;
} else {
dir = path.resolve(dir, name);
}
})
.parse(process.argv);
await api.import({
dir,
interactive: true,
});
})();
示例7: launch
(async () => {
let commandArgs = process.argv;
let appArgs;
const doubleDashIndex = process.argv.indexOf('--');
if (doubleDashIndex !== -1) {
commandArgs = process.argv.slice(0, doubleDashIndex);
appArgs = process.argv.slice(doubleDashIndex + 1);
}
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[cwd]')
.option('-p, --app-path <path>', 'Override the path to the Electron app to launch (defaults to \'.\')')
.option('-l, --enable-logging', 'Enable advanced logging. This will log internal Electron things')
.option('-n, --run-as-node', 'Run the Electron app as a Node.JS script')
.option('--vscode', 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.')
.option('-i, --inspect-electron', 'Triggers inspect mode on Electron to allow debugging the main process. Electron >1.7 only')
.action((cwd) => {
if (!cwd) return;
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
dir = cwd;
} else if (fs.existsSync(path.resolve(dir, cwd))) {
dir = path.resolve(dir, cwd);
}
})
.parse(commandArgs);
program.on('--help', () => {
console.log(' Any arguments found after "--" will be passed to the Electron app, e.g.');
console.log('');
console.log(' $ electron-forge /path/to/project -l -- -d -f foo.txt');
console.log('');
console.log(' will pass the arguments "-d -f foo.txt" to the Electron app');
});
const opts: StartOptions = {
dir,
interactive: true,
enableLogging: !!program.enableLogging,
runAsNode: !!program.runAsNode,
inspect: !!program.inspectElectron,
};
if (program.vscode && appArgs) {
// Args are in the format ~arg~ so we need to strip the "~"
appArgs = appArgs
.map(arg => arg.substr(1, arg.length - 2))
.filter(arg => arg.length > 0);
}
if (program.appPath) opts.appPath = program.appPath;
if (appArgs) opts.args = appArgs;
const spawned = await api.start(opts);
await new Promise((resolve) => {
spawned.on('exit', (code: number) => {
if ((spawned as any).restarted) return;
if (code !== 0) {
process.exit(code);
}
resolve();
});
});
})();
示例8: getMakeOptions
(async () => {
const makeOpts = getMakeOptions();
await api.make(makeOpts);
})();