Skip to content

Commit 3601be1

Browse files
committed
chore: use prettier as a formatter
1 parent 5f2b719 commit 3601be1

20 files changed

+312
-738
lines changed

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist/
3+
lib/
4+
/example/build.js

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
semi: false
2+
singleQuote: true
3+
printWidth: 80

build/build.js

Lines changed: 85 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const rollup = require('rollup')
66
const replace = require('rollup-plugin-replace')
77
const babel = require('rollup-plugin-babel')
88
const version = process.env.VERSION || require('../package.json').version
9-
const banner =
10-
`/**
9+
const banner = `/**
1110
* vue-class-component v${version}
1211
* (c) 2015-present Evan You
1312
* @license MIT
@@ -17,7 +16,7 @@ if (!fs.existsSync('dist')) {
1716
fs.mkdirSync('dist')
1817
}
1918

20-
const resolve = _path => path.resolve(__dirname, '../', _path)
19+
const resolve = (_path) => path.resolve(__dirname, '../', _path)
2120

2221
const babelConfigForModern = {
2322
presets: [
@@ -26,58 +25,60 @@ const babelConfigForModern = {
2625
{
2726
modules: false,
2827
targets: {
29-
esmodules: true
30-
}
31-
}
32-
]
33-
]
28+
esmodules: true,
29+
},
30+
},
31+
],
32+
],
3433
}
3534

3635
const babelConfigForLegacy = {
3736
presets: [
3837
[
3938
'@babel/env',
4039
{
41-
modules: false
42-
}
43-
]
44-
]
40+
modules: false,
41+
},
42+
],
43+
],
4544
}
4645

47-
build([
48-
{
49-
file: resolve('dist/vue-class-component.js'),
50-
format: 'umd',
51-
env: 'development'
52-
},
53-
{
54-
file: resolve('dist/vue-class-component.min.js'),
55-
format: 'umd',
56-
env: 'production'
57-
},
58-
{
59-
file: resolve('dist/vue-class-component.common.js'),
60-
format: 'cjs'
61-
},
62-
{
63-
file: resolve('dist/vue-class-component.esm.js'),
64-
format: 'esm'
65-
},
66-
{
67-
file: resolve('dist/vue-class-component.esm.browser.js'),
68-
format: 'esm',
69-
env: 'development'
70-
},
71-
{
72-
file: resolve('dist/vue-class-component.esm.browser.min.js'),
73-
format: 'esm',
74-
env: 'production'
75-
}
76-
].map(genConfig)).catch(() => {
46+
build(
47+
[
48+
{
49+
file: resolve('dist/vue-class-component.js'),
50+
format: 'umd',
51+
env: 'development',
52+
},
53+
{
54+
file: resolve('dist/vue-class-component.min.js'),
55+
format: 'umd',
56+
env: 'production',
57+
},
58+
{
59+
file: resolve('dist/vue-class-component.common.js'),
60+
format: 'cjs',
61+
},
62+
{
63+
file: resolve('dist/vue-class-component.esm.js'),
64+
format: 'esm',
65+
},
66+
{
67+
file: resolve('dist/vue-class-component.esm.browser.js'),
68+
format: 'esm',
69+
env: 'development',
70+
},
71+
{
72+
file: resolve('dist/vue-class-component.esm.browser.min.js'),
73+
format: 'esm',
74+
env: 'production',
75+
},
76+
].map(genConfig)
77+
).catch(() => {
7778
process.exit(1)
7879
})
7980

80-
function genConfig (opts) {
81+
function genConfig(opts) {
8182
const config = {
8283
input: {
8384
input: resolve('lib/index.js'),
@@ -87,8 +88,8 @@ function genConfig (opts) {
8788
opts.format === 'esm' && typeof opts.env === 'string'
8889
? babelConfigForModern
8990
: babelConfigForLegacy
90-
)
91-
]
91+
),
92+
],
9293
},
9394
output: {
9495
file: opts.file,
@@ -97,50 +98,55 @@ function genConfig (opts) {
9798
name: 'VueClassComponent',
9899
exports: 'named',
99100
globals: {
100-
vue: 'Vue'
101-
}
102-
}
101+
vue: 'Vue',
102+
},
103+
},
103104
}
104105

105106
if (opts.env) {
106-
config.input.plugins.unshift(replace({
107-
'process.env.NODE_ENV': JSON.stringify(opts.env)
108-
}))
107+
config.input.plugins.unshift(
108+
replace({
109+
'process.env.NODE_ENV': JSON.stringify(opts.env),
110+
})
111+
)
109112
}
110113

111114
return config
112115
}
113116

114-
function build (builds) {
117+
function build(builds) {
115118
let built = 0
116119
const total = builds.length
117120
const next = () => {
118-
return buildEntry(builds[built]).then(() => {
119-
built++
120-
if (built < total) {
121-
return next()
122-
}
123-
}).catch(error => {
124-
logError(error)
125-
throw error
126-
})
121+
return buildEntry(builds[built])
122+
.then(() => {
123+
built++
124+
if (built < total) {
125+
return next()
126+
}
127+
})
128+
.catch((error) => {
129+
logError(error)
130+
throw error
131+
})
127132
}
128133

129134
return next()
130135
}
131136

132-
function buildEntry ({ input, output }) {
137+
function buildEntry({ input, output }) {
133138
const isProd = /min\.js$/.test(output.file)
134-
return rollup.rollup(input)
135-
.then(bundle => bundle.generate(output))
136-
.then(result => {
139+
return rollup
140+
.rollup(input)
141+
.then((bundle) => bundle.generate(output))
142+
.then((result) => {
137143
const { code } = result.output[0]
138144
if (isProd) {
139145
const minified = uglify.minify(code, {
140146
output: {
141147
preamble: output.banner,
142-
ascii_only: true
143-
}
148+
ascii_only: true,
149+
},
144150
}).code
145151
return write(output.file, minified, true)
146152
} else {
@@ -149,14 +155,19 @@ function buildEntry ({ input, output }) {
149155
})
150156
}
151157

152-
function write (dest, code, zip) {
158+
function write(dest, code, zip) {
153159
return new Promise((resolve, reject) => {
154-
function report (extra) {
155-
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
160+
function report(extra) {
161+
console.log(
162+
blue(path.relative(process.cwd(), dest)) +
163+
' ' +
164+
getSize(code) +
165+
(extra || '')
166+
)
156167
resolve()
157168
}
158169

159-
fs.writeFile(dest, code, err => {
170+
fs.writeFile(dest, code, (err) => {
160171
if (err) return reject(err)
161172
if (zip) {
162173
zlib.gzip(code, (err, zipped) => {
@@ -170,14 +181,14 @@ function write (dest, code, zip) {
170181
})
171182
}
172183

173-
function getSize (code) {
184+
function getSize(code) {
174185
return (code.length / 1024).toFixed(2) + 'kb'
175186
}
176187

177-
function logError (e) {
188+
function logError(e) {
178189
console.log(e)
179190
}
180191

181-
function blue (str) {
192+
function blue(str) {
182193
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
183194
}

build/dev-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ fs.watch('test/test.build.js', () => {
88
run('mocha --reporter min test/test.build.js')
99
})
1010

11-
function run (command) {
11+
function run(command) {
1212
const [name, ...args] = command.split(' ')
1313
spawn(`node_modules/.bin/${name}`, args, {
1414
shell: true,
15-
stdio: 'inherit'
15+
stdio: 'inherit',
1616
})
1717
}

docs/.vuepress/config.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
title: 'Vue Class Component',
3-
description: 'ECMAScript / TypeScript decorator for class-style Vue components',
3+
description:
4+
'ECMAScript / TypeScript decorator for class-style Vue components',
45

56
themeConfig: {
67
repo: 'vuejs/vue-class-component',
@@ -10,18 +11,16 @@ module.exports = {
1011
nav: [
1112
{
1213
text: 'Guide',
13-
link: '/'
14+
link: '/',
1415
},
1516
{
1617
text: 'API Reference',
17-
link: '/api/'
18-
}
18+
link: '/api/',
19+
},
1920
],
2021

2122
sidebar: {
22-
'/api/': [
23-
''
24-
],
23+
'/api/': [''],
2524

2625
'/': [
2726
'',
@@ -34,8 +33,8 @@ module.exports = {
3433
'guide/additional-hooks.md',
3534
'guide/custom-decorators.md',
3635
'guide/extend-and-mixins.md',
37-
'guide/caveats.md'
38-
]
36+
'guide/caveats.md',
37+
],
3938
},
4039
{
4140
title: 'TypeScript Guide',
@@ -44,10 +43,10 @@ module.exports = {
4443
'guide/props-definition.md',
4544
'guide/property-type-declaration.md',
4645
'guide/refs-type-extension.md',
47-
'guide/hooks-auto-complete.md'
48-
]
49-
}
50-
]
51-
}
52-
}
53-
}
46+
'guide/hooks-auto-complete.md',
47+
],
48+
},
49+
],
50+
},
51+
},
52+
}

example/babel.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module.exports = {
2-
presets: [
3-
['@babel/env', { modules: false }]
4-
]
2+
presets: [['@babel/env', { modules: false }]],
53
}

example/src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ import { createApp } from 'vue'
22
import App from './App.vue'
33

44
createApp(App, { propMessage: 'World' }).mount('#app')
5-

0 commit comments

Comments
 (0)