From d38da5c715e6417595c31b2cca3d6feaa9abb449 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 10 Aug 2020 11:45:33 +0530 Subject: [PATCH] chore: prettify templates --- src/commands/basic/add.js | 30 +++++++++++++++++++++--------- src/commands/basic/init.js | 21 +++++++++++++-------- src/templates/vuex/store.js | 14 -------------- 3 files changed, 34 insertions(+), 31 deletions(-) delete mode 100644 src/templates/vuex/store.js diff --git a/src/commands/basic/add.js b/src/commands/basic/add.js index d6f916edf..999cad215 100644 --- a/src/commands/basic/add.js +++ b/src/commands/basic/add.js @@ -2,7 +2,6 @@ import chalk from 'chalk'; import fs from 'fs'; -import path from 'path'; import showBanner from 'node-banner'; import appData from '../../utils/projectConfig'; @@ -11,11 +10,6 @@ import dirOfChoice from '../../utils/directoryPrompt'; import exec from '../../utils/exec'; import inquirer from 'inquirer'; -const vuexStoreTemplate = fs.readFileSync( - path.resolve(__dirname, '..', '..', 'templates/vuex/store.js'), - 'utf8', -); - /** * Choose additional deps to install on the go * @@ -512,13 +506,31 @@ const addDeps = async (deps, { dev }) => { } else { // Configure vuex-store if (deps.includes('vuex')) { + // Content to be inserted + const vuexStoreTemplate = [ + `import Vue from "vue";`, + `import Vuex from "vuex";`, + '', + `Vue.use(Vuex);`, + '', + `export default new Vuex.Store({`, + `${' '.repeat(2)}state: {},`, + '', + `${' '.repeat(2)}getters: {},`, + '', + `${' '.repeat(2)}mutations: {},`, + '', + `${' '.repeat(2)}actions: {}`, + `});`, + '', + ]; const config = fs .readFileSync('./client/src/main.js', 'utf8') .toString() .split('\n'); // Creates a new store.js file within the client/src directory. - fs.writeFileSync('./client/src/store.js', vuexStoreTemplate); + fs.writeFileSync('./client/src/store.js', vuexStoreTemplate.join('\n')); // Fetch the index corresponding to the very first blank line const blankLineIndex = config.indexOf(config.find((line) => line === '')); @@ -550,8 +562,8 @@ const addDeps = async (deps, { dev }) => { // Import Vuetify and minified css towards the top of the config file [ - `import Vuetify from 'vuetify';`, - `import 'vuetify/dist/vuetify.min.css';`, + `import Vuetify from "vuetify";`, + `import "vuetify/dist/vuetify.min.css";`, ].forEach((item, i) => config.splice(i + 1, 0, item)); // Fetch the index after which the respective config should come up diff --git a/src/commands/basic/init.js b/src/commands/basic/init.js index 7b191e982..183336b39 100644 --- a/src/commands/basic/init.js +++ b/src/commands/basic/init.js @@ -152,15 +152,8 @@ const fetchTemplate = async (template) => { // Keep track whether dependencies are to be installed projectConfig.isConfigured = { client: false, - server: false, }; - // Update project specific config file - fs.writeFileSync( - `./${projectPathRelative}/.mevnrc`, - JSON.stringify(projectConfig, null, 2), - ); - // Show up a suitable prompt whether if the user requires a Full stack application (Express.js) const { requireServer } = await inquirer.prompt({ name: 'requireServer', @@ -176,6 +169,12 @@ const fetchTemplate = async (template) => { const source = path.join(__dirname, '..', '..', ...serverPath); const dest = path.resolve(projectPathRelative); + // Keep track whether dependencies are to be installed + projectConfig.isConfigured = { + client: false, + server: false, + }; + // Copy server template directory to the destination copyDirSync(source, dest); @@ -187,6 +186,12 @@ const fetchTemplate = async (template) => { fs.writeFileSync(`${renameToPath}/.gitignore`, 'node_modules'); } + // Update project specific config file + fs.writeFileSync( + `./${projectPathRelative}/.mevnrc`, + JSON.stringify(projectConfig, null, 2), + ); + // Show up initial instructions to the user showInstructions(); }; @@ -227,7 +232,7 @@ const initializeProject = async (appName) => { chalk.red.bold(`It seems the current directory isn't empty.`), ); console.log(); - process.exit(0); + process.exit(1); } } diff --git a/src/templates/vuex/store.js b/src/templates/vuex/store.js deleted file mode 100644 index 23ab9509b..000000000 --- a/src/templates/vuex/store.js +++ /dev/null @@ -1,14 +0,0 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; - -Vue.use(Vuex); - -export default new Vuex.Store({ - state: {}, - - getters: {}, - - mutations: {}, - - actions: {}, -});