Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
⭐ new: support vue-cli
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
kazupon committed Jun 5, 2016
1 parent ab95ae9 commit 4f43ccd
Show file tree
Hide file tree
Showing 18 changed files with 518 additions and 0 deletions.
39 changes: 39 additions & 0 deletions meta.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
10 changes: 10 additions & 0 deletions template/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"globals": {
"process": true
},
"extends": "vue",
"rules": {
"no-multiple-empty-lines": [2, {"max": 2}],
"no-console": 0
}
}
7 changes: 7 additions & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lib
coverage
node_modules
.DS_Store
*.log
*.swp
*~
Empty file added template/CHANGELOG.md
Empty file.
20 changes: 20 additions & 0 deletions template/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 29 additions & 0 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions template/config/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"globals": {
"process": true
},
"extends": "vue",
"rules": {
"no-multiple-empty-lines": [2, {"max": 2}],
"no-console": 0
}
}
9 changes: 9 additions & 0 deletions template/config/banner.js
Original file line number Diff line number Diff line change
@@ -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' +
' */'
122 changes: 122 additions & 0 deletions template/config/build.js
Original file line number Diff line number Diff line change
@@ -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'
}
94 changes: 94 additions & 0 deletions template/config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -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
})
}
42 changes: 42 additions & 0 deletions template/config/webpack.dev.conf.js
Original file line number Diff line number Diff line change
@@ -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()
]
}
Empty file added template/dist/.gitkeep
Empty file.
Loading

0 comments on commit 4f43ccd

Please sign in to comment.