2016-08-10 13:35:40 -07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
var templates = {
|
2016-10-21 09:01:29 -07:00
|
|
|
'package-template.json': '/',
|
2016-10-18 16:33:42 -07:00
|
|
|
'index.html': 'www/',
|
2016-10-05 21:18:29 -07:00
|
|
|
'config-template.xml': '/',
|
|
|
|
'ionic.config.json': '/',
|
2016-08-19 13:47:37 -07:00
|
|
|
'.desktop': 'webkitbuilds/',
|
|
|
|
'setup-win.iss': 'webkitbuilds/',
|
2016-10-18 07:19:21 -07:00
|
|
|
'build-macos.sh': 'webkitbuilds/',
|
2016-12-28 11:49:42 -08:00
|
|
|
'manifest.json': 'chrome-app/',
|
2016-08-10 13:35:40 -07:00
|
|
|
// 'bower.json': '/',
|
|
|
|
};
|
|
|
|
var configDir = process.argv[2] || 'copay';
|
2016-10-17 17:07:41 -07:00
|
|
|
var JSONheader = ' { ' + "\n" + ' "//":"Changes to this file will be overwritten",' + "\n" + ' "//":" Modify it in the app-template directory", ' + "\n";
|
2016-08-10 13:35:40 -07:00
|
|
|
|
|
|
|
var MakefileHeader = "# PLEASE! Do not edit this file directly \n# Modify it at app-template/\n";
|
|
|
|
|
|
|
|
var fs = require('fs-extra');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var configBlob = fs.readFileSync(configDir + '/appConfig.json', 'utf8');
|
|
|
|
var config = JSON.parse(configBlob, 'utf8');
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
console.log('Applying ' + config.nameCase + ' template');
|
|
|
|
|
|
|
|
Object.keys(templates).forEach(function(k) {
|
|
|
|
var targetDir = templates[k];
|
|
|
|
console.log(' # ' + k + ' => ' + targetDir);
|
|
|
|
|
|
|
|
var content = fs.readFileSync(k, 'utf8');
|
|
|
|
|
|
|
|
|
|
|
|
if (k.indexOf('.json') > 0) {
|
|
|
|
content = content.replace('{', JSONheader);
|
|
|
|
|
|
|
|
} else if (k.indexOf('Makefile') >= 0) {
|
|
|
|
content = MakefileHeader + content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(config).forEach(function(k) {
|
|
|
|
if (k.indexOf('_') == 0) return;
|
|
|
|
|
|
|
|
var r = new RegExp("\\*" + k.toUpperCase() + "\\*", "g");
|
|
|
|
content = content.replace(r, config[k]);
|
|
|
|
});
|
|
|
|
|
|
|
|
var r = new RegExp("\\*[A-Z]{3,30}\\*", "g");
|
|
|
|
var s = content.match(r);
|
|
|
|
if (s) {
|
|
|
|
console.log('UNKNOWN VARIABLE', s);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2017-03-21 12:40:27 -07:00
|
|
|
if (k === 'config-template.xml') {
|
2016-10-05 21:18:29 -07:00
|
|
|
k = 'config.xml';
|
2016-10-21 09:01:29 -07:00
|
|
|
} else if (k === 'package-template.json') {
|
|
|
|
k = 'package.json';
|
2016-10-05 21:18:29 -07:00
|
|
|
}
|
2016-10-18 23:29:42 -07:00
|
|
|
|
2017-03-21 12:40:27 -07:00
|
|
|
if (!fs.existsSync('../' + targetDir)) {
|
2016-10-18 23:29:42 -07:00
|
|
|
fs.mkdirSync('../' + targetDir);
|
|
|
|
}
|
2016-08-10 13:35:40 -07:00
|
|
|
fs.writeFileSync('../' + targetDir + k, content, 'utf8');
|
|
|
|
});
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
console.log('Copying ' + configDir + '/appConfig.json' + ' to root');
|
|
|
|
configBlob = configBlob.replace('{', JSONheader);
|
|
|
|
fs.writeFileSync('../appConfig.json', configBlob, 'utf8');
|
|
|
|
|
2016-09-01 12:51:29 -07:00
|
|
|
////////////////
|
|
|
|
var externalServices;
|
|
|
|
try {
|
2016-10-21 10:17:58 -07:00
|
|
|
var confName = configDir.toUpperCase();
|
2016-10-22 07:56:00 -07:00
|
|
|
var externalServicesConf = confName + '_EXTERNAL_SERVICES_CONFIG_LOCATION';
|
2016-10-21 10:17:58 -07:00
|
|
|
console.log('Looking for ' + externalServicesConf + '...');
|
2017-03-21 12:40:27 -07:00
|
|
|
if (typeof process.env[externalServicesConf] !== 'undefined') {
|
2016-10-21 10:17:58 -07:00
|
|
|
var location = process.env[externalServicesConf]
|
2017-03-21 12:40:27 -07:00
|
|
|
if (location.charAt(0) === '~') {
|
2016-10-21 09:44:26 -07:00
|
|
|
location = location.replace(/^\~/, process.env.HOME || process.env.USERPROFILE);
|
2016-10-21 09:30:02 -07:00
|
|
|
}
|
|
|
|
console.log('Found at: ' + location);
|
2016-10-21 09:01:29 -07:00
|
|
|
console.log('Copying ' + location + ' to root');
|
|
|
|
externalServices = fs.readFileSync(location, 'utf8');
|
2016-10-22 07:56:00 -07:00
|
|
|
} else {
|
|
|
|
throw externalServicesConf + ' environment variable not set.';
|
2016-10-21 09:01:29 -07:00
|
|
|
}
|
2017-03-21 12:40:27 -07:00
|
|
|
} catch (err) {
|
2016-10-22 07:56:00 -07:00
|
|
|
console.log(err);
|
2016-09-01 12:51:29 -07:00
|
|
|
externalServices = '{}';
|
|
|
|
console.log('External services not configured');
|
|
|
|
}
|
|
|
|
fs.writeFileSync('../externalServices.json', externalServices, 'utf8');
|
2016-08-10 13:35:40 -07:00
|
|
|
|
2017-03-22 06:20:26 -07:00
|
|
|
function copyDir(from, to) {
|
2017-02-23 13:46:41 -08:00
|
|
|
console.log('Copying dir ' + from + ' to ' + to);
|
|
|
|
if (fs.existsSync(to)) fs.removeSync(to); // remove previous app directory
|
|
|
|
if (!fs.existsSync(from)) return; // nothing to do
|
2017-03-22 06:20:26 -07:00
|
|
|
fs.copySync(from, to);
|
2016-08-10 13:35:40 -07:00
|
|
|
}
|
|
|
|
|
2017-03-13 12:50:08 -07:00
|
|
|
// Push Notification
|
|
|
|
fs.copySync(configDir + '/GoogleService-Info.plist', '../GoogleService-Info.plist');
|
|
|
|
fs.copySync(configDir + '/google-services.json', '../google-services.json');
|
2016-08-10 13:35:40 -07:00
|
|
|
|
2017-03-22 06:20:26 -07:00
|
|
|
copyDir(configDir + '/img', '../www/img/app');
|
|
|
|
copyDir(configDir + '/sass', '../src/sass/app');
|
|
|
|
console.log("apply.js finished. \n\n");
|