0
我是新来的节点,我想在命令行中使用节点循环槽命令。命令是这样的:通过命令行窗口在节点中循环
node dist/main.js dist/index.html dynamic/
node dist/main.js dist/index.html dynamic page.html
node dist/main.js dist/index.html dynamic page2.html
我使用angular4普遍和重新呈现我的网页我必须把这些命令在命令提示符。如果我已经没有20页,而且还会更多,这不会成为问题。我的手变酸了嘿嘿..
我该怎么做?
谢谢!
的main.js文件
import 'zone.js/dist/zone-node';
import { renderModuleFactory } from '@angular/platform-server'
import { enableProdMode } from '@angular/core'
import { AppServerModuleNgFactory } from './src/app.server.module.ngfactory'
import * as fs from 'fs';
import * as path from 'path';
enableProdMode();
const args = process.argv.slice(2);
if (args.length != 3) {
process.stdout.write("Usage: node dist/main.js <document> <distDir> <url>\n");
process.exit();
}
const indexFileContent = fs.readFileSync(args[0], 'utf8');
renderModuleFactory(AppServerModuleNgFactory, {
document: indexFileContent,
url: args[2]
}).then(string => {
let destUrl = args[2];
if (destUrl == '/')
destUrl = 'index.html'
const targetDir = args[1] + '/' + destUrl;
targetDir.split('/').forEach((dir, index, splits) => {
if (index !== splits.length - 1) {
const parent = splits.slice(0, index).join('/');
const dirPath = path.resolve(parent, dir);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
}
});
fs.writeFileSync(targetDir, string);
console.log(targetDir);
});
这段代码是从博客:"Angular v4 Universal Demystified"
你想做什么/实现(太模糊) –
所以你正在建立这些网页...手动? - main.js做什么? - 你是否将这些论点转化为角度cli?我不完全确定你是否生成最终的html文件 –
是的,这基本上是我的问题,我该怎么做?我是node.js的新手。思考如何使用所有代码行来创建数组,但我不知道如何... –