Skip to content

Commit

Permalink
chore: prettify templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Aug 10, 2020
1 parent e578ba5 commit d38da5c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
30 changes: 21 additions & 9 deletions src/commands/basic/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
*
Expand Down Expand Up @@ -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 === ''));
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions src/commands/basic/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);

Expand All @@ -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();
};
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 0 additions & 14 deletions src/templates/vuex/store.js

This file was deleted.

0 comments on commit d38da5c

Please sign in to comment.