dicebox
Version:
build tool for typescript based RPG Maker MV plugins
69 lines • 2.91 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("fs");
const prompts = require("prompts");
const kebabCase = require("lodash.kebabcase");
const shellJs = require("shelljs");
const ejs = require("ejs");
function init() {
return __awaiter(this, void 0, void 0, function* () {
const initialProjectSettings = yield askForInitialProjectSettings();
const boilerplateDir = path.join(__dirname, '..', '..', 'boilerplate');
shellJs.cp('-r', `${boilerplateDir}/**/*`, '.');
const ejsFiles = shellJs.ls('./**/*.ejs');
ejsFiles.forEach(ejsFile => {
const outputFilename = ejsFile.split('.').slice(0, -1).join('.');
const renderedContent = ejs.render(shellJs.cat(ejsFile), initialProjectSettings);
fs.writeFileSync(outputFilename, renderedContent);
shellJs.rm(ejsFile);
});
shellJs.exec('npm install');
});
}
exports.init = init;
const askForInitialProjectSettings = () => __awaiter(void 0, void 0, void 0, function* () {
const abort = () => {
console.log('aborted...'); // tslint:disable-line
process.exit();
};
const { projectName } = yield prompts({
message: 'Plugin Display Name (can include spaces)',
type: 'text',
name: 'projectName',
}, { onCancel: abort });
const projectNameKebabCase = kebabCase(projectName);
const { pluginFilename } = yield prompts({
message: 'Plugin File Name',
type: 'text',
name: 'pluginFilename',
validate: n => /^[a-zA-Z0-9]+$/.test(n) || 'Filename must be PascalCase, e.g.: MyPlugin'
}, { onCancel: abort });
const { projectAuthor } = yield prompts({
message: 'Author Name',
type: 'text',
name: 'projectAuthor'
}, { onCancel: abort });
const { pluginDescription } = yield prompts({
message: 'Plugin Description',
type: 'text',
name: 'pluginDescription'
}, { onCancel: abort });
return {
projectName,
projectNameKebabCase,
pluginFilename,
projectAuthor,
pluginDescription
};
});
//# sourceMappingURL=init.js.map