Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Commit 98ec0b2

Browse files
committed
eslint
1 parent 8350490 commit 98ec0b2

File tree

8 files changed

+58
-46
lines changed

8 files changed

+58
-46
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": "vue"
4+
}

index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var through = require('through')
22
var compiler = require('./lib/compiler')
33

4-
compiler.loadConfig({
5-
extractCss: true
6-
})
7-
84
module.exports = function vueify (file, options) {
9-
if (!/.vue$/.test(file)) return through()
5+
if (!/.vue$/.test(file)) {
6+
return through()
7+
}
8+
109
compiler.applyConfig(options)
1110
compiler.applyConfig({
1211
sourceMap: options._flags.debug
@@ -16,15 +15,15 @@ module.exports = function vueify (file, options) {
1615
var stream = through(write, end)
1716
stream.vueify = true
1817

19-
function dependency(file) {
18+
function dependency (file) {
2019
stream.emit('file', file)
2120
}
2221

23-
function emitStyle (style) {
24-
stream.emit('vueify-style', style)
22+
function emitStyle (e) {
23+
stream.emit('vueify-style', e)
2524
}
2625

27-
function write(buf) {
26+
function write (buf) {
2827
data += buf
2928
}
3029

@@ -33,7 +32,7 @@ module.exports = function vueify (file, options) {
3332
compiler.on('dependency', dependency)
3433
compiler.on('style', emitStyle)
3534

36-
compiler.compile(data, file, function(error, result) {
35+
compiler.compile(data, file, function (error, result) {
3736
compiler.removeListener('dependency', dependency)
3837
compiler.removeListener('style', emitStyle)
3938
if (error) {

lib/compiler.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var fs = require('fs')
22
var path = require('path')
33
var chalk = require('chalk')
44
var hash = require('hash-sum')
5-
var assign = require('object-assign')
65
var Emitter = require('events').EventEmitter
76
var vueCompiler = require('vue-template-compiler')
87
var sourceMap = require('source-map')
@@ -12,9 +11,10 @@ var genId = require('./gen-id')
1211
var normalize = require('./normalize')
1312
var compilers = require('./compilers')
1413
var rewriteStyle = require('./style-rewriter')
14+
var compileTemplate = require('./template-compiler')
1515

1616
// determine dynamic script paths
17-
var hotReloadAPIPath = 'vue-hot-reload-api' //normalize.dep('vue-hot-reload-api')
17+
var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
1818
var insertCSSPath = normalize.lib('insert-css')
1919

2020
var hasBabel = true
@@ -178,10 +178,7 @@ compiler.compile = function (content, filePath, cb) {
178178
script.split(splitRE).forEach(function (line, index) {
179179
var ln = index + 1
180180
var originalLine = inMapConsumer
181-
? inMapConsumer.originalPositionFor({
182-
line: ln,
183-
column: 0
184-
}).line
181+
? inMapConsumer.originalPositionFor({ line: ln, column: 0 }).line
185182
: ln
186183
if (originalLine) {
187184
map.addMapping({
@@ -206,18 +203,7 @@ function processTemplate (part, filePath, parts) {
206203
var template = getContent(part, filePath)
207204
return compileAsPromise('template', template, part.lang, filePath)
208205
.then(function (res) {
209-
var compiled = vueCompiler.compile(res)
210-
if (compiled.errors.length) {
211-
compiled.errors.forEach(function (msg) {
212-
console.error('\n' + chalk.red(msg) + '\n')
213-
})
214-
throw new Error('Vue template compilation failed')
215-
} else {
216-
parts.template = {
217-
render: toFunction(compiled.render),
218-
staticRenderFns: '[' + compiled.staticRenderFns.map(toFunction).join(',') + ']'
219-
}
220-
}
206+
parts.template = compileTemplate(res, compiler)
221207
})
222208
}
223209

@@ -255,10 +241,10 @@ function getContent (part, filePath) {
255241

256242
function loadSrc (src, filePath) {
257243
var dir = path.dirname(filePath)
258-
var filePath = path.resolve(dir, src)
259-
compiler.emit('dependency', filePath)
244+
var srcPath = path.resolve(dir, src)
245+
compiler.emit('dependency', srcPath)
260246
try {
261-
return fs.readFileSync(filePath, 'utf-8')
247+
return fs.readFileSync(srcPath, 'utf-8')
262248
} catch (e) {
263249
console.error(chalk.red(
264250
'Failed to load src: "' + src +
@@ -288,7 +274,3 @@ function compileAsPromise (type, source, lang, filePath) {
288274
return Promise.resolve(source)
289275
}
290276
}
291-
292-
function toFunction (code) {
293-
return 'function(){' + code + '}'
294-
}

lib/compilers/sass.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function (raw, cb, compiler, filePath) {
3535
if (err) {
3636
cb(err)
3737
} else {
38-
res.stats.includedFiles.forEach(function(file){
38+
res.stats.includedFiles.forEach(function (file) {
3939
compiler.emit('dependency', file)
4040
})
4141
cb(null, res.css.toString())

lib/ensure-require.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module.exports = function (name, deps) {
22
var i, len
33
var missing = []
4-
if (typeof deps === "string") {
4+
if (typeof deps === 'string') {
55
deps = [deps]
66
}
77
for (i = 0, len = deps.length; i < len; i++) {
8-
var mis, req = deps[i]
9-
if (typeof req === "string") {
8+
var mis
9+
var req = deps[i]
10+
if (typeof req === 'string') {
1011
mis = req
1112
} else {
1213
mis = req[1]
@@ -24,7 +25,7 @@ module.exports = function (name, deps) {
2425
}
2526
if (missing.length > 0) {
2627
var message = 'You are trying to use "' + name + '". '
27-
var npmInstall = 'npm install --save-dev ' + missing.join(" ")
28+
var npmInstall = 'npm install --save-dev ' + missing.join(' ')
2829
if (missing.length > 1) {
2930
var last = missing.pop()
3031
message += missing.join(', ') + ' and ' + last + ' are '

lib/template-compiler.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var chalk = require('chalk')
2+
var vueCompiler = require('vue-template-compiler')
3+
4+
module.exports = function compileTemplate (template, compiler) {
5+
var compiled = vueCompiler.compile(template)
6+
if (compiled.errors.length) {
7+
compiled.errors.forEach(function (msg) {
8+
console.error('\n' + chalk.red(msg) + '\n')
9+
})
10+
throw new Error('Vue template compilation failed')
11+
} else {
12+
return {
13+
render: toFunction(compiled.render),
14+
staticRenderFns: '[' + compiled.staticRenderFns.map(toFunction).join(',') + ']'
15+
}
16+
}
17+
}
18+
19+
function toFunction (code) {
20+
return 'function(){' + code + '}'
21+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"url": "https://github.com/vuejs/vueify/issues"
1818
},
1919
"scripts": {
20-
"test": "mocha test/test.js --slow=5000 --timeout=10000"
20+
"test": "eslint index.js lib && mocha test/test.js --slow=5000 --timeout=10000"
2121
},
2222
"homepage": "https://github.com/vuejs/vueify",
2323
"dependencies": {
@@ -42,6 +42,8 @@
4242
"browserify": "^13.0.1",
4343
"chai": "^3.5.0",
4444
"coffee-script": "^1.10.0",
45+
"eslint": "^2.13.0",
46+
"eslint-config-vue": "^1.0.3",
4547
"jade": "^1.11.0",
4648
"jsdom": "^9.2.1",
4749
"less": "^2.5.1",

plugins/extract-css.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
var fs = require('fs')
22
var compiler = require('../lib/compiler')
33

4-
compiler.applyConfig({
5-
extractCSS: true
6-
})
7-
84
module.exports = function (b, opts) {
9-
var outPath = opts.out || opts.o || 'bundle.css'
5+
compiler.applyConfig({
6+
extractCSS: true
7+
})
8+
109
var styles = Object.create(null)
10+
var outPath = opts.out || opts.o || 'bundle.css'
11+
if (typeof outPath === 'function') {
12+
outPath = outPath()
13+
}
1114

1215
b.on('bundle', function (bs) {
1316
bs.on('end', function () {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy