UNPKG

statigen

Version:

A static site generator that supports html, ejs, and markdown source files

44 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InitCommand = void 0; const fsExtra = require("fs-extra"); const path = require("path"); const isEmptyDir = require("empty-dir"); const childProcess = require("child_process"); const util_1 = require("./util"); class InitCommand { run(options) { let outDir; if (options.path) { outDir = path.resolve(process.cwd(), options.path); } else { outDir = process.cwd(); } if (fsExtra.pathExistsSync(outDir) && !isEmptyDir.sync(outDir)) { throw new Error(`Directory is not empty: ${outDir}`); } //copy the files to `src` fsExtra.copySync(path.resolve(__dirname, '..', 'templates', 'default'), path.resolve(outDir, 'src')); //create the package.json fsExtra.outputFileSync(path.resolve(outDir, 'package.json'), JSON.stringify({ name: 'statigen-site', version: '0.1.0', description: 'A static website built by statigen', scripts: { build: 'statigen', watch: 'statigen --watch' }, dependencies: { statigen: `^${(0, util_1.getLatestVersion)('statigen')}` } }, null, 4)); //run npm install childProcess.spawnSync(process.platform.startsWith('win') ? 'npm.cmd' : 'npm', ['install'], { cwd: outDir, stdio: 'inherit' }); } } exports.InitCommand = InitCommand; //# sourceMappingURL=InitCommand.js.map