Skip to content

Commit 5f7ea5a

Browse files
committed
Setup prettier 🤩
1 parent 55406d0 commit 5f7ea5a

12 files changed

Lines changed: 434 additions & 900 deletions

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["prettier"]
3+
}

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 120,
3+
"useTabs": false,
4+
"semi": false,
5+
"singleQuote": true,
6+
"trailingComma": "all"
7+
}

README.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ Then, simply configure it as a plugin in the webpack config:
2222
var GitRevisionPlugin = require('git-revision-webpack-plugin')
2323

2424
module.exports = {
25-
plugins: [
26-
new GitRevisionPlugin()
27-
]
25+
plugins: [new GitRevisionPlugin()],
2826
}
2927
```
3028

@@ -61,8 +59,8 @@ Example:
6159
module.exports = {
6260
output: {
6361
publicPath: 'http://my-fancy-cdn.com/[git-revision-version]/',
64-
filename: '[name]-[git-revision-hash].js'
65-
}
62+
filename: '[name]-[git-revision-hash].js',
63+
},
6664
}
6765
```
6866

@@ -81,12 +79,12 @@ module.exports = {
8179
plugins: [
8280
gitRevisionPlugin,
8381
new webpack.DefinePlugin({
84-
'VERSION': JSON.stringify(gitRevisionPlugin.version()),
85-
'COMMITHASH': JSON.stringify(gitRevisionPlugin.commithash()),
86-
'BRANCH': JSON.stringify(gitRevisionPlugin.branch()),
87-
'LASTCOMMITDATETIME': JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
88-
})
89-
]
82+
VERSION: JSON.stringify(gitRevisionPlugin.version()),
83+
COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
84+
BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
85+
LASTCOMMITDATETIME: JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
86+
}),
87+
],
9088
}
9189
```
9290

@@ -104,9 +102,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
104102
module.exports = {
105103
plugins: [
106104
new GitRevisionPlugin({
107-
lightweightTags: true
108-
})
109-
]
105+
lightweightTags: true,
106+
}),
107+
],
110108
}
111109
```
112110

@@ -120,9 +118,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
120118
module.exports = {
121119
plugins: [
122120
new GitRevisionPlugin({
123-
branch: true
124-
})
125-
]
121+
branch: true,
122+
}),
123+
],
126124
}
127125
```
128126

@@ -136,9 +134,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
136134
module.exports = {
137135
plugins: [
138136
new GitRevisionPlugin({
139-
commithashCommand: 'rev-list --max-count=1 --no-merges HEAD'
140-
})
141-
]
137+
commithashCommand: 'rev-list --max-count=1 --no-merges HEAD',
138+
}),
139+
],
142140
}
143141
```
144142

@@ -152,9 +150,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
152150
module.exports = {
153151
plugins: [
154152
new GitRevisionPlugin({
155-
versionCommand: 'describe --always --tags --dirty'
156-
})
157-
]
153+
versionCommand: 'describe --always --tags --dirty',
154+
}),
155+
],
158156
}
159157
```
160158

@@ -168,9 +166,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
168166
module.exports = {
169167
plugins: [
170168
new GitRevisionPlugin({
171-
branchCommand: 'rev-parse --symbolic-full-name HEAD'
172-
})
173-
]
169+
branchCommand: 'rev-parse --symbolic-full-name HEAD',
170+
}),
171+
],
174172
}
175173
```
176174

@@ -184,9 +182,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
184182
module.exports = {
185183
plugins: [
186184
new GitRevisionPlugin({
187-
branchCommand: 'log -1 --format=%ci'
188-
})
189-
]
185+
branchCommand: 'log -1 --format=%ci',
186+
}),
187+
],
190188
}
191189
```
192190

fixtures/project/webpack.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ module.exports = {
33

44
output: {
55
publicPath: 'http://cdn.com/assets/[git-revision-branch]/[git-revision-version]/[git-revision-hash]',
6-
filename: '[name]-[git-revision-branch]-[git-revision-version].js'
6+
filename: '[name]-[git-revision-branch]-[git-revision-version].js',
77
},
88

99
module: {
1010
rules: [
1111
{
1212
test: /\.(txt)$/,
13-
use: 'file-loader?name=[name]-[git-revision-branch]-[git-revision-version].[ext]'
14-
}
15-
]
16-
}
13+
use: 'file-loader?name=[name]-[git-revision-branch]-[git-revision-version].[ext]',
14+
},
15+
],
16+
},
1717
}

lib/build-file.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ var runGitCommand = require('./helpers/run-git-command')
33
module.exports = ({ compiler, gitWorkTree, command, replacePattern, asset }) => {
44
var data = ''
55

6-
compiler.hooks.compilation.tap('compilation', (compilation) => {
6+
compiler.hooks.compilation.tap('compilation', compilation => {
77
compilation.hooks.optimizeTree.tapAsync('optimize-tree', (chunks, modules, callback) => {
8-
runGitCommand(gitWorkTree, command, function (err, res) {
9-
if (err) { return callback(err) }
8+
runGitCommand(gitWorkTree, command, function(err, res) {
9+
if (err) {
10+
return callback(err)
11+
}
1012
data = res
1113

1214
callback()
1315
})
1416
})
1517

1618
compilation.mainTemplate.hooks.assetPath.tap('asset-path', (assetPath, chunkData) => {
17-
return (typeof assetPath === 'function'
18-
? assetPath(chunkData)
19-
: assetPath).replace(replacePattern, data)
19+
return (typeof assetPath === 'function' ? assetPath(chunkData) : assetPath).replace(replacePattern, data)
2020
})
2121
})
2222

2323
compiler.hooks.emit.tapAsync('emit', (compilation, callback) => {
2424
compilation.assets[asset] = {
25-
source: function () {
25+
source: function() {
2626
return data
2727
},
28-
size: function () {
28+
size: function() {
2929
return data.length
30-
}
30+
},
3131
}
3232

3333
callback()

lib/helpers/remove-empty-lines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = function removeEmptyLines (string) {
1+
module.exports = function removeEmptyLines(string) {
22
return string.replace(/[\s\r\n]+$/, '')
33
}

lib/helpers/run-git-command.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ var execSync = require('child_process').execSync
33
var path = require('path')
44
var removeEmptyLines = require('./remove-empty-lines')
55

6-
module.exports = function (gitWorkTree, command, callback) {
6+
module.exports = function(gitWorkTree, command, callback) {
77
var gitCommand = gitWorkTree
8-
? [
9-
'git',
10-
'--git-dir=' + path.join(gitWorkTree, '.git'),
11-
'--work-tree=' + gitWorkTree,
12-
command
13-
].join(' ')
14-
: [
15-
'git',
16-
command
17-
].join(' ')
8+
? ['git', '--git-dir=' + path.join(gitWorkTree, '.git'), '--work-tree=' + gitWorkTree, command].join(' ')
9+
: ['git', command].join(' ')
1810

1911
if (callback) {
20-
exec(gitCommand, function (err, stdout) {
21-
if (err) { return callback(err) }
12+
exec(gitCommand, function(err, stdout) {
13+
if (err) {
14+
return callback(err)
15+
}
2216
callback(null, removeEmptyLines(stdout))
2317
})
2418
} else {

0 commit comments

Comments
 (0)