2019-11-03 09:51:32 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var P = require('../plugins.js');
|
|
|
|
var args = process.argv.slice(3);
|
|
|
|
var cli = require('./lib/cli.js');
|
2019-11-19 05:55:29 +00:00
|
|
|
var Init = require('../lib/init.js');
|
2019-11-19 09:24:09 +00:00
|
|
|
var Greenlock = require('../');
|
2019-11-03 09:51:32 +00:00
|
|
|
|
|
|
|
var Flags = require('./lib/flags.js');
|
|
|
|
|
|
|
|
var flagOptions = Flags.flags();
|
|
|
|
var myFlags = {};
|
|
|
|
['maintainer-email', 'cluster', 'manager', 'manager-xxxx'].forEach(function(k) {
|
|
|
|
myFlags[k] = flagOptions[k];
|
|
|
|
});
|
|
|
|
|
|
|
|
cli.parse(myFlags);
|
|
|
|
cli.main(async function(argList, flags) {
|
2019-11-19 05:55:29 +00:00
|
|
|
var pkgRoot = process.cwd();
|
2019-11-03 09:51:32 +00:00
|
|
|
var manager = flags.manager;
|
|
|
|
|
|
|
|
if (['fs', 'cloud'].includes(manager)) {
|
2019-11-05 07:01:31 +00:00
|
|
|
manager = '@greenlock/manager';
|
|
|
|
}
|
|
|
|
if (['cloud'].includes(manager)) {
|
|
|
|
flags.managerOpts.cloud = true;
|
2019-11-03 09:51:32 +00:00
|
|
|
}
|
2019-11-05 07:01:31 +00:00
|
|
|
|
2019-11-03 09:51:32 +00:00
|
|
|
flags.manager = flags.managerOpts;
|
|
|
|
delete flags.managerOpts;
|
2019-11-19 05:55:29 +00:00
|
|
|
flags.manager.module = manager;
|
2019-11-03 09:51:32 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
P._loadSync(manager);
|
|
|
|
} catch (e) {
|
|
|
|
try {
|
|
|
|
P._installSync(manager);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(
|
|
|
|
'error:',
|
|
|
|
JSON.stringify(manager),
|
|
|
|
'could not be loaded, and could not be installed.'
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 09:24:09 +00:00
|
|
|
var greenlock = Greenlock.create({
|
2019-11-19 05:55:29 +00:00
|
|
|
packageRoot: pkgRoot,
|
|
|
|
manager: flags.manager,
|
|
|
|
maintainerEmail: flags.maintainerEmail,
|
|
|
|
_mustPackage: true
|
|
|
|
});
|
2019-11-19 09:24:09 +00:00
|
|
|
await greenlock.manager.defaults();
|
2019-11-19 05:55:29 +00:00
|
|
|
|
|
|
|
//writeGreenlockJs(pkgdir, flags);
|
2019-11-19 09:24:09 +00:00
|
|
|
writeServerJs(pkgRoot, flags);
|
|
|
|
writeAppJs(pkgRoot);
|
2019-11-03 09:51:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
rc._bin_mode = true;
|
|
|
|
var Greenlock = require('../');
|
|
|
|
// this is a copy, so it's safe to modify
|
|
|
|
var greenlock = Greenlock.create(rc);
|
|
|
|
var mconf = await greenlock.manager.defaults();
|
|
|
|
var flagOptions = Flags.flags(mconf, myOpts);
|
|
|
|
*/
|
|
|
|
}, args);
|
|
|
|
|
2019-11-19 05:55:29 +00:00
|
|
|
/*
|
2019-11-05 07:01:31 +00:00
|
|
|
function writeGreenlockJs(pkgdir, flags) {
|
|
|
|
var greenlockJs = 'greenlock.js';
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var tmpl = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'tmpl/greenlock.tmpl.js'),
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
fs.accessSync(path.join(pkgdir, greenlockJs));
|
|
|
|
console.warn("[skip] '%s' exists", greenlockJs);
|
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
// continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags.maintainerEmail) {
|
|
|
|
tmpl = tmpl.replace(
|
|
|
|
/pkg.author/g,
|
|
|
|
JSON.stringify(flags.maintainerEmail)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fs.writeFileSync(path.join(pkgdir, greenlockJs), tmpl);
|
|
|
|
console.info("created '%s'", greenlockJs);
|
|
|
|
}
|
2019-11-19 05:55:29 +00:00
|
|
|
*/
|
2019-11-05 07:01:31 +00:00
|
|
|
|
2019-11-03 09:51:32 +00:00
|
|
|
function writeServerJs(pkgdir, flags) {
|
|
|
|
var serverJs = 'server.js';
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2019-11-19 05:55:29 +00:00
|
|
|
var tmpl;
|
2019-11-03 09:51:32 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
fs.accessSync(path.join(pkgdir, serverJs));
|
2019-11-05 07:01:31 +00:00
|
|
|
console.warn("[skip] '%s' exists", serverJs);
|
|
|
|
return;
|
2019-11-03 09:51:32 +00:00
|
|
|
} catch (e) {
|
|
|
|
// continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags.cluster) {
|
2019-11-19 05:55:29 +00:00
|
|
|
tmpl = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'tmpl/cluster.tmpl.js'),
|
|
|
|
'utf8'
|
|
|
|
);
|
2019-11-05 10:18:48 +00:00
|
|
|
tmpl = tmpl.replace(/cluster: false/g, 'cluster: true');
|
2019-11-19 05:55:29 +00:00
|
|
|
} else {
|
|
|
|
tmpl = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'tmpl/server.tmpl.js'),
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags.maintainerEmail) {
|
|
|
|
tmpl = tmpl
|
|
|
|
.replace(/pkg.author/g, JSON.stringify(flags.maintainerEmail))
|
|
|
|
.replace(/\/\/maintainerEmail/g, 'maintainerEmail');
|
2019-11-03 09:51:32 +00:00
|
|
|
}
|
2019-11-05 10:18:48 +00:00
|
|
|
|
2019-11-03 09:51:32 +00:00
|
|
|
fs.writeFileSync(path.join(pkgdir, serverJs), tmpl);
|
2019-11-05 07:01:31 +00:00
|
|
|
console.info("created '%s'", serverJs);
|
2019-11-03 09:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function writeAppJs(pkgdir) {
|
|
|
|
var appJs = 'app.js';
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var tmpl = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'tmpl/app.tmpl.js'),
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
fs.accessSync(path.join(pkgdir, appJs));
|
2019-11-05 07:01:31 +00:00
|
|
|
console.warn("[skip] '%s' exists", appJs);
|
|
|
|
return;
|
2019-11-03 09:51:32 +00:00
|
|
|
} catch (e) {
|
2019-11-05 07:01:31 +00:00
|
|
|
fs.writeFileSync(path.join(pkgdir, appJs), tmpl);
|
|
|
|
console.info("created '%s'", appJs);
|
2019-11-03 09:51:32 +00:00
|
|
|
}
|
|
|
|
}
|