diff --git a/meta.js b/meta.js new file mode 100644 index 0000000..524eb7f --- /dev/null +++ b/meta.js @@ -0,0 +1,39 @@ +module.exports = { + prompts: { + name: { + type: 'string', + required: true, + message: 'Plugin name' + }, + description: { + type: 'string', + required: false, + message: 'Plugin description', + default: 'A Vue.js Plugin' + }, + author: { + type: 'string', + message: 'Author' + }, + githubAccount: { + type: 'string', + required: false, + message: 'GitHub Account', + default: '' + } + }, + helpers: { + nowYear: function () { + return new Date().getFullYear() + }, + authorFullNameFrom: function (author) { + const startPosition = author.indexOf('<') + return author.slice(0, startPosition - 1) + }, + authorEmailFrom: function (author) { + const startPosition = author.indexOf('<') + const endPosition = author.indexOf('>') + return author.slice(startPosition + 1, endPosition) + } + } +} diff --git a/template/.eslintrc b/template/.eslintrc new file mode 100644 index 0000000..da6830b --- /dev/null +++ b/template/.eslintrc @@ -0,0 +1,10 @@ +{ + "globals": { + "process": true + }, + "extends": "vue", + "rules": { + "no-multiple-empty-lines": [2, {"max": 2}], + "no-console": 0 + } +} diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 0000000..ef3312f --- /dev/null +++ b/template/.gitignore @@ -0,0 +1,7 @@ +lib +coverage +node_modules +.DS_Store +*.log +*.swp +*~ diff --git a/template/CHANGELOG.md b/template/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/template/LICENSE b/template/LICENSE new file mode 100644 index 0000000..ae80253 --- /dev/null +++ b/template/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) {{ nowYear }} {{ authorFullNameFrom author }} + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/template/README.md b/template/README.md new file mode 100644 index 0000000..f3250e3 --- /dev/null +++ b/template/README.md @@ -0,0 +1,29 @@ +# {{ name }} + +{{ description }} + + +## Build Setup + + # install dependencies + npm install + + # serve with hot reload at localhost:8080 + npm run dev + + # lint source codes + npm run lint + + # build for production with minification + npm run build + + # run unit tests + npm run unit + + # run all tests + npm test + + +## License + +[MIT](http://opensource.org/licenses/MIT) diff --git a/template/config/.eslintrc b/template/config/.eslintrc new file mode 100644 index 0000000..da6830b --- /dev/null +++ b/template/config/.eslintrc @@ -0,0 +1,10 @@ +{ + "globals": { + "process": true + }, + "extends": "vue", + "rules": { + "no-multiple-empty-lines": [2, {"max": 2}], + "no-console": 0 + } +} diff --git a/template/config/banner.js b/template/config/banner.js new file mode 100644 index 0000000..02c3cdd --- /dev/null +++ b/template/config/banner.js @@ -0,0 +1,9 @@ +var pack = require('../package.json') +var version = process.env.VERSION || pack.version + +module.exports = + '/*!\n' + + ' * ' + pack.name + ' v' + version + '\n' + + ' * (c) ' + new Date().getFullYear() + ' ' + pack.author.name + '\n' + + ' * Released under the ' + pack.license + ' License.\n' + + ' */' diff --git a/template/config/build.js b/template/config/build.js new file mode 100644 index 0000000..2c3b9c2 --- /dev/null +++ b/template/config/build.js @@ -0,0 +1,122 @@ +var fs = require('fs') +var zlib = require('zlib') +var rollup = require('rollup') +var uglify = require('uglify-js') +var babel = require('rollup-plugin-babel') +var replace = require('rollup-plugin-replace') +var pack = require('../package.json') +var banner = require('./banner') + +// update main file +var main = fs + .readFileSync('src/index.js', 'utf-8') + .replace(/plugin\.version = '[\d\.]+'/, "plugin.version = '" + pack.version + "'") +fs.writeFileSync('src/index.js', main) + +// CommonJS build. +// this is used as the "main" field in package.json +// and used by bundlers like Webpack and Browserify. +rollup.rollup({ + entry: 'src/index.js', + plugins: [ + babel({ + presets: ['es2015-rollup'] + }) + ] +}) +.then(function (bundle) { + return write('dist/' + pack.name + '.common.js', bundle.generate({ + format: 'cjs', + banner: banner + }).code) +}) +// Standalone Dev Build +.then(function () { + return rollup.rollup({ + entry: 'src/index.js', + plugins: [ + replace({ + 'process.env.NODE_ENV': "'development'" + }), + babel({ + presets: ['es2015-rollup'] + }) + ] + }) + .then(function (bundle) { + return write('dist/' + pack.name + '.js', bundle.generate({ + format: 'umd', + banner: banner, + moduleName: classify(pack.name) + }).code) + }) +}) +.then(function () { + // Standalone Production Build + return rollup.rollup({ + entry: 'src/index.js', + plugins: [ + replace({ + 'process.env.NODE_ENV': "'production'" + }), + babel({ + presets: ['es2015-rollup'] + }) + ] + }) + .then(function (bundle) { + var code = bundle.generate({ + format: 'umd', + moduleName: classify(pack.name) + }).code + var minified = banner + '\n' + uglify.minify(code, { + fromString: true + }).code + return write('dist/' + pack.name + '.min.js', minified) + }) + .then(zip) +}) +.catch(logError) + +function toUpper (_, c) { + return c ? c.toUpperCase() : '' +} + +const classifyRE = /(?:^|[-_\/])(\w)/g +function classify (str) { + return str.replace(classifyRE, toUpper) +} + +function write (dest, code) { + return new Promise(function (resolve, reject) { + fs.writeFile(dest, code, function (err) { + if (err) return reject(err) + console.log(blue(dest) + ' ' + getSize(code)) + resolve() + }) + }) +} + +function zip () { + return new Promise(function (resolve, reject) { + fs.readFile('dist/' + pack.name + '.min.js', function (err, buf) { + if (err) return reject(err) + zlib.gzip(buf, function (err, buf) { + if (err) return reject(err) + write('dist/' + pack.name + '.min.js.gz', buf).then(resolve) + }) + }) + }) +} + +function getSize (code) { + return (code.length / 1024).toFixed(2) + 'kb' +} + +function logError (e) { + console.log(e) +} + +function blue (str) { + return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m' +} diff --git a/template/config/karma.conf.js b/template/config/karma.conf.js new file mode 100644 index 0000000..7be93d6 --- /dev/null +++ b/template/config/karma.conf.js @@ -0,0 +1,94 @@ +// Karma configuration +// Generated on Tue Sep 08 2015 19:27:24 GMT+0900 (JST) + +module.exports = function (config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha'], + + // list of files / patterns to load in the browser + files: [ + '../test/index.js' + ], + + // list of files to exclude + exclude: [ + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + '../test/index.js': ['webpack'] + }, + + webpack: { + devtool: 'source-map', + module: { + loaders: [{ + test: /\.js$/, + exclude: /node_modules|vue\/dist/, + loader: 'babel', + query: { + presets: ['es2015'], + plugins: [ + ['babel-plugin-espower'] + ] + } + }], + postLoaders: [{ + test: /\.json$/, + loader: 'json' + }, { + test: /\.js$/, + exclude: /test|node_modules|vue\/dist/, + loader: 'istanbul-instrumenter' + }] + } + }, + + webpackMiddleware: { + noInfo: true + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: [ + 'mocha', 'coverage' + ], + + coverageReporter: { + reporters: [{ + type: 'lcov', dir: '../coverage' + }, { + type: 'text-summary', dir: '../coverage' + }] + }, + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true + }) +} diff --git a/template/config/webpack.dev.conf.js b/template/config/webpack.dev.conf.js new file mode 100644 index 0000000..2b3ea43 --- /dev/null +++ b/template/config/webpack.dev.conf.js @@ -0,0 +1,42 @@ +var webpack = require('webpack') + +module.exports = { + entry: 'mocha!./test/index.js', + output: { + path: './test', + filename: 'specs.js', + publicPath: '/' + }, + devtool: 'source-map', + module: { + preLoaders: [{ + test: /\.js$/, + exclude: /node_modules/, + loader: 'eslint-loader' + }], + loaders: [{ + test: /\.js$/, + exclude: /node_modules|vue\/dist/, + loader: 'babel', + query: { + presets: ['es2015'], + plugins: [ + 'babel-plugin-espower' + ] + } + }], + postLoaders: [{ + test: /\.json$/, + loader: 'json' + }] + }, + devServer: { + contentBase: './test', + port: 8080, + hot: true, + inline: true + }, + plugins: [ + new webpack.HotModuleReplacementPlugin() + ] +} diff --git a/template/dist/.gitkeep b/template/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/template/package.json b/template/package.json new file mode 100644 index 0000000..7f67224 --- /dev/null +++ b/template/package.json @@ -0,0 +1,74 @@ +{ + "name": "{{ name }}", + "description": "{{ description }}", + "version": "0.0.0", + "author": { + "name": "{{ authorFullNameFrom author }}", + "email": "{{ authorEmailFrom author }}" + }, + {{#unless_eq githubAccount ""}} + "bugs": { + "url": "https://github.com/{{ github_account }}/{{ name }}/issues" + }, + {{/unless_eq}} + "devDependencies": { + "babel-core": "^6.2.1", + "babel-loader": "^6.2.0", + "babel-plugin-espower": "^2.0.0", + "babel-preset-es2015": "^6.1.18", + "babel-preset-es2015-rollup": "^1.0.0", + "eslint": "^2.8.0", + "eslint-config-vue": "^1.0.0", + "eslint-loader": "^1.3.0", + "istanbul-instrumenter-loader": "^0.1.3", + "json-loader": "^0.5.4", + "karma": "^0.13.9", + "karma-coverage": "^0.5.2", + "karma-mocha": "^0.2.0", + "karma-mocha-reporter": "^1.1.1", + "karma-phantomjs-launcher": "^0.2.1", + "karma-sourcemap-loader": "^0.3.5", + "karma-webpack": "^1.7.0", + "mocha": "^2.3.4", + "mocha-loader": "^0.7.1", + "phantomjs": "^1.9.18", + "power-assert": "^1.2.0", + "rollup": "^0.21.1", + "rollup-plugin-babel": "^2.2.0", + "rollup-plugin-replace": "^1.1.0", + "uglify-js": "^2.6.1", + "vue": "^1.0.10", + "webpack": "^1.12.9", + "webpack-dev-server": "^1.14.0" + }, + "files": [ + "dist/{{ name }}.js", + "dist/{{ name }}.min.js", + "dist/{{ name }}.common.js", + "src" + ], + {{#unless_eq githubAccount ""}} + "homepage": "https://github.com/{{ github_account }}/{{ name }}#readme", + {{/unless_eq}} + "jsnext:main": "src/index.js", + "keywords": [ + "plugin", + "vue", + "vuejs" + ], + "license": "MIT", + "main": "dist/{{ name }}.common.js", + {{#unless_eq githubAccount ""}} + "repository": { + "type": "git", + "url": "git+https://github.com/{{ github_account }}/{{ name }}.git" + }, + {{/unless_eq}} + "scripts": { + "build": "node config/build.js", + "dev": "webpack-dev-server --quiet --config config/webpack.dev.conf.js --host 0.0.0.0", + "lint": "eslint src test config", + "test": "npm run lint && npm run unit", + "unit": "karma start config/karma.conf.js" + } +} diff --git a/template/src/index.js b/template/src/index.js new file mode 100644 index 0000000..8485d43 --- /dev/null +++ b/template/src/index.js @@ -0,0 +1,9 @@ +function plugin (Vue, options = {}) { + Vue.prototype.$add = (a, b) => { + return a + b + } +} + +plugin.version = '1.3.0' + +export default plugin diff --git a/template/test/.eslintrc b/template/test/.eslintrc new file mode 100644 index 0000000..af22ba9 --- /dev/null +++ b/template/test/.eslintrc @@ -0,0 +1,19 @@ +{ + "globals": { + "describe": true, + "context": true, + "it": true, + "before": true, + "after": true, + "beforeEach": true, + "afterEach": true, + "process": true + }, + "extends": "vue", + "rules": { + "no-inline-comments": 0, + "object-curly-spacing": ["error", "always"], + "no-multiple-empty-lines": [2, {"max": 2}], + "no-new": 0 + } +} diff --git a/template/test/add.js b/template/test/add.js new file mode 100644 index 0000000..73cf2f4 --- /dev/null +++ b/template/test/add.js @@ -0,0 +1,18 @@ +import assert from 'power-assert' +import Vue from 'vue' + + +describe('$add', () => { + let vm + + beforeEach(() => { + vm = new Vue() + }) + + describe('1 + 1', () => { + it('should be 2', () => { + assert(vm.$add(1, 1) === 3) + }) + }) +}) + diff --git a/template/test/index.html b/template/test/index.html new file mode 100644 index 0000000..994c04f --- /dev/null +++ b/template/test/index.html @@ -0,0 +1,10 @@ + + + + plugin tests + + + + + + diff --git a/template/test/index.js b/template/test/index.js new file mode 100644 index 0000000..4a7f978 --- /dev/null +++ b/template/test/index.js @@ -0,0 +1,6 @@ +import Vue from 'vue' +import plugin from '../src/index' + +Vue.use(plugin) + +require('./add')