add vue template

This commit is contained in:
Timo Hocker 2020-01-16 21:11:59 +01:00
parent 3bd332f52a
commit e6c447a4b6
9 changed files with 155 additions and 1 deletions

View File

@ -43,10 +43,18 @@ snippeteer node [name]
### Jenkins ### Jenkins
Adds files necessary for jenkins Adds files necessary for jenkins
optionally with a js script for npm modules by adding 'node' as argument optionally with a js script for npm modules by adding 'node' as argument
```sh ```sh
snippeteer jenkins [node] snippeteer jenkins [node]
``` ```
### Vue
Adds files, dependencies and scripts for vue to a nodejs project
```sh
snippeteer vue
```

View File

@ -1 +1,2 @@
/node_modules/ /node_modules/
/dist/

82
snippets/vue/index.js Normal file
View File

@ -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 };

View File

@ -0,0 +1,2 @@
> 1%
last 2 versions

View File

@ -0,0 +1 @@
module.exports = { presets: [ '@vue/cli-plugin-babel/preset' ] };

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>html</title>
</head>
<body>
<noscript>
<strong>We're sorry but html doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

View File

@ -0,0 +1,20 @@
<template>
<div id="app">
<comp />
</div>
</template>
<script>
import comp from './components/comp.vue';
export default {
name: 'App',
components: { comp }
};
</script>
<style>
.hidden {
display: none;
}
</style>

View File

@ -0,0 +1,14 @@
<template>
<div />
</template>
<script>
export default {
name: 'Comp',
props: {},
data: () => ({ })
};
</script>
<style scoped>
</style>

View File

@ -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');