pandora
Version:
A powerful and lightweight application manager for Node.js applications powered by TypeScript.
68 lines (49 loc) • 1.27 kB
JavaScript
;
const path = require('path');
const fs = require('fs');
exports.preCheck = (targetPath, appName) => {
let appRoot = process.cwd();
let pkgPath = path.join(appRoot, 'package.json');
// start path must be process.cwd()
let procFilePath = path.join(appRoot, 'procfile.js');
if(fs.existsSync(pkgPath) && !fs.existsSync(procFilePath)) {
const template = `
'use strict';
module.exports = (pandora) => {
/**
* default is fork mode
*/
pandora
.fork('${appName}', '${targetPath}');
/**
* you can use cluster mode to start application
*/
// pandora
// .cluster('./cluster.js');
/**
* you can create another process here
*/
// pandora
// .process('background')
// .argv(['--expose-gc']);
/**
* more features please visit our document.
* https://github.com/midwayjs/pandora/
*/
};`;
fs.writeFileSync(procFilePath, template);
console.log(`pandora: procfile.js was auto generated at ${procFilePath}`);
}
};
exports.dirnameUntilPkgJson = function (targetPath) {
let cur = targetPath;
while (true) {
if(fs.existsSync(path.join(cur, 'package.json'))) {
return cur;
}
cur = path.dirname(cur);
if(cur === '/') {
return null;
}
}
};