Fixed enormous bug in not passing the app configuration properly

This commit is contained in:
Jia Hao 2015-07-05 16:43:32 +08:00
parent 4a621b14a7
commit 4495b26c92
5 changed files with 68 additions and 20 deletions

2
.gitignore vendored
View File

@ -2,8 +2,6 @@ node_modules
.DS_Store
build/
# the file used to pass variables from the cli to the app
app/targetUrl.txt

View File

@ -31,13 +31,12 @@ app.on('ready', function() {
);
mainWindow.loadUrl('file://' + __dirname + '/index.html');
//mainWindow.openDevTools();
mainWindow.webContents.on('did-finish-load', function() {
fs.readFile(__dirname + '/targetUrl.txt', 'utf8', function (error, data) {
fs.readFile(APP_ARGS_FILE_PATH, 'utf8', function (error, data) {
if (error) {
console.error('Error reading file: ' + error);
} else {
console.log(data);
mainWindow.webContents.send('params', data);
}

34
cli.js
View File

@ -4,8 +4,10 @@ var args = require('minimist')(process.argv.slice(2), {boolean: ['prune', 'asar'
var packager = require('./');
var usage = fs.readFileSync(__dirname + '/usage.txt').toString();
var validator = require('validator');
var tempDir = require('./tempDir');
args.dir = './app';
args.dir = 'blah'; // set to true first
args.name = args._[0];
var protocolSchemes = [].concat(args.protocol || []);
@ -29,22 +31,24 @@ if (!validator.isURL(args.target)) {
process.exit(1);
}
// writes parameters for the app into a text file
// I'm not exactly sure how to pass these as an argument through code
var appArgs = {
name: args.name,
targetUrl: args.target
};
fs.writeFileSync(__dirname + '/app/targetUrl.txt', JSON.stringify(appArgs));
tempDir(args.name, args.target, function (error, appDir) {
packager(args, function done(err, appPaths) {
if (err) {
if (err.message) console.error(err.message);
else console.error(err, err.stack);
if (error) {
console.error(error);
process.exit(1);
} else {
args.dir = appDir;
packager(args, function done(err, appPaths) {
if (err) {
if (err.message) console.error(err.message);
else console.error(err, err.stack);
process.exit(1);
}
if (appPaths.length > 1) console.error('Wrote new apps to:\n' + appPaths.join('\n'));
else if (appPaths.length === 1) console.error('Wrote new app to', appPaths[0]);
});
}
if (appPaths.length > 1) console.error('Wrote new apps to:\n' + appPaths.join('\n'));
else if (appPaths.length === 1) console.error('Wrote new app to', appPaths[0]);
});

View File

@ -28,6 +28,7 @@
"rcedit": "^0.3.0",
"rimraf": "^2.3.2",
"run-series": "^1.1.1",
"temp": "^0.8.3",
"validator": "^3.40.1"
},
"devDependencies": {

46
tempDir.js Normal file
View File

@ -0,0 +1,46 @@
/**
* Created by JiaHao on 5/7/15.
*/
var fs = require('fs');
var temp = require('temp').track();
var ncp = require('ncp').ncp;
/**
* @callback tempDirCallback
* @param error
* @param tempDirPath
*/
/**
* Creates a temporary directory and copies the './app folder' inside, and adds a text file with the configuration
* for the single page app.
*
* @param {string} name
* @param {string} targetURL
* @param {tempDirCallback} callback
*/
module.exports = function (name, targetURL, callback) {
var tempDir = temp.path();
ncp('./app', tempDir, function (error) {
if (error) {
callback('Error creating temporary directory', null);
} else {
var appArgs = {
name: name,
targetUrl: targetURL
};
fs.writeFileSync(tempDir + '/targetUrl.txt', JSON.stringify(appArgs));
callback(error, tempDir);
}
});
};