vip-server-renderer
Version:
Atom server renderer(PHP)
74 lines (53 loc) • 1.87 kB
JavaScript
/**
* @file copy php runtime
* @author cxtom (cxtom2008@gmail.com)
*/
var fs = require('fs-extra');
var path = require('path');
var relative = require('is-relative');
var lib = require('./index');
var PHP_RUNTIME_VERSION = lib.PHP_RUNTIME_VERSION;
function addVersion(filePath) {
var files = fs.readdirSync(filePath);
files.forEach(function (file) {
var curPath = path.resolve(filePath, file);
var stat = fs.statSync(curPath);
if (stat.isFile() && path.extname(curPath) === '.php') {
var content = fs.readFileSync(curPath, 'utf8');
content = content.replace(/runtime_default/g, 'runtime_' + PHP_RUNTIME_VERSION);
fs.outputFileSync(curPath, content);
}
else if (stat.isDirectory()) {
addVersion(curPath);
}
});
}
function run() {
var output = process.argv[2] || process.argv[1];
if (!output) {
console.log('output path is necessary!');
process.exit(1);
}
var outputpath = relative(output) ? path.join(process.cwd(), output) : output;
var runtimePath = path.resolve(__dirname, '../../src/platforms/vip/server');
var libPath = path.resolve(outputpath, 'lib', 'runtime_' + PHP_RUNTIME_VERSION);
// var defaultLibPath = path.resolve(outputpath, 'lib/runtime_default');
var runtimeLibPath = path.resolve(runtimePath, 'lib/runtime_default');
fs.ensureDirSync(outputpath);
var files = fs.readdirSync(runtimePath);
// 拷贝全局 php 文件
files.forEach(function (file) {
var curPath = path.resolve(runtimePath, file);
if (fs.statSync(curPath).isFile() && path.extname(curPath) === '.php') {
fs.copySync(curPath, path.resolve(outputpath, file));
}
});
// // 不存在默认的,就考一下
// if (!fs.pathExistsSync(defaultLibPath)) {
// fs.copySync(runtimeLibPath, defaultLibPath);
// }
fs.copySync(runtimeLibPath, libPath);
addVersion(libPath);
}
run();
module.exports = run;