Skip to content

Commit

Permalink
Setup prettier 🤩
Browse files Browse the repository at this point in the history
  • Loading branch information
pirelenito committed Oct 6, 2019
1 parent 55406d0 commit 5f7ea5a
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 900 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["prettier"]
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
56 changes: 27 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Then, simply configure it as a plugin in the webpack config:
var GitRevisionPlugin = require('git-revision-webpack-plugin')

module.exports = {
plugins: [
new GitRevisionPlugin()
]
plugins: [new GitRevisionPlugin()],
}
```

Expand Down Expand Up @@ -61,8 +59,8 @@ Example:
module.exports = {
output: {
publicPath: 'http://my-fancy-cdn.com/[git-revision-version]/',
filename: '[name]-[git-revision-hash].js'
}
filename: '[name]-[git-revision-hash].js',
},
}
```

Expand All @@ -81,12 +79,12 @@ module.exports = {
plugins: [
gitRevisionPlugin,
new webpack.DefinePlugin({
'VERSION': JSON.stringify(gitRevisionPlugin.version()),
'COMMITHASH': JSON.stringify(gitRevisionPlugin.commithash()),
'BRANCH': JSON.stringify(gitRevisionPlugin.branch()),
'LASTCOMMITDATETIME': JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
})
]
VERSION: JSON.stringify(gitRevisionPlugin.version()),
COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
LASTCOMMITDATETIME: JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
}),
],
}
```

Expand All @@ -104,9 +102,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
lightweightTags: true
})
]
lightweightTags: true,
}),
],
}
```

Expand All @@ -120,9 +118,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
branch: true
})
]
branch: true,
}),
],
}
```

Expand All @@ -136,9 +134,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
commithashCommand: 'rev-list --max-count=1 --no-merges HEAD'
})
]
commithashCommand: 'rev-list --max-count=1 --no-merges HEAD',
}),
],
}
```

Expand All @@ -152,9 +150,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
versionCommand: 'describe --always --tags --dirty'
})
]
versionCommand: 'describe --always --tags --dirty',
}),
],
}
```

Expand All @@ -168,9 +166,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
branchCommand: 'rev-parse --symbolic-full-name HEAD'
})
]
branchCommand: 'rev-parse --symbolic-full-name HEAD',
}),
],
}
```

Expand All @@ -184,9 +182,9 @@ var GitRevisionPlugin = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
branchCommand: 'log -1 --format=%ci'
})
]
branchCommand: 'log -1 --format=%ci',
}),
],
}
```

Expand Down
10 changes: 5 additions & 5 deletions fixtures/project/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module.exports = {

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

module: {
rules: [
{
test: /\.(txt)$/,
use: 'file-loader?name=[name]-[git-revision-branch]-[git-revision-version].[ext]'
}
]
}
use: 'file-loader?name=[name]-[git-revision-branch]-[git-revision-version].[ext]',
},
],
},
}
18 changes: 9 additions & 9 deletions lib/build-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ var runGitCommand = require('./helpers/run-git-command')
module.exports = ({ compiler, gitWorkTree, command, replacePattern, asset }) => {
var data = ''

compiler.hooks.compilation.tap('compilation', (compilation) => {
compiler.hooks.compilation.tap('compilation', compilation => {
compilation.hooks.optimizeTree.tapAsync('optimize-tree', (chunks, modules, callback) => {
runGitCommand(gitWorkTree, command, function (err, res) {
if (err) { return callback(err) }
runGitCommand(gitWorkTree, command, function(err, res) {
if (err) {
return callback(err)
}
data = res

callback()
})
})

compilation.mainTemplate.hooks.assetPath.tap('asset-path', (assetPath, chunkData) => {
return (typeof assetPath === 'function'
? assetPath(chunkData)
: assetPath).replace(replacePattern, data)
return (typeof assetPath === 'function' ? assetPath(chunkData) : assetPath).replace(replacePattern, data)
})
})

compiler.hooks.emit.tapAsync('emit', (compilation, callback) => {
compilation.assets[asset] = {
source: function () {
source: function() {
return data
},
size: function () {
size: function() {
return data.length
}
},
}

callback()
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/remove-empty-lines.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function removeEmptyLines (string) {
module.exports = function removeEmptyLines(string) {
return string.replace(/[\s\r\n]+$/, '')
}
20 changes: 7 additions & 13 deletions lib/helpers/run-git-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@ var execSync = require('child_process').execSync
var path = require('path')
var removeEmptyLines = require('./remove-empty-lines')

module.exports = function (gitWorkTree, command, callback) {
module.exports = function(gitWorkTree, command, callback) {
var gitCommand = gitWorkTree
? [
'git',
'--git-dir=' + path.join(gitWorkTree, '.git'),
'--work-tree=' + gitWorkTree,
command
].join(' ')
: [
'git',
command
].join(' ')
? ['git', '--git-dir=' + path.join(gitWorkTree, '.git'), '--work-tree=' + gitWorkTree, command].join(' ')
: ['git', command].join(' ')

if (callback) {
exec(gitCommand, function (err, stdout) {
if (err) { return callback(err) }
exec(gitCommand, function(err, stdout) {
if (err) {
return callback(err)
}
callback(null, removeEmptyLines(stdout))
})
} else {
Expand Down
Loading

0 comments on commit 5f7ea5a

Please sign in to comment.