diff --git a/README.md b/README.md index c47d01a..fbb68d3 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,18 @@ snippeteer node [name] ### Jenkins -Adds files necessary for jenkins +Adds files necessary for jenkins optionally with a js script for npm modules by adding 'node' as argument ```sh snippeteer jenkins [node] ``` + +### Vue + +Adds files, dependencies and scripts for vue to a nodejs project + +```sh +snippeteer vue +``` diff --git a/snippets/node/template/.gitignore b/snippets/node/template/.gitignore index 2ccbe46..b0a5c34 100644 --- a/snippets/node/template/.gitignore +++ b/snippets/node/template/.gitignore @@ -1 +1,2 @@ /node_modules/ +/dist/ diff --git a/snippets/vue/index.js b/snippets/vue/index.js new file mode 100644 index 0000000..562bce8 --- /dev/null +++ b/snippets/vue/index.js @@ -0,0 +1,82 @@ +/* eslint-disable no-sync */ +/* eslint-disable no-console */ + +const fs = require ('fs-extra'); +const path = require ('path'); +const child_process = require ('child_process'); + +/** + * copies the full template to a new folder named after arg[0] + * + * @param {string} folder folder to run in + * @param {Array} args function arguments + */ +async function run (folder, args) { + const snip_folder = path.join (folder, ...args); + const template = path.join (__dirname, 'template'); + + for (const f of fs.readdirSync (template)) + fs.copy ( + path.join (template, f), + path.join (snip_folder, f), + { filter: (src, dest) => !fs.existsSync (dest) } + ); + + const devdeps = [ + 'babel-eslint', + 'vue-template-compiler', + '@vue/cli-plugin-babel', + '@vue/cli-plugin-eslint', + '@vue/cli-service' + ]; + const deps = [ + 'core-js', + 'vue' + ]; + + child_process.execSync ( + `npm i --save ${deps.join (' ')} && npm i --save-dev ${devdeps.join (' ')} + `, + { cwd: snip_folder, stdio: 'inherit' } + ); + + const package_json = JSON.parse ( + await fs.readFile (path.join (snip_folder, 'package.json'), 'utf-8') + ); + + package_json.scripts.serve = 'vue-cli-service serve'; + package_json.scripts.build = 'vue-cli-service build'; + + await fs.writeFile ( + path.join (snip_folder, 'package.json'), + JSON.stringify (package_json, null, 2) + ); +} + +/** + * checks if the arguments meet the requirements + * + * @param {string} folder folder to run in + * @returns {boolean} true if arguments match requirements + */ +function assert (folder) { + const tests = [ + { + f: () => (typeof folder === 'string'), + reason: 'cwd is not a folder (internal error)' + }, + { + f: () => (fs.existsSync (folder)), + reason: 'cwd does not exist (internal error)' + } + ]; + for (const test of tests) + if (!test.f ()) { + console.log (test.reason); + return false; + } + + return true; +} + +module.exports = { run, assert }; diff --git a/snippets/vue/template/.browserslistrc b/snippets/vue/template/.browserslistrc new file mode 100644 index 0000000..d6471a3 --- /dev/null +++ b/snippets/vue/template/.browserslistrc @@ -0,0 +1,2 @@ +> 1% +last 2 versions diff --git a/snippets/vue/template/babel.config.js b/snippets/vue/template/babel.config.js new file mode 100644 index 0000000..81195ed --- /dev/null +++ b/snippets/vue/template/babel.config.js @@ -0,0 +1 @@ +module.exports = { presets: [ '@vue/cli-plugin-babel/preset' ] }; diff --git a/snippets/vue/template/public/index.html b/snippets/vue/template/public/index.html new file mode 100644 index 0000000..3863951 --- /dev/null +++ b/snippets/vue/template/public/index.html @@ -0,0 +1,17 @@ + + + + + + + + html + + + +
+ + + diff --git a/snippets/vue/template/src/App.vue b/snippets/vue/template/src/App.vue new file mode 100644 index 0000000..f7aed77 --- /dev/null +++ b/snippets/vue/template/src/App.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/snippets/vue/template/src/components/comp.vue b/snippets/vue/template/src/components/comp.vue new file mode 100644 index 0000000..ccb0d3f --- /dev/null +++ b/snippets/vue/template/src/components/comp.vue @@ -0,0 +1,14 @@ + + + + + diff --git a/snippets/vue/template/src/main.js b/snippets/vue/template/src/main.js new file mode 100644 index 0000000..cad1bb1 --- /dev/null +++ b/snippets/vue/template/src/main.js @@ -0,0 +1,9 @@ +// @ts-nocheck +/* eslint-disable */ +import Vue from 'vue'; +import App from './App.vue'; + +Vue.config.productionTip = false; + +new Vue ({ render: (h) => h (App) }) + .$mount ('#app');