2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-26 07:13:26 +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([ async.waterfall([
function (callback) { function (callback) {
console.log("Dir: ", tmpobj.name);
copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.badge, options.width, options.height, callback); copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.badge, options.width, options.height, callback);
}, },
function (tempDir, 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 optionsFactory from './options';
import buildApp from './buildApp'; import buildApp from './buildApp';
function main() { const packageJson = require(path.join('..', 'package'));
const options = optionsFactory();
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) => { buildApp(options, (error, appPath) => {
if (error) { if (error) {
console.trace(error); console.error(error);
return; 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 TEMPLATE_APP_DIR = path.join(__dirname, '../', 'app');
const ELECTRON_VERSION = '0.36.4'; const ELECTRON_VERSION = '0.36.4';
function optionsFactory(name = 'MyApp', function optionsFactory(name = 'MyApp',
targetUrl = 'http://google.com', targetUrl = 'http://google.com',
platform = detectPlatform(), platform = detectPlatform(),
architecture = detectArch(), arch = detectArch(),
version = ELECTRON_VERSION, version = ELECTRON_VERSION,
outDir = os.homedir(), outDir = process.cwd(),
overwrite = true, overwrite = true,
conceal = true, conceal = false,
iconDir, icon,
badge = false, badge = false,
width = 1280, width = 1280,
height = 800) { height = 800) {
@ -24,7 +23,7 @@ function optionsFactory(name = 'MyApp',
targetUrl: targetUrl, targetUrl: targetUrl,
platform: platform, platform: platform,
arch: architecture, arch: arch,
version: version, version: version,
out: outDir, out: outDir,
@ -32,7 +31,7 @@ function optionsFactory(name = 'MyApp',
// optionals // optionals
overwrite: overwrite, overwrite: overwrite,
asar: conceal, asar: conceal,
icon: iconDir, icon: icon,
// app configuration // app configuration
badge: badge, badge: badge,
@ -41,7 +40,6 @@ function optionsFactory(name = 'MyApp',
} }
} }
function detectPlatform() { function detectPlatform() {
const platform = os.platform(); const platform = os.platform();
if (platform === 'darwin' || platform === 'win32' || platform === 'linux') { if (platform === 'darwin' || platform === 'win32' || platform === 'linux') {