finalize new version, 1.1.0
This commit is contained in:
parent
318b16545c
commit
e9889e6550
22 changed files with 1011 additions and 1934 deletions
|
@ -1,20 +1,12 @@
|
||||||
# EditorConfig helps developers define and maintain consistent
|
|
||||||
# coding styles between different editors and IDEs
|
|
||||||
# http://editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
|
charset=utf-8
|
||||||
# Change these settings to your own preference
|
end_of_line=lf
|
||||||
indent_style = space
|
insert_final_newline=false
|
||||||
indent_size = 2
|
indent_style=space
|
||||||
|
indent_size=2
|
||||||
# We recommend you to keep these unchanged
|
max_line_length = 140
|
||||||
end_of_line = lf
|
wrap_width = 140
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
npm-debug*
|
npm-debug*
|
||||||
.idea/
|
.idea/
|
||||||
demo/
|
demo/
|
||||||
|
scrapyard/
|
||||||
|
|
49
README.md
49
README.md
|
@ -12,10 +12,9 @@ $ npm install webpack-auto-inject-version --save-dev
|
||||||
[How to use](#user-content-how-to-use) <br>
|
[How to use](#user-content-how-to-use) <br>
|
||||||
[Available options](#user-content-available-options) <br>
|
[Available options](#user-content-available-options) <br>
|
||||||
[Output examples](#user-content-output-examples)
|
[Output examples](#user-content-output-examples)
|
||||||
|
[How to use with other webpack plugins](#user-content-how-to-use-with-other-webpack-plugins)
|
||||||
[Change log](#user-content-change-log)
|
[Change log](#user-content-change-log)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# What it does
|
# What it does
|
||||||
Auto Inject Version (AIV) can:
|
Auto Inject Version (AIV) can:
|
||||||
- inject version from package.json into every bundle file as a comment ( at the top )
|
- inject version from package.json into every bundle file as a comment ( at the top )
|
||||||
|
@ -23,7 +22,6 @@ Auto Inject Version (AIV) can:
|
||||||
- inject version from package.json into any place in CSS/JS file by special tag `[AIV]{version}[/AIV]`
|
- inject version from package.json into any place in CSS/JS file by special tag `[AIV]{version}[/AIV]`
|
||||||
- auto increase package.json version by --env.major, --env.minor, --env.patch passed into webpack
|
- auto increase package.json version by --env.major, --env.minor, --env.patch passed into webpack
|
||||||
|
|
||||||
|
|
||||||
# How to use
|
# How to use
|
||||||
It's easy to set it up, all you need is:
|
It's easy to set it up, all you need is:
|
||||||
* use WebpackAutoInject in webpack plugins
|
* use WebpackAutoInject in webpack plugins
|
||||||
|
@ -53,7 +51,6 @@ module.exports = {
|
||||||
...
|
...
|
||||||
plugins: [
|
plugins: [
|
||||||
new WebpackAutoInject({
|
new WebpackAutoInject({
|
||||||
NAME: 'AIV custom name',
|
|
||||||
// specify the name of the tag in the outputed files eg
|
// specify the name of the tag in the outputed files eg
|
||||||
// bundle.js: [SHORT] Version: 0.13.36 ...
|
// bundle.js: [SHORT] Version: 0.13.36 ...
|
||||||
SHORT: 'CUSTOM',
|
SHORT: 'CUSTOM',
|
||||||
|
@ -201,9 +198,53 @@ Example html:
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# How to use with other webpack plugins
|
||||||
|
|
||||||
|
Webpack plugins order matters!
|
||||||
|
Always try to put WebpackAutoInject as a first webpack plugin.
|
||||||
|
|
||||||
|
## compression-webpack-plugin
|
||||||
|
|
||||||
|
```
|
||||||
|
plugins: [
|
||||||
|
new WebpackAutoInject(),
|
||||||
|
new CompressionPlugin(),
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## uglifyjs-webpack-plugin
|
||||||
|
|
||||||
|
```
|
||||||
|
plugins: [
|
||||||
|
new WebpackAutoInject(),
|
||||||
|
new UglifyJsPlugin(),
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## webpack.optimize.UglifyJsPlugin
|
||||||
|
|
||||||
|
If the order won't be enough, you can always add ignore to the uglifyJsPlugin
|
||||||
|
to prevent stripping out AIV comments eg:
|
||||||
|
|
||||||
|
```
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
...
|
||||||
|
output: {
|
||||||
|
// prevent version info to be removed from bundle.js
|
||||||
|
comments: /\[AIV\]/,
|
||||||
|
},
|
||||||
|
...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
# Change log
|
# Change log
|
||||||
|
## [1.1.0] - 15/03/2018
|
||||||
|
- webpack sync apply
|
||||||
|
- "name" has been removed as not used anyway, use SHORT instead
|
||||||
|
- eslint changes
|
||||||
|
- InjectByTag - AIVTagRegexp exposed in config to allow [AIV] tag modifications
|
||||||
|
- comma fix in InjectByTag regexp
|
||||||
|
- query has on filename has been fixed
|
||||||
## [1.0.0] - 25/08/2017
|
## [1.0.0] - 25/08/2017
|
||||||
- Date format can now be specified for InjectAsComment
|
- Date format can now be specified for InjectAsComment
|
||||||
- Date format can now be specified for InjectByTag
|
- Date format can now be specified for InjectByTag
|
||||||
|
|
101
demo/dist/index-bundle.js
vendored
101
demo/dist/index-bundle.js
vendored
|
@ -1,101 +0,0 @@
|
||||||
// [AIV_SHORT] Version: 0.13.36, Thursday, March 15th, 2018, 7:57:59 AM
|
|
||||||
/******/ (function(modules) { // webpackBootstrap
|
|
||||||
/******/ // The module cache
|
|
||||||
/******/ var installedModules = {};
|
|
||||||
/******/
|
|
||||||
/******/ // The require function
|
|
||||||
/******/ function __webpack_require__(moduleId) {
|
|
||||||
/******/
|
|
||||||
/******/ // Check if module is in cache
|
|
||||||
/******/ if(installedModules[moduleId]) {
|
|
||||||
/******/ return installedModules[moduleId].exports;
|
|
||||||
/******/ }
|
|
||||||
/******/ // Create a new module (and put it into the cache)
|
|
||||||
/******/ var module = installedModules[moduleId] = {
|
|
||||||
/******/ i: moduleId,
|
|
||||||
/******/ l: false,
|
|
||||||
/******/ exports: {}
|
|
||||||
/******/ };
|
|
||||||
/******/
|
|
||||||
/******/ // Execute the module function
|
|
||||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
||||||
/******/
|
|
||||||
/******/ // Flag the module as loaded
|
|
||||||
/******/ module.l = true;
|
|
||||||
/******/
|
|
||||||
/******/ // Return the exports of the module
|
|
||||||
/******/ return module.exports;
|
|
||||||
/******/ }
|
|
||||||
/******/
|
|
||||||
/******/
|
|
||||||
/******/ // expose the modules object (__webpack_modules__)
|
|
||||||
/******/ __webpack_require__.m = modules;
|
|
||||||
/******/
|
|
||||||
/******/ // expose the module cache
|
|
||||||
/******/ __webpack_require__.c = installedModules;
|
|
||||||
/******/
|
|
||||||
/******/ // identity function for calling harmony imports with the correct context
|
|
||||||
/******/ __webpack_require__.i = function(value) { return value; };
|
|
||||||
/******/
|
|
||||||
/******/ // define getter function for harmony exports
|
|
||||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
||||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
||||||
/******/ Object.defineProperty(exports, name, {
|
|
||||||
/******/ configurable: false,
|
|
||||||
/******/ enumerable: true,
|
|
||||||
/******/ get: getter
|
|
||||||
/******/ });
|
|
||||||
/******/ }
|
|
||||||
/******/ };
|
|
||||||
/******/
|
|
||||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
||||||
/******/ __webpack_require__.n = function(module) {
|
|
||||||
/******/ var getter = module && module.__esModule ?
|
|
||||||
/******/ function getDefault() { return module['default']; } :
|
|
||||||
/******/ function getModuleExports() { return module; };
|
|
||||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
||||||
/******/ return getter;
|
|
||||||
/******/ };
|
|
||||||
/******/
|
|
||||||
/******/ // Object.prototype.hasOwnProperty.call
|
|
||||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
||||||
/******/
|
|
||||||
/******/ // __webpack_public_path__
|
|
||||||
/******/ __webpack_require__.p = "/";
|
|
||||||
/******/
|
|
||||||
/******/ // Load entry module and return exports
|
|
||||||
/******/ return __webpack_require__(__webpack_require__.s = 2);
|
|
||||||
/******/ })
|
|
||||||
/************************************************************************/
|
|
||||||
/******/ ([
|
|
||||||
/* 0 */
|
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
var html = __webpack_require__(1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample code
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
var myVariable = 5;
|
|
||||||
var test = function(val) {
|
|
||||||
return val * val;
|
|
||||||
};
|
|
||||||
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.13.36</span> <span>7:57:59</span> <span>0.13.36_7:57:59</span> <span>V:0.13.36 Date:7:57:59</span> <span>Version 0.13.36 , 7:57:59</span></body></html>"
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
/* 2 */
|
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
module.exports = __webpack_require__(0);
|
|
||||||
|
|
||||||
|
|
||||||
/***/ })
|
|
||||||
/******/ ]);
|
|
100
demo/dist/js/index.js
vendored
100
demo/dist/js/index.js
vendored
|
@ -1,100 +0,0 @@
|
||||||
/******/ (function(modules) { // webpackBootstrap
|
|
||||||
/******/ // The module cache
|
|
||||||
/******/ var installedModules = {};
|
|
||||||
/******/
|
|
||||||
/******/ // The require function
|
|
||||||
/******/ function __webpack_require__(moduleId) {
|
|
||||||
/******/
|
|
||||||
/******/ // Check if module is in cache
|
|
||||||
/******/ if(installedModules[moduleId]) {
|
|
||||||
/******/ return installedModules[moduleId].exports;
|
|
||||||
/******/ }
|
|
||||||
/******/ // Create a new module (and put it into the cache)
|
|
||||||
/******/ var module = installedModules[moduleId] = {
|
|
||||||
/******/ i: moduleId,
|
|
||||||
/******/ l: false,
|
|
||||||
/******/ exports: {}
|
|
||||||
/******/ };
|
|
||||||
/******/
|
|
||||||
/******/ // Execute the module function
|
|
||||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
||||||
/******/
|
|
||||||
/******/ // Flag the module as loaded
|
|
||||||
/******/ module.l = true;
|
|
||||||
/******/
|
|
||||||
/******/ // Return the exports of the module
|
|
||||||
/******/ return module.exports;
|
|
||||||
/******/ }
|
|
||||||
/******/
|
|
||||||
/******/
|
|
||||||
/******/ // expose the modules object (__webpack_modules__)
|
|
||||||
/******/ __webpack_require__.m = modules;
|
|
||||||
/******/
|
|
||||||
/******/ // expose the module cache
|
|
||||||
/******/ __webpack_require__.c = installedModules;
|
|
||||||
/******/
|
|
||||||
/******/ // identity function for calling harmony imports with the correct context
|
|
||||||
/******/ __webpack_require__.i = function(value) { return value; };
|
|
||||||
/******/
|
|
||||||
/******/ // define getter function for harmony exports
|
|
||||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
||||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
||||||
/******/ Object.defineProperty(exports, name, {
|
|
||||||
/******/ configurable: false,
|
|
||||||
/******/ enumerable: true,
|
|
||||||
/******/ get: getter
|
|
||||||
/******/ });
|
|
||||||
/******/ }
|
|
||||||
/******/ };
|
|
||||||
/******/
|
|
||||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
||||||
/******/ __webpack_require__.n = function(module) {
|
|
||||||
/******/ var getter = module && module.__esModule ?
|
|
||||||
/******/ function getDefault() { return module['default']; } :
|
|
||||||
/******/ function getModuleExports() { return module; };
|
|
||||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
||||||
/******/ return getter;
|
|
||||||
/******/ };
|
|
||||||
/******/
|
|
||||||
/******/ // Object.prototype.hasOwnProperty.call
|
|
||||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
||||||
/******/
|
|
||||||
/******/ // __webpack_public_path__
|
|
||||||
/******/ __webpack_require__.p = "/";
|
|
||||||
/******/
|
|
||||||
/******/ // Load entry module and return exports
|
|
||||||
/******/ return __webpack_require__(__webpack_require__.s = 2);
|
|
||||||
/******/ })
|
|
||||||
/************************************************************************/
|
|
||||||
/******/ ([
|
|
||||||
/* 0 */
|
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
var html = __webpack_require__(1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample code
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
var myVariable = 5;
|
|
||||||
var test = function(val) {
|
|
||||||
return val * val;
|
|
||||||
};
|
|
||||||
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.13.36</span> <span>7:58:33</span> <span>0.13.36_7:58:33</span> <span>V:0.13.36 Date:7:58:33</span> <span>Version 0.13.36 , 7:58:33</span></body></html>"
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
/* 2 */
|
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
module.exports = __webpack_require__(0);
|
|
||||||
|
|
||||||
|
|
||||||
/***/ })
|
|
||||||
/******/ ]);
|
|
2
demo/dist/js/main.js
vendored
Normal file
2
demo/dist/js/main.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
// [AIV_SHORT] Version: 0.14.0, Thursday, March 15th, 2018, 11:02:44 AM
|
||||||
|
!function(n){var t={};function e(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=n,e.c=t,e.i=function(n){return n},e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:r})},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=2)}([function(n,t,e){e(1)},function(n,t){n.exports="<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><title>Title</title></head><body><span>0.14.0</span> <span>11:02:44</span> <span>0.14.0_11:02:44</span> <span>V:0.14.0 Date:11:02:44</span> <span>Version 0.14.0 , 11:02:44</span></body></html>"},function(n,t,e){n.exports=e(0)}]);
|
BIN
demo/dist/js/main.js.gz28ac7f3ef78eb7e2a737
vendored
Normal file
BIN
demo/dist/js/main.js.gz28ac7f3ef78eb7e2a737
vendored
Normal file
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "example-using-inject",
|
"name": "example-using-inject",
|
||||||
"version": "0.13.36",
|
"version": "0.14.0",
|
||||||
"description": "This is an example how to use webpack-auto-inject-version plugin in webpack",
|
"description": "This is an example how to use webpack-auto-inject-version plugin in webpack",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack --config ./webpack.conf.js",
|
"start": "webpack --config ./webpack.conf.js",
|
||||||
|
@ -11,9 +11,11 @@
|
||||||
"author": "Radoslaw Swiat",
|
"author": "Radoslaw Swiat",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"compression-webpack-plugin": "^1.1.11",
|
||||||
"html-loader": "^0.4.5",
|
"html-loader": "^0.4.5",
|
||||||
"html-minify-loader": "^1.1.0",
|
"html-minify-loader": "^1.1.0",
|
||||||
"raw-loader": "^0.5.1",
|
"raw-loader": "^0.5.1",
|
||||||
|
"uglifyjs-webpack-plugin": "^1.2.3",
|
||||||
"webpack": "^2.3.3",
|
"webpack": "^2.3.3",
|
||||||
"webpack-auto-inject-version": "^0.5.10"
|
"webpack-auto-inject-version": "^0.5.10"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
const CompressionPlugin = require('compression-webpack-plugin');
|
||||||
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||||
|
|
||||||
// Require WebpackAutoInject from npm installed modules ( preferred )
|
// Require WebpackAutoInject from npm installed modules ( preferred )
|
||||||
// var WebpackAutoInject = require('webpack-auto-inject-version');
|
// var WebpackAutoInject = require('webpack-auto-inject-version');
|
||||||
// Require WebpackAutoInject from dist - dev purpose only ( do not use the below line )
|
// Require WebpackAutoInject from dist - dev purpose only ( do not use the below line )
|
||||||
const WebpackAutoInject = require('../dist/WebpackAutoInjectVersion');
|
const WebpackAutoInject = require('../dist/WebpackAutoInjectVersion');
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
watch: true,
|
watch: true,
|
||||||
entry: {
|
entry: {
|
||||||
|
@ -14,10 +18,12 @@ module.exports = {
|
||||||
extensions: ['.js', '.html'],
|
extensions: ['.js', '.html'],
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: 'js/[name].js?[chunkhash]',
|
// filename: '[name]-bundle.js',
|
||||||
|
// path: path.resolve(process.cwd(), 'dist'),
|
||||||
|
// publicPath: '/', // Public path to 'dist' scope in production
|
||||||
|
filename: 'js/main.js?[chunkhash]',
|
||||||
path: path.resolve(process.cwd(), 'dist'),
|
path: path.resolve(process.cwd(), 'dist'),
|
||||||
chunkFilename: 'js/[id].js?[chunkhash]',
|
chunkFilename: 'js/main.js?[chunkhash]',
|
||||||
publicPath: '/', // Public path to 'dist' scope in production
|
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
|
@ -61,5 +67,9 @@ module.exports = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new CompressionPlugin({
|
||||||
|
algorithm: 'gzip',
|
||||||
|
}),
|
||||||
|
new UglifyJsPlugin(),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
2397
dist/WebpackAutoInjectVersion.js
vendored
2397
dist/WebpackAutoInjectVersion.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "webpack-auto-inject-version",
|
"name": "webpack-auto-inject-version",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"repository": "radswiat/webpack-auto-inject-version",
|
"repository": "radswiat/webpack-auto-inject-version",
|
||||||
"description": "Webpack plugin for auto inject version from package.json",
|
"description": "Webpack plugin for auto inject version from package.json",
|
||||||
"main": "dist/WebpackAutoInjectVersion.js",
|
"main": "dist/WebpackAutoInjectVersion.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "babel-node tools/compile.js",
|
"start": "babel-node tools/compile.js",
|
||||||
|
"start:watch": "babel-node tools/compile-watch.js",
|
||||||
"eslint": "eslint ./src/**"
|
"eslint": "eslint ./src/**"
|
||||||
},
|
},
|
||||||
"author": "Radoslaw Swiat",
|
"author": "Radoslaw Swiat",
|
||||||
|
|
34
scrapyard/webpack-optimize-chunk-assets-hook.js
Normal file
34
scrapyard/webpack-optimize-chunk-assets-hook.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// 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();
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// });
|
|
@ -1,6 +1,7 @@
|
||||||
import semver from 'semver';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
|
import semver from 'semver';
|
||||||
import { isArgv } from 'core/utils';
|
import { isArgv } from 'core/utils';
|
||||||
import log from 'core/log';
|
import log from 'core/log';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
|
@ -15,20 +16,24 @@ export default class AutoIncreaseVersion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply will be called from main class
|
* Apply will be called from main class
|
||||||
|
*
|
||||||
* @protected
|
* @protected
|
||||||
* @returns {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
apply() {
|
apply() {
|
||||||
|
|
||||||
|
// setup promise
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
this.resolve = resolve;
|
||||||
|
this.reject = reject;
|
||||||
|
});
|
||||||
|
|
||||||
// when runInWatchMode
|
// when runInWatchMode
|
||||||
// we have to register AutoIncreaseVersion instead of firing it straight away
|
// we have to register AutoIncreaseVersion instead of firing it straight away
|
||||||
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
|
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
|
||||||
if (this.context.compiler) {
|
if (this.context.compiler) {
|
||||||
this.context.compiler.plugin('emit', async (compilation, cb) => {
|
this.context.compiler.plugin('emit', (compilation, cb) => {
|
||||||
await new Promise((resolve, reject) => {
|
this.start();
|
||||||
this.resolve = resolve;
|
|
||||||
this.reject = reject;
|
|
||||||
this.start();
|
|
||||||
});
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -36,11 +41,8 @@ export default class AutoIncreaseVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
// when runInWatchMode is off
|
// when runInWatchMode is off
|
||||||
return new Promise((resolve, reject) => {
|
this.start();
|
||||||
this.resolve = resolve;
|
return promise;
|
||||||
this.reject = reject;
|
|
||||||
this.start();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +67,7 @@ export default class AutoIncreaseVersion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open package file
|
* Open package file
|
||||||
* @returns {any}
|
* @return {any}
|
||||||
*/
|
*/
|
||||||
openPackageFile() {
|
openPackageFile() {
|
||||||
try {
|
try {
|
||||||
|
@ -76,6 +78,7 @@ export default class AutoIncreaseVersion {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +109,7 @@ export default class AutoIncreaseVersion {
|
||||||
* Increase major
|
* Increase major
|
||||||
*/
|
*/
|
||||||
major() {
|
major() {
|
||||||
let newVersion = semver.inc(this.packageFile.version, 'major');
|
const newVersion = semver.inc(this.packageFile.version, 'major');
|
||||||
this.closePackageFile(newVersion);
|
this.closePackageFile(newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +117,7 @@ export default class AutoIncreaseVersion {
|
||||||
* Increase minor
|
* Increase minor
|
||||||
*/
|
*/
|
||||||
minor() {
|
minor() {
|
||||||
let newVersion = semver.inc(this.packageFile.version, 'minor');
|
const newVersion = semver.inc(this.packageFile.version, 'minor');
|
||||||
this.closePackageFile(newVersion);
|
this.closePackageFile(newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +125,7 @@ export default class AutoIncreaseVersion {
|
||||||
* Increase patch
|
* Increase patch
|
||||||
*/
|
*/
|
||||||
patch() {
|
patch() {
|
||||||
let newVersion = semver.inc(this.packageFile.version, 'patch');
|
const newVersion = semver.inc(this.packageFile.version, 'patch');
|
||||||
this.closePackageFile(newVersion);
|
this.closePackageFile(newVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import log from 'core/log';
|
import log from 'core/log';
|
||||||
|
|
||||||
import tags from './tags';
|
import tags from './tags';
|
||||||
|
|
||||||
const endOfLine = require('os').EOL;
|
const endOfLine = require('os').EOL;
|
||||||
|
@ -20,38 +22,67 @@ export default class InjectAsComment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply will be called from main class
|
* Apply will be called from main class
|
||||||
|
* - hook into webpack emit
|
||||||
|
* - iterate complication.assets files
|
||||||
|
* - handle each file
|
||||||
* @protected
|
* @protected
|
||||||
* @returns {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
apply() {
|
apply() {
|
||||||
|
// bind into emit hook
|
||||||
this.context.compiler.plugin('emit', (compilation, cb) => {
|
this.context.compiler.plugin('emit', (compilation, cb) => {
|
||||||
for (let basename in compilation.assets) {
|
// iterate over all assets file in compilation
|
||||||
let ext = path.extname(basename);
|
for (const basename in compilation.assets) {
|
||||||
let asset = compilation.assets[basename];
|
// bug fix, extname is not able to handle chunk file params index.js?random123
|
||||||
switch (ext) {
|
const ext = path.extname(basename).replace(/(\?)(.){0,}/, '');
|
||||||
case '.js' :
|
const asset = compilation.assets[basename];
|
||||||
this.injectIntoJs(asset);
|
this._handleAssetFile(ext, asset);
|
||||||
break;
|
|
||||||
case '.html' :
|
|
||||||
this.injectIntoHtml(asset);
|
|
||||||
break;
|
|
||||||
case '.css' :
|
|
||||||
this.injectIntoCss(asset);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`);
|
log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`);
|
||||||
}
|
}
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
return new Promise((resolve) => { resolve(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle asset file
|
||||||
|
* - call suitable inject based on file extension
|
||||||
|
* @param ext
|
||||||
|
* @param asset
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_handleAssetFile(ext, asset) {
|
||||||
|
switch (ext) {
|
||||||
|
case '.js': {
|
||||||
|
this.injectIntoJs(asset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '.html': {
|
||||||
|
this.injectIntoHtml(asset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '.css': {
|
||||||
|
this.injectIntoCss(asset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse tags
|
||||||
|
* - parse inject tags eg {version}, {date}
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* @param baseOpen
|
||||||
|
* @param baseClose
|
||||||
|
*
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
parseTags(baseOpen, baseClose) {
|
parseTags(baseOpen, baseClose) {
|
||||||
let tagPattern = this.context.config.componentsOptions.InjectAsComment.tag;
|
let tagPattern = this.context.config.componentsOptions.InjectAsComment.tag;
|
||||||
tagPattern = tagPattern.replace(/(\{([a-zA-Z]+)\})/g, (tag) => {
|
tagPattern = tagPattern.replace(/(\{([a-zA-Z]+)\})/g, (tag) => {
|
||||||
let tagName = tag.replace(/(\{|\})/g, '');
|
const tagName = tag.replace(/(\{|\})/g, '');
|
||||||
if (typeof tags[tagName] === 'function') {
|
if (typeof tags[tagName] === 'function') {
|
||||||
return tags[tagName](this.context);
|
return tags[tagName](this.context);
|
||||||
}
|
}
|
||||||
|
@ -61,18 +92,42 @@ export default class InjectAsComment {
|
||||||
return `${baseOpen} ${tagPattern} ${baseClose}`;
|
return `${baseOpen} ${tagPattern} ${baseClose}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject into css
|
||||||
|
* - inject tag comment into css asset file
|
||||||
|
* - format: / ** .... ** /
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* @param asset
|
||||||
|
*/
|
||||||
injectIntoCss(asset) {
|
injectIntoCss(asset) {
|
||||||
let modAsset = this.parseTags(`/** [${config.SHORT}] `, ' **/ ');
|
let modAsset = this.parseTags(`/** [${config.SHORT}] `, ' **/ ');
|
||||||
modAsset += `${endOfLine} ${asset.source()} `;
|
modAsset += `${endOfLine} ${asset.source()} `;
|
||||||
asset.source = () => modAsset;
|
asset.source = () => modAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject into html
|
||||||
|
* - inject tag comment into html asset file
|
||||||
|
* - format: <!-- ... -->
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* @param asset
|
||||||
|
*/
|
||||||
injectIntoHtml(asset) {
|
injectIntoHtml(asset) {
|
||||||
let modAsset = this.parseTags(`<!-- [${config.SHORT}] `, ' --> ');
|
let modAsset = this.parseTags(`<!-- [${config.SHORT}] `, ' --> ');
|
||||||
modAsset += `${endOfLine} ${asset.source()} `;
|
modAsset += `${endOfLine} ${asset.source()} `;
|
||||||
asset.source = () => modAsset;
|
asset.source = () => modAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject into JS
|
||||||
|
* - inject tag comment into JS asset file
|
||||||
|
* - format: // ...
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* @param asset
|
||||||
|
*/
|
||||||
injectIntoJs(asset) {
|
injectIntoJs(asset) {
|
||||||
let modAsset = this.parseTags(`// [${config.SHORT}] `, ' ');
|
let modAsset = this.parseTags(`// [${config.SHORT}] `, ' ');
|
||||||
modAsset += `${endOfLine} ${asset.source()} `;
|
modAsset += `${endOfLine} ${asset.source()} `;
|
||||||
|
|
|
@ -7,5 +7,5 @@ export default {
|
||||||
},
|
},
|
||||||
date: () => {
|
date: () => {
|
||||||
return dateFormat(new Date(), config.componentsOptions.InjectAsComment.dateFormat);
|
return dateFormat(new Date(), config.componentsOptions.InjectAsComment.dateFormat);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
export default {
|
export default {
|
||||||
NAME: 'Auto Inject Version CONFIG',
|
|
||||||
SHORT: 'AIV_SHORT',
|
SHORT: 'AIV_SHORT',
|
||||||
SILENT: false,
|
SILENT: false,
|
||||||
PACKAGE_JSON_PATH: './package.json',
|
PACKAGE_JSON_PATH: './package.json',
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import config from 'config';
|
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
|
import config from 'config';
|
||||||
import { isArgv } from 'core/utils';
|
import { isArgv } from 'core/utils';
|
||||||
|
|
||||||
const endOfLine = require('os').EOL;
|
const endOfLine = require('os').EOL;
|
||||||
|
|
||||||
class Log {
|
class Log {
|
||||||
|
@ -21,7 +23,7 @@ class Log {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get console log head
|
* Get console log head
|
||||||
* @returns {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getHead() {
|
getHead() {
|
||||||
return endOfLine + chalk.bgYellow.black('[AIV] : ');
|
return endOfLine + chalk.bgYellow.black('[AIV] : ');
|
||||||
|
@ -29,6 +31,7 @@ class Log {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get log text by ID from config file
|
* Get log text by ID from config file
|
||||||
|
* @param id
|
||||||
*/
|
*/
|
||||||
getText(id) {
|
getText(id) {
|
||||||
return config.LOGS_TEXT[id];
|
return config.LOGS_TEXT[id];
|
||||||
|
@ -37,7 +40,7 @@ class Log {
|
||||||
/**
|
/**
|
||||||
* Call any type
|
* Call any type
|
||||||
* @param type
|
* @param type
|
||||||
* @param msg
|
* @param msgId
|
||||||
*/
|
*/
|
||||||
call(type, msgId) {
|
call(type, msgId) {
|
||||||
if (typeof this[type] === 'function') {
|
if (typeof this[type] === 'function') {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
let argv = require('optimist').argv;
|
const argv = require('optimist').argv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get argv from webpack env[argv]
|
* Get argv from webpack env[argv]
|
||||||
* Since webpack 2.0 we have to pass args by the env
|
* Since webpack 2.0 we have to pass args by the env
|
||||||
* example:
|
* example:
|
||||||
* - webpack --config ./webpack.conf.js --env.patch
|
* - webpack --config ./webpack.conf.js --env.patch
|
||||||
|
*
|
||||||
* @param arg
|
* @param arg
|
||||||
* @returns {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
export function isArgv(arg) {
|
export function isArgv(arg) {
|
||||||
if (typeof argv.env === 'undefined') {
|
if (typeof argv.env === 'undefined') {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* global define */
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ export default class WebpackAutoInject {
|
||||||
);
|
);
|
||||||
this.version = packageFile.version;
|
this.version = packageFile.version;
|
||||||
log.call('info', 'AIS_START');
|
log.call('info', 'AIS_START');
|
||||||
this.executeNoneWebpackComponents();
|
this._executeNoneWebpackComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +37,7 @@ export default class WebpackAutoInject {
|
||||||
*/
|
*/
|
||||||
setConfig(userConfig) {
|
setConfig(userConfig) {
|
||||||
this.config = merge(config, userConfig);
|
this.config = merge(config, userConfig);
|
||||||
console.log(this.config);
|
|
||||||
// lets convert all components names to lowercase - to prevent issues
|
// lets convert all components names to lowercase - to prevent issues
|
||||||
this.config.components = transform(this.config.components, (result, val, key) => {
|
this.config.components = transform(this.config.components, (result, val, key) => {
|
||||||
result[key.toLowerCase()] = val;
|
result[key.toLowerCase()] = val;
|
||||||
|
@ -47,12 +48,14 @@ export default class WebpackAutoInject {
|
||||||
* Webpack apply call,
|
* Webpack apply call,
|
||||||
* when webpack is initialized and
|
* when webpack is initialized and
|
||||||
* plugin has been called by webpack
|
* plugin has been called by webpack
|
||||||
* @param compiler
|
*
|
||||||
* @protected
|
* @protected
|
||||||
|
*
|
||||||
|
* @param compiler
|
||||||
*/
|
*/
|
||||||
async apply(compiler) {
|
apply(compiler) {
|
||||||
this.compiler = compiler;
|
this.compiler = compiler;
|
||||||
await this.executeWebpackComponents();
|
this._executeWebpackComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,8 +63,8 @@ export default class WebpackAutoInject {
|
||||||
* - runs as soon as possible,
|
* - runs as soon as possible,
|
||||||
* > without waiting for webpack init
|
* > without waiting for webpack init
|
||||||
*/
|
*/
|
||||||
async executeNoneWebpackComponents() {
|
_executeNoneWebpackComponents() {
|
||||||
await this.executeComponent([AutoIncreaseVersion]);
|
this._executeComponent([AutoIncreaseVersion]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,19 +72,23 @@ export default class WebpackAutoInject {
|
||||||
* - runs when webpack is initialized
|
* - runs when webpack is initialized
|
||||||
* and plugins is called by webpack
|
* and plugins is called by webpack
|
||||||
*/
|
*/
|
||||||
async executeWebpackComponents() {
|
_executeWebpackComponents() {
|
||||||
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
|
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
|
||||||
await this.executeComponent([AutoIncreaseVersion]);
|
this._executeComponent([AutoIncreaseVersion]);
|
||||||
}
|
}
|
||||||
await this.executeComponent([InjectAsComment, InjectByTag]);
|
this._executeComponent([InjectAsComment, InjectByTag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute components,
|
* Execute components,
|
||||||
* - general layer for comp execution
|
* - general layer for comp execution
|
||||||
* - used for both, webpack and non webpack comp
|
* - used for both, webpack and non webpack comp
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* @param components
|
||||||
*/
|
*/
|
||||||
async executeComponent(components) {
|
_executeComponent(components) {
|
||||||
// no more components,
|
// no more components,
|
||||||
// finish
|
// finish
|
||||||
if (!components.length) {
|
if (!components.length) {
|
||||||
|
@ -89,22 +96,22 @@ export default class WebpackAutoInject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// take first component class
|
// take first component class
|
||||||
let ComponentClass = components.shift();
|
const ComponentClass = components.shift();
|
||||||
|
|
||||||
// if component is disabled, call next component
|
// if component is disabled, call next component
|
||||||
if (!this.config.components[ComponentClass.componentName.toLowerCase()]) {
|
if (!this.config.components[ComponentClass.componentName.toLowerCase()]) {
|
||||||
await this.executeComponent(components);
|
this._executeComponent(components);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute component
|
// execute component
|
||||||
let inst = new ComponentClass(this);
|
const inst = new ComponentClass(this);
|
||||||
|
|
||||||
// await for apply to finish
|
// await for apply to finish
|
||||||
await inst.apply();
|
inst.apply();
|
||||||
|
|
||||||
// call next tick
|
// call next tick
|
||||||
await this.executeComponent(components);
|
this._executeComponent(components);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
tools/compile-watch.js
Normal file
17
tools/compile-watch.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import gutil from 'gutil';
|
||||||
|
import webpack from 'webpack';
|
||||||
|
|
||||||
|
import webpackConfig from './webpack.conf';
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
console.log('compiling');
|
||||||
|
const compiler = webpack(webpackConfig);
|
||||||
|
compiler.watch({}, (err, stats) => {
|
||||||
|
gutil.log('[webpack:build]', stats.toString({
|
||||||
|
chunks: false, // Makes the build much quieter
|
||||||
|
colors: true,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
|
@ -1,14 +1,15 @@
|
||||||
import webpack from 'webpack';
|
|
||||||
import gutil from 'gutil';
|
import gutil from 'gutil';
|
||||||
|
import webpack from 'webpack';
|
||||||
|
|
||||||
import webpackConfig from './webpack.conf';
|
import webpackConfig from './webpack.conf';
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
console.log('compiling');
|
console.log('compiling');
|
||||||
let compiler = webpack(webpackConfig);
|
const compiler = webpack(webpackConfig);
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
gutil.log('[webpack:build]', stats.toString({
|
gutil.log('[webpack:build]', stats.toString({
|
||||||
chunks: false, // Makes the build much quieter
|
chunks: false, // Makes the build much quieter
|
||||||
colors: true
|
colors: true,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import path from 'path';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
target: 'node',
|
target: 'node',
|
||||||
entry: ['./src/main.js'],
|
entry: ['./src/webpack-auto-inject.js'],
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js'],
|
extensions: ['.js'],
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue