UNPKG

@lightweightform/kotlin-cli

Version:

LF Kotlin CLI Plugin

83 lines (68 loc) 1.83 kB
#!/usr/bin/env node 'use strict'; const {execSync} = require('child_process'); const fs = require('fs'); //Get project name const projectName = process.argv[2]; //Create schema.json generateJson(); //Generate MVN base project shLog( `lf-kotlin generate -g pt.at.${projectName} schema.json ${projectName} ${projectName}`, ); //Generate Angular project with the Project Name shLog( `ng new ${projectName}-app --directory=./${projectName}/${projectName}-app --style=scss --routing=true --skip-git`, ); transferJsonLocation(projectName); //Adds LF-AT-THEME to the Angular module shLog( `cd ${projectName} && cd ${projectName}-app && ng add lf-at-theme@4.0.0-beta.9`, ); //Initialize git on the root of the project shLog(`git init ${projectName}`); console.log('SETUP FINISHED'); // Utility functions =========================================================== /** * Creates schema.json to generate Maven project. */ function generateJson() { fs.writeFileSync( `./schema.json`, `{ "type": "record", "fieldsSchemas": {}, "initialState": { "GlobalValidationIssues": {} } }`, ); } /** * Deletes schema.json from the current directory and adds it to Angular Project */ function transferJsonLocation(projName) { fs.copyFileSync('schema.json', `${projName}/${projName}-app/schema.json`); fs.unlink('./schema.json', err => { if (err) throw err; }); } /** * Execute a command and return its output. * @param {string} cmd Command to execute. * @returns {string} Command output. */ function sh(cmd) { return execSync(cmd) .toString() .trimEnd(); } /** * Log and execute a command, also logging its output. * @param {string} cmd Command to log and execute. * @returns {void} */ function shLog(cmd) { console.log(`$ ${cmd}`.trimEnd()); console.log(`${sh(cmd)}\n`); }