Release version 1.2.0

This commit is contained in:
rad.swiat 2018-10-27 18:59:02 +01:00
parent 5f4b82bc42
commit 58a56af144
11 changed files with 768 additions and 543 deletions

View File

@ -1,4 +1,5 @@
npm-debug*
.idea/
.vscode/
demo/
scrapyard/

View File

@ -23,8 +23,8 @@ Auto Inject Version (AIV) can:
- auto increase package.json version by --env.major, --env.minor, --env.patch passed into webpack
# How to use
It's easy to set it up, all you need is:
* use WebpackAutoInject in webpack plugins
It's easy to set it up, all you need is:
* use WebpackAutoInject in webpack plugins
* pass config as a parameter, or leave it blank as all options are "on" by default.
### Simple config example ( in webpack.conf.js )
@ -67,7 +67,8 @@ module.exports = {
},
InjectAsComment: {
tag: 'Version: {version} - {date}',
dateFormat: 'h:MM:ss TT'
dateFormat: 'h:MM:ss TT', // change timezone: `UTC:h:MM:ss` or `GMT:h:MM:ss`
multiLineCommentType: false, // use `/** */` instead of `//` as comment block
},
InjectByTag: {
fileRegex: /\.+/,
@ -173,11 +174,12 @@ Example:
...
InjectAsComment: {
tag: 'Build version: {version} - {date}', // default
dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT' // default
dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT', // default
multiLineCommentType: false, // default
}
})
]
```
```
Default: true
@ -238,6 +240,11 @@ to prevent stripping out AIV comments eg:
```
# Change log
## [1.2.0] - 27/10/2018
- inject as comment will no more be a version behind with auto increase version
- inject as comment can now switched to multiline comment type eg /** */
- added support for npm log levels eg `npm start -s` will disable console logs
- unit tests added inside the `demo` folder, `npm run test`
## [1.1.0] - 15/03/2018
- webpack sync apply
- "name" has been removed as not used anyway, use SHORT instead

View File

@ -1,5 +1,4 @@
// [AIV_SHORT] Build version: 0.14.0 - Saturday, October 27th, 2018, 2:45:47 PM
/******/ (function(modules) { // webpackBootstrap
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
@ -88,7 +87,7 @@ test(myVariable);
/* 1 */
/***/ (function(module, exports) {
module.exports = "<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><title>Title</title></head><body><span>0.14.0</span> <span>_14:10:47_</span> <span>0.14.0__14:10:47_</span> <span>V:0.14.0 Date:_14:10:47_</span> <span>Version 0.14.0 , _14:10:47_</span> <span id=date>_14:10:47_</span></body></html>"
module.exports = "<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><title>Title</title></head><body><span>0.14.0</span> <span>_18:10:17_</span> <span>0.14.0__18:10:17_</span> <span>V:0.14.0 Date:_18:10:17_</span> <span>Version 0.14.0 , _18:10:17_</span> <span id=date>_18:10:17_</span></body></html>"
/***/ }),
/* 2 */
@ -98,4 +97,4 @@ module.exports = __webpack_require__(0);
/***/ })
/******/ ]);
/******/ ]);

View File

@ -9,6 +9,11 @@ describe('Inject by tag', () => {
describe('default', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: false,
InjectAsComment: false,
InjectByTag: true,
},
componentsOptions: {
InjectByTag: {
dateFormat: '_HH:mm:ss_',
@ -37,19 +42,128 @@ describe('Inject by tag', () => {
const date = $('#date').text().trim();
expect(/^(_\d\d:\d\d:\d\d_)$/.test(date)).to.be.true;
});
});
}
});
});
});
if (webpackConfName === 'confHtml') {
it('HTML!?!?>!?', () => {
const distHtml = getDistFile('index.html');
expect(distHtml).to.not.include('[AIV]');
});
}
describe('Inject as comment', () => {
// default inject by tag tests
describe('default', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: false,
InjectAsComment: true,
InjectByTag: false,
},
componentsOptions: {
InjectAsComment: {
tag: '_Version: {version} - {date}',
dateFormat: '_HH:mm:ss_',
// multiLineCommentType: true
},
},
};
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
it('Should include AIV_SHORT comment block', async () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.include('[AIV_SHORT] _Version:');
});
it('Should use single line comment block', () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.match(/^(\/\/)/);
});
});
}
});
});
// default inject by tag tests
describe('multiline', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: false,
InjectAsComment: true,
InjectByTag: false,
},
componentsOptions: {
InjectAsComment: {
tag: '_Version: {version} - {date}',
dateFormat: '_HH:mm:ss_',
multiLineCommentType: true
},
},
};
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
it('Should use multiline comment block', () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.match(/^(\/\*\*)/);
});
});
}
});
});
});
describe('Auto increase version', () => {
// default inject by tag tests
describe('default', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: true,
InjectAsComment: true,
InjectByTag: false,
},
componentsOptions: {
AutoIncreaseVersion: {
runInWatchMode: true,
simulate: true, // testing purpose only
forceMode: 'patch', // testing purpose only
},
},
};
// container for webpack iterations
describe('Iterate webpack configs', async () => {
for (const [webpackConfName, webpackConfig] of testWebpackConfigs) {
describe(`webpack: ${webpackConfName}`, () => {
it('prepare', async () => {
await webpackCompile(webpackConfig, config);
});
it('InjectAsComment should include correct AIV version', async () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.include('0.14.1');
});
});
}
});
});
});

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "webpack-auto-inject-version",
"version": "1.1.0",
"version": "1.2.0",
"repository": "radswiat/webpack-auto-inject-version",
"description": "Webpack plugin for auto inject version from package.json",
"main": "dist/WebpackAutoInjectVersion.js",

View File

@ -1,34 +0,0 @@
// this.context.compiler.plugin('compilation', (compilation) => {
// console.log(chalk.red('COOOMPILE!'));
// console.log(compilation.assets)
//
// compilation.plugin('optimize-chunk-assets', (chunks, cb) => {
// //unless you specified multiple entries in your config
// //there's only one chunk at this point
// chunks.forEach((chunk) => {
// //chunks have circular references to their modules
// console.log(chalk.green('----- module -----'));
// // console.log(JSON.stringify(chunk));
//
// chunk.files.forEach((file) => {
// console.log('--------------------------');
// console.log(file);
// // console.log(compilation.assets[file]);
// // compilation.assets[file] = 'asdasdadas';
//
// // const asset = `VERSION! ${endOfLine} ${compilation.assets[file].source()} `;
// // compilation.assets[file].source = () => asset;
// // console.log('--------- end -----------------');
//
// const assetFile = compilation.assets[file];
// const assetFilename = file;
// const ext = path.extname(assetFilename).replace(/(\?)(.){0,}/, '');
// console.log('ext', ext);
// const newContent = this.handleAssetFile(ext, assetFile);
// console.log(newContent);
// });
// });
// cb();
// });
//
// });

View File

@ -54,6 +54,15 @@ export default class AutoIncreaseVersion {
if (!this.packageFile) {
return;
}
// handle force mode - major, minor or patch can be applied trough config
// ONLY TO BE USED FOR TESTING PURPOSES,
if (config.componentsOptions.AutoIncreaseVersion.forceMode) {
if (typeof this[config.componentsOptions.AutoIncreaseVersion.forceMode] === 'function') {
return this[config.componentsOptions.AutoIncreaseVersion.forceMode]();
}
}
if (isArgv('major')) {
this.major();
} else if (isArgv('minor')) {
@ -83,12 +92,25 @@ export default class AutoIncreaseVersion {
}
}
updateContextVersion(newVersion) {
this.context.version = newVersion;
}
/**
* Close & save package file
* @param newVersion
*/
closePackageFile(newVersion) {
this.packageFile.version = newVersion;
// prevent saving package.json file in simulate mode
if (config.componentsOptions.AutoIncreaseVersion.simulate) {
log.info(`autoIncVersion : new version : ${newVersion}`);
log.info('package.json updated!');
return;
}
// write new package.json file
fs.writeFile(
path.resolve(this.context.config.PACKAGE_JSON_PATH),
JSON.stringify(this.packageFile, null, 4), (err) => {
@ -110,6 +132,7 @@ export default class AutoIncreaseVersion {
*/
major() {
const newVersion = semver.inc(this.packageFile.version, 'major');
this.updateContextVersion(newVersion);
this.closePackageFile(newVersion);
}
@ -118,6 +141,7 @@ export default class AutoIncreaseVersion {
*/
minor() {
const newVersion = semver.inc(this.packageFile.version, 'minor');
this.updateContextVersion(newVersion);
this.closePackageFile(newVersion);
}
@ -126,6 +150,7 @@ export default class AutoIncreaseVersion {
*/
patch() {
const newVersion = semver.inc(this.packageFile.version, 'patch');
this.updateContextVersion(newVersion);
this.closePackageFile(newVersion);
}
}

View File

@ -129,7 +129,12 @@ export default class InjectAsComment {
* @param asset
*/
injectIntoJs(asset) {
let modAsset = this.parseTags(`// [${config.SHORT}] `, ' ');
let modAsset;
if (this.context.config.componentsOptions.InjectAsComment.multiLineCommentType) {
modAsset = this.parseTags(`/** [${config.SHORT}] `, '*/ ');
} else {
modAsset = this.parseTags(`// [${config.SHORT}] `, ' ');
}
modAsset += `${endOfLine} ${asset.source()} `;
asset.source = () => modAsset;
}

View File

@ -14,6 +14,7 @@ export default {
InjectAsComment: {
tag: 'Build version: {version} - {date}',
dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
multiLineCommentType: false,
},
InjectByTag: {
fileRegex: /\.+/,

View File

@ -14,7 +14,11 @@ class Log {
}
getLogLevel() {
if (isArgv('aiv-log-full')) {
// support npm log levels
if (process.env.npm_config_loglevel === 'silent') {
this.logLevel = 0;
} else if (isArgv('aiv-log-full')) {
this.logLevel = 3;
} else if (isArgv('aiv-log-none')) {
this.logLevel = 0;