зеркало из https://github.com/mozilla/Spoke.git
Copy default project files.
This commit is contained in:
Родитель
1598a5d69e
Коммит
51ecb90c19
58
bin/spoke
58
bin/spoke
|
@ -2,6 +2,9 @@
|
|||
const commander = require("commander");
|
||||
const opn = require("opn");
|
||||
const pkg = require("../package.json");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const readline = require("readline");
|
||||
|
||||
commander.version(pkg.version);
|
||||
|
||||
|
@ -23,22 +26,43 @@ if (process.env.NODE_ENV === "development") {
|
|||
}
|
||||
|
||||
const projectPath = commander.args.length > 0 ? commander.args[0] : process.cwd();
|
||||
const projectFilePath = path.join(projectPath, "spoke-project.json");
|
||||
|
||||
console.log(`Starting ${pkg.name} server...`);
|
||||
console.log(`Serving project directory: ${projectPath}`);
|
||||
|
||||
startServer({
|
||||
projectPath,
|
||||
port: commander.port,
|
||||
https: commander.https
|
||||
})
|
||||
.then(() => {
|
||||
console.log(`Server listening on port ${commander.port}`);
|
||||
|
||||
if (commander.open) {
|
||||
opn(`http://localhost:${commander.port}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
if (!fs.existsSync(projectFilePath)) {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
rl.question("Creating new Spoke project. Would you like to add a the default assets? (y/n)", answer => {
|
||||
const copyDefaultAssets = answer.toLowerCase() === "y";
|
||||
|
||||
rl.close();
|
||||
|
||||
run(copyDefaultAssets);
|
||||
});
|
||||
} else {
|
||||
run(false);
|
||||
}
|
||||
|
||||
function run(copyDefaultAssets) {
|
||||
console.log(`Starting ${pkg.name} server...`);
|
||||
console.log(`Serving project directory: ${projectPath}`);
|
||||
|
||||
startServer({
|
||||
projectPath,
|
||||
copyDefaultAssets,
|
||||
port: commander.port,
|
||||
https: commander.https
|
||||
})
|
||||
.then(() => {
|
||||
console.log(`Server listening on port ${commander.port}`);
|
||||
|
||||
if (commander.open) {
|
||||
opn(`http://localhost:${commander.port}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -10,6 +10,8 @@
|
|||
"bin/",
|
||||
"lib/",
|
||||
"public/",
|
||||
"example/ArchitectureKit",
|
||||
"example/Parthenon",
|
||||
"LICENSE"
|
||||
],
|
||||
"repository": {
|
||||
|
|
|
@ -78,6 +78,25 @@ export default async function startServer(options) {
|
|||
const projectPath = path.resolve(opts.projectPath);
|
||||
const projectDirName = path.basename(projectPath);
|
||||
|
||||
await fs.ensureDir(projectPath);
|
||||
|
||||
const projectFilePath = path.join(projectPath, "spoke-project.json");
|
||||
|
||||
if (!fs.existsSync(projectFilePath)) {
|
||||
await fs.writeJSON(projectFilePath, {});
|
||||
}
|
||||
|
||||
if (opts.copyDefaultAssets) {
|
||||
const exampleDirPath = path.join(__dirname, "..", "..", "example");
|
||||
const defaultAssetDirectories = ["ArchitectureKit", "Parthenon"];
|
||||
|
||||
for (const assetDir of defaultAssetDirectories) {
|
||||
const src = path.join(exampleDirPath, assetDir);
|
||||
const dest = path.join(projectPath, assetDir);
|
||||
await fs.copy(src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
const app = new Koa();
|
||||
|
||||
let server;
|
||||
|
|
Загрузка…
Ссылка в новой задаче