2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-23 10:38:55 +00:00

Implement cli

This commit is contained in:
Jia Hao 2016-01-18 23:38:52 +08:00
parent 36b5597063
commit 0fe67234f2
3 changed files with 57 additions and 15 deletions

View File

@ -27,8 +27,6 @@ function buildApp(options, callback) {
async.waterfall([
function (callback) {
console.log("Dir: ", tmpobj.name);
copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.badge, options.width, options.height, callback);
},
function (tempDir, callback) {

56
src/cli.js Normal file → Executable file
View File

@ -1,12 +1,33 @@
import commander from 'commander';
#! /usr/bin/env node
import path from 'path';
import program from 'commander';
import optionsFactory from './options';
import buildApp from './buildApp';
function main() {
const options = optionsFactory();
const packageJson = require(path.join('..', 'package'));
function main(program) {
const options = optionsFactory(
program.appName,
program.targetUrl,
program.platform,
program.arch,
program.electronVersion,
program.outDir,
program.overwrite,
program.conceal,
program.icon,
program.badge,
program.width,
program.height);
console.log(`Using Electron v${options.version}`);
console.log(options);
buildApp(options, (error, appPath) => {
if (error) {
console.trace(error);
console.error(error);
return;
}
@ -14,4 +35,29 @@ function main() {
});
}
main();
if (require.main === module) {
program
.version(packageJson.version)
.arguments('<targetUrl> [appDir]')
.action(function (targetUrl, appDir) {
program.targetUrl = targetUrl;
program.outDir = appDir;
})
.option('-n, --appName [value]', 'app name')
.option('-p, --platform [platform]', 'linux, win32, or darwin')
.option('-a, --arch [architecture]', 'ia32 or x64')
.option('-e, --electron-version', 'electron version to package, without the \'v\', see https://github.com/atom/electron/releases')
.option('-o, --overwrite', 'if output directory for a platform already exists, replaces it rather than skipping it, defaults to true')
.option('-c, --conceal', 'packages the source code within your app into an archive, defaults to false, see http://electron.atom.io/docs/v0.36.0/tutorial/application-packaging/')
.option('-i, --icon [dir]', 'the icon file to use as the icon for the app (should be a .icns file on OSX)')
.option('-b, --badge', 'if the target app should show badges in the dock on receipt of desktop notifications (OSX only), defaults to false')
.option('-w, --width [value]', 'set window width, defaults to 1280px')
.option('-h, --height [value]', 'set window height, defaults to 800px')
.parse(process.argv);
if (!process.argv.slice(2).length) {
program.help();
}
main(program);
}

View File

@ -4,16 +4,15 @@ import path from 'path';
const TEMPLATE_APP_DIR = path.join(__dirname, '../', 'app');
const ELECTRON_VERSION = '0.36.4';
function optionsFactory(name = 'MyApp',
targetUrl = 'http://google.com',
platform = detectPlatform(),
architecture = detectArch(),
arch = detectArch(),
version = ELECTRON_VERSION,
outDir = os.homedir(),
outDir = process.cwd(),
overwrite = true,
conceal = true,
iconDir,
conceal = false,
icon,
badge = false,
width = 1280,
height = 800) {
@ -24,7 +23,7 @@ function optionsFactory(name = 'MyApp',
targetUrl: targetUrl,
platform: platform,
arch: architecture,
arch: arch,
version: version,
out: outDir,
@ -32,7 +31,7 @@ function optionsFactory(name = 'MyApp',
// optionals
overwrite: overwrite,
asar: conceal,
icon: iconDir,
icon: icon,
// app configuration
badge: badge,
@ -41,7 +40,6 @@ function optionsFactory(name = 'MyApp',
}
}
function detectPlatform() {
const platform = os.platform();
if (platform === 'darwin' || platform === 'win32' || platform === 'linux') {