webpack-auto-inject-version
Advanced tools
Comparing version 0.5.14 to 1.0.0
{ | ||
"name": "webpack-auto-inject-version", | ||
"version": "0.5.14", | ||
"version": "1.0.0", | ||
"repository": "radswiat/webpack-auto-inject-version", | ||
@@ -5,0 +5,0 @@ "description": "Webpack plugin for auto inject version from package.json", |
@@ -34,3 +34,3 @@ # Auto inject version - Webpack plugin | ||
### Example ( in webpack.conf.js ) | ||
### Simple config example ( in webpack.conf.js ) | ||
```js | ||
@@ -53,3 +53,55 @@ var WebpackAutoInject = require('webpack-auto-inject-version'); | ||
### Full config example ( in webpack.conf.js ) | ||
``` | ||
module.exports = { | ||
... | ||
plugins: [ | ||
new WebpackAutoInject({ | ||
NAME: 'AIV custom name', | ||
SHORT: 'CUSTOM', | ||
SILENT: false, | ||
PACKAGE_JSON_PATH: './package.json', | ||
components: { | ||
AutoIncreaseVersion: true, | ||
InjectAsComment: true, | ||
InjectByTag: true | ||
}, | ||
componentsOptions: { | ||
AutoIncreaseVersion: { | ||
runInWatchMode: false // it will increase version with every single build! | ||
}, | ||
InjectAsComment: { | ||
tag: 'Version: {version} - {date}', | ||
dateFormat: 'h:MM:ss TT' | ||
}, | ||
InjectByTag: { | ||
fileRegex: /\.+/, | ||
dateFormat: 'h:MM:ss TT' | ||
} | ||
}, | ||
LOGS_TEXT: { | ||
AIS_START: 'DEMO AIV started' | ||
} | ||
}) | ||
] | ||
} | ||
``` | ||
### Inject by tag example | ||
``` | ||
<body> | ||
<span> | ||
[AIV]{version}[/AIV] | ||
</span> | ||
<span> | ||
[AIV]{date}[/AIV] | ||
</span> | ||
<span> | ||
[AIV]{version}_{date}[/AIV] | ||
</span> | ||
<span> | ||
[AIV]V:{version} Date:{date}[/AIV] | ||
</span> | ||
</body> | ||
``` | ||
@@ -71,2 +123,20 @@ # Available options | ||
``` | ||
To enable watch mode: | ||
``` | ||
plugins: [ | ||
new WebpackAutoInject({ | ||
... | ||
components: { | ||
AutoIncreaseVersion: true, | ||
... | ||
}, | ||
componentsOptions: { | ||
AutoIncreaseVersion: { | ||
runInWatchMode: false // it will increase version with every single build! | ||
} | ||
} | ||
}) | ||
] | ||
``` | ||
Default: true | ||
@@ -105,3 +175,4 @@ | ||
InjectAsComment: { | ||
tag: 'Build version: {version} - {date}' // default | ||
tag: 'Build version: {version} - {date}', // default | ||
dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT' // default | ||
} | ||
@@ -134,2 +205,8 @@ }) | ||
# Change log | ||
## [1.0.0] - 25/08/2017 | ||
- Date format can now be specified for InjectAsComment | ||
- Date format can now be specified for InjectByTag | ||
- Webpack WATCH support added | ||
d- Root SILENT option added | ||
- Minor fixes | ||
## [0.5.14] - 12/04/2017 | ||
@@ -136,0 +213,0 @@ - Remove babel polyfills from webpack build as it was causing issues if babel was already used in project |
@@ -6,2 +6,3 @@ import semver from 'semver'; | ||
import log from 'core/log'; | ||
import config from 'config'; | ||
@@ -22,2 +23,19 @@ export default class AutoIncreaseVersion { | ||
apply() { | ||
// when runInWatchMode | ||
// we have to register AutoIncreaseVersion instead of firing it straight away | ||
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) { | ||
if (this.context.compiler) { | ||
this.context.compiler.plugin('emit', async (compilation, cb) => { | ||
await new Promise((resolve, reject) => { | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
this.start(); | ||
}); | ||
cb(); | ||
}); | ||
} | ||
return null; | ||
} | ||
// when runInWatchMode is off | ||
return new Promise((resolve, reject) => { | ||
@@ -36,2 +54,5 @@ this.resolve = resolve; | ||
this.packageFile = this.openPackageFile(); | ||
if (!this.packageFile) { | ||
return; | ||
} | ||
if (isArgv('major')) { | ||
@@ -44,3 +65,3 @@ this.major(); | ||
} else { | ||
this.reject(); | ||
this.resolve(); | ||
} | ||
@@ -54,3 +75,12 @@ } | ||
openPackageFile() { | ||
return JSON.parse(fs.readFileSync(path.resolve(this.context.config.PACKAGE_JSON_PATH), 'utf8')); | ||
try { | ||
return JSON.parse( | ||
fs.readFileSync( | ||
path.resolve(this.context.config.PACKAGE_JSON_PATH), | ||
'utf8' | ||
) | ||
); | ||
} catch (err) { | ||
return null; | ||
} | ||
} | ||
@@ -57,0 +87,0 @@ |
import dateFormat from 'dateformat'; | ||
import config from 'config'; | ||
@@ -8,4 +9,4 @@ export default { | ||
date: () => { | ||
return dateFormat(new Date(), 'dddd, mmmm dS, yyyy, h:MM:ss TT'); | ||
return dateFormat(new Date(), config.componentsOptions.InjectAsComment.dateFormat); | ||
} | ||
}; |
@@ -0,2 +1,4 @@ | ||
import dateFormat from 'dateformat'; | ||
import log from 'core/log'; | ||
import config from 'config'; | ||
@@ -11,2 +13,3 @@ /** | ||
static componentName = 'InjectByTag'; | ||
static AIVTagRegexp = /(\[AIV])(([a-zA-Z{} :;!()_@\-"'\\\/])+)(\[\/AIV])/g; | ||
@@ -36,7 +39,26 @@ constructor(context) { | ||
let modFile = originalSource.replace(/(\[AIV\]{version}\[\/AIV\])/g, () => { | ||
let modFile = originalSource.replace(InjectByTag.AIVTagRegexp, (tag) => { | ||
// handle version | ||
tag = tag.replace(/(\{)(version)(\})/g, () => { | ||
return this.context.version; | ||
}); | ||
// handle date | ||
tag = tag.replace(/(\{)(date)(\})/g, () => { | ||
return dateFormat(new Date(), config.componentsOptions.InjectByTag.dateFormat); | ||
}); | ||
// remove [AIV] and [/AIV] | ||
tag = tag.replace(/(\[AIV])|(\[\/AIV])/g, ''); | ||
replaced++; | ||
return this.context.version; | ||
return tag; | ||
}); | ||
// let modFile = originalSource.replace(/(\[AIV\]{version}\[\/AIV\])/g, () => { | ||
// replaced++; | ||
// return this.context.version; | ||
// }); | ||
asset.source = () => modFile; | ||
@@ -43,0 +65,0 @@ log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`); |
export default { | ||
NAME: 'Auto Inject Version', | ||
SHORT: 'AIV', | ||
SILENT: false, | ||
PACKAGE_JSON_PATH: './package.json', | ||
@@ -9,7 +12,12 @@ components: { | ||
componentsOptions: { | ||
AutoIncreaseVersion: { | ||
runInWatchMode: false | ||
}, | ||
InjectAsComment: { | ||
tag: 'Build version: {version} - {date}' | ||
tag: 'Build version: {version} - {date}', | ||
dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT' | ||
}, | ||
InjectByTag: { | ||
fileRegex: /\.+/ | ||
fileRegex: /\.+/, | ||
dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT' | ||
} | ||
@@ -16,0 +24,0 @@ }, |
@@ -49,2 +49,3 @@ import config from 'config'; | ||
error(msg) { | ||
if (config.SILENT) return; | ||
if (this.logLevel < 3) return; | ||
@@ -55,2 +56,3 @@ console.log(`${this.getHead()} ${chalk.red('error')} : ${msg}`); | ||
info(msg) { | ||
if (config.SILENT) return; | ||
if (!this.logLevel) return; | ||
@@ -61,2 +63,3 @@ console.log(`${this.getHead()} ${chalk.blue('info')} : ${msg}`); | ||
warn(msg) { | ||
if (config.SILENT) return; | ||
if (!this.logLevel) return; | ||
@@ -63,0 +66,0 @@ console.log(`${this.getHead()} ${chalk.yellow('warn')} : ${msg}`); |
@@ -16,11 +16,2 @@ /* global define */ | ||
/** | ||
* Protected config | ||
* @type {{NAME: string, SHORT: string}} | ||
*/ | ||
static protectedConfig = { | ||
NAME: 'Auto Inject Version', | ||
SHORT: 'AIV' | ||
}; | ||
/** | ||
* Constructor, | ||
@@ -53,4 +44,2 @@ * called on webpack config load | ||
}); | ||
this.config = merge(this.config, WebpackAutoInject.protectedConfig); | ||
} | ||
@@ -85,2 +74,5 @@ | ||
async executeWebpackComponents() { | ||
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) { | ||
await this.executeComponent([AutoIncreaseVersion]); | ||
} | ||
await this.executeComponent([InjectAsComment, InjectByTag]); | ||
@@ -87,0 +79,0 @@ } |
@@ -15,10 +15,2 @@ import path from 'path'; | ||
module: { | ||
// rules: [ | ||
// { // eslint feature | ||
// enforce: 'pre', | ||
// test: /\.js$/, | ||
// loader: 'eslint-loader', | ||
// exclude: /node_modules/ | ||
// } | ||
// ], | ||
loaders: [ | ||
@@ -25,0 +17,0 @@ { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
729682
21463
1
215