add vue template
This commit is contained in:
parent
3bd332f52a
commit
e6c447a4b6
10
README.md
10
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
|
||||
```
|
||||
|
1
snippets/node/template/.gitignore
vendored
1
snippets/node/template/.gitignore
vendored
@ -1 +1,2 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
|
82
snippets/vue/index.js
Normal file
82
snippets/vue/index.js
Normal 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 };
|
2
snippets/vue/template/.browserslistrc
Normal file
2
snippets/vue/template/.browserslistrc
Normal file
@ -0,0 +1,2 @@
|
||||
> 1%
|
||||
last 2 versions
|
1
snippets/vue/template/babel.config.js
Normal file
1
snippets/vue/template/babel.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = { presets: [ '@vue/cli-plugin-babel/preset' ] };
|
17
snippets/vue/template/public/index.html
Normal file
17
snippets/vue/template/public/index.html
Normal 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>
|
20
snippets/vue/template/src/App.vue
Normal file
20
snippets/vue/template/src/App.vue
Normal 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>
|
14
snippets/vue/template/src/components/comp.vue
Normal file
14
snippets/vue/template/src/components/comp.vue
Normal file
@ -0,0 +1,14 @@
|
||||
<template>
|
||||
<div />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'Comp',
|
||||
props: {},
|
||||
data: () => ({ })
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
9
snippets/vue/template/src/main.js
Normal file
9
snippets/vue/template/src/main.js
Normal 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');
|
Loading…
x
Reference in New Issue
Block a user