Merge pull request #40 from radswiat/feature/unit-tests

release/1.2.1
This commit is contained in:
Radek 2018-10-27 19:03:12 +01:00 committed by GitHub
commit 8ebdbfcc0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 15266 additions and 1332 deletions

View File

@ -4,7 +4,8 @@
"plugins": [
"jsdoc",
"import",
"filenames"
"filenames",
"babel"
],
"env": {
"browser": true,
@ -43,6 +44,7 @@
}
},
"rules": {
"babel/arrow-parens": 2,
"spaced-comment": "off",
"no-unused-expressions": "off",
"func-names": "off",

3
.gitignore vendored
View File

@ -1,4 +1,7 @@
.idea/
.vscode/
node_modules/
demo/node_modules/
demo/package-lock.json
demo/dist
npm-debug*

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,13 @@ to prevent stripping out AIV comments eg:
```
# Change log
## [1.2.1] - 27/10/2018
- security updates
## [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

1
demo/README.md Normal file
View File

@ -0,0 +1 @@
# Webpack auto inject testing environment

102
demo/dist/js/main.js vendored
View File

@ -1,2 +1,100 @@
// [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)}]);
/******/ (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.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 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(0);
/***/ })
/******/ ]);

Binary file not shown.

8483
demo/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,20 +3,29 @@
"version": "0.14.0",
"description": "This is an example how to use webpack-auto-inject-version plugin in webpack",
"scripts": {
"start": "webpack --config ./webpack.conf.js",
"start": "nodemon --watch ./webpack.conf.js --exec webpack -- --config ./webpack.conf.js",
"patch": "webpack --config ./webpack.conf.js --env.patch",
"minor": "webpack --config ./webpack.conf.js --env.minor",
"major": "webpack --config ./webpack.conf.js --env.major"
"major": "webpack --config ./webpack.conf.js --env.major",
"test": "./node_modules/.bin/jest --config tools/jest/config/jest-config.js --no-cache --runInBand"
},
"author": "Radoslaw Swiat",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-jest": "^23.6.0",
"chai": "^4.2.0",
"cheerio": "^1.0.0-rc.2",
"clean-webpack-plugin": "^0.1.19",
"compression-webpack-plugin": "^1.1.11",
"html-loader": "^0.4.5",
"html-minify-loader": "^1.1.0",
"html-webpack-plugin": "^3.2.0",
"jest": "^23.6.0",
"nodemon": "^1.18.5",
"raw-loader": "^0.5.1",
"uglifyjs-webpack-plugin": "^1.2.3",
"webpack": "^2.3.3",
"webpack": "^2.7.0",
"webpack-auto-inject-version": "^0.5.10"
}
}

View File

@ -20,5 +20,6 @@
<span>
[AIV]Version {version} , {date}[/AIV]
</span>
<span id="date">[AIV]{date}[/AIV]</span>
</body>
</html>

View File

@ -0,0 +1,6 @@
const fs = require('fs');
const path = require('path');
export default function getDistFile(file) {
return fs.readFileSync(path.resolve(process.cwd(), 'dist', file), 'utf8');
}

View File

@ -0,0 +1,10 @@
const webpack = require('webpack');
export default function webpackCompile(webpackConfig, aivConfig) {
const compiler = webpack(webpackConfig(aivConfig));
return new Promise((resolve) => {
compiler.run(() => {
resolve();
});
});
}

169
demo/tests/test.spec.js Normal file
View File

@ -0,0 +1,169 @@
import webpackCompile from './helpers/webpack-compile';
import getDistFile from './helpers/get-dist-file';
import testWebpackConfigs from './webpack-configs';
import cheerio from 'cheerio';
describe('Inject by tag', () => {
// default inject by tag tests
describe('default', () => {
const config = {
SILENT: true,
components: {
AutoIncreaseVersion: false,
InjectAsComment: false,
InjectByTag: true,
},
componentsOptions: {
InjectByTag: {
dateFormat: '_HH:mm:ss_',
},
},
};
// 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 not include any not parsed tags', async () => {
const distMainJS = getDistFile('js/main.js');
expect(distMainJS).to.not.include('[AIV]');
expect(distMainJS).to.not.include('[/AIV]');
});
it('Should properly parse date', () => {
const distMainJS = getDistFile('js/main.js');
const $ = cheerio.load(distMainJS);
const date = $('#date').text().trim();
expect(/^(_\d\d:\d\d:\d\d_)$/.test(date)).to.be.true;
});
});
}
});
});
});
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');
});
});
}
});
});
});

View File

@ -0,0 +1,58 @@
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
// Require WebpackAutoInject from npm installed modules ( preferred )
// var WebpackAutoInject = require('webpack-auto-inject-version');
// Require WebpackAutoInject from dist - dev purpose only ( do not use the below line )
const WebpackAutoInject = require('../../../dist/WebpackAutoInjectVersion');
module.exports = (autoInjectConfig) => ({
watch: true,
entry: {
index: ['./src/main.js'],
},
resolve: {
extensions: ['.js', '.html'],
},
output: {
// 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'),
chunkFilename: 'js/main.js?[chunkhash]',
},
module: {
loaders: [
{
test: /\.js$/,
include: [
path.resolve('src'),
],
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.txt$/,
loader: 'raw-loader',
},
{
test: /\.html$/,
loader: 'raw-loader!html-minify-loader',
},
],
},
plugins: [
new CleanWebpackPlugin(path.resolve(process.cwd(), 'dist')),
new WebpackAutoInject(autoInjectConfig),
// new CompressionPlugin({
// algorithm: 'gzip',
// }),
// new UglifyJsPlugin(),
],
});

View File

@ -0,0 +1,62 @@
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Require WebpackAutoInject from npm installed modules ( preferred )
// var WebpackAutoInject = require('webpack-auto-inject-version');
// Require WebpackAutoInject from dist - dev purpose only ( do not use the below line )
const WebpackAutoInject = require('../../../dist/WebpackAutoInjectVersion');
module.exports = (autoInjectConfig) => ({
watch: true,
entry: {
index: ['./src/main.js'],
},
resolve: {
extensions: ['.js', '.html'],
},
output: {
// 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'),
chunkFilename: 'js/main.js?[chunkhash]',
},
module: {
loaders: [
{
test: /\.js$/,
include: [
path.resolve('src'),
],
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.txt$/,
loader: 'raw-loader',
},
{
test: /\.html$/,
loader: 'raw-loader!html-minify-loader',
},
],
},
plugins: [
new CleanWebpackPlugin(path.resolve(process.cwd(), 'dist')),
new WebpackAutoInject(autoInjectConfig),
// new CompressionPlugin({
// algorithm: 'gzip',
// }),
// new UglifyJsPlugin(),
new HtmlWebpackPlugin({
template: path.resolve('src', 'index.html'),
}),
],
});

View File

@ -0,0 +1,58 @@
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
// Require WebpackAutoInject from npm installed modules ( preferred )
// var WebpackAutoInject = require('webpack-auto-inject-version');
// Require WebpackAutoInject from dist - dev purpose only ( do not use the below line )
const WebpackAutoInject = require('../../../dist/WebpackAutoInjectVersion');
module.exports = (autoInjectConfig) => ({
watch: true,
entry: {
index: ['./src/main.js'],
},
resolve: {
extensions: ['.js', '.html'],
},
output: {
// 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'),
chunkFilename: 'js/main.js?[chunkhash]',
},
module: {
loaders: [
{
test: /\.js$/,
include: [
path.resolve('src'),
],
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.txt$/,
loader: 'raw-loader',
},
{
test: /\.html$/,
loader: 'raw-loader!html-minify-loader',
},
],
},
plugins: [
new CleanWebpackPlugin(path.resolve(process.cwd(), 'dist')),
new WebpackAutoInject(autoInjectConfig),
new CompressionPlugin({
algorithm: 'gzip',
}),
new UglifyJsPlugin(),
],
});

View File

@ -0,0 +1,9 @@
import confDefault from './conf-default';
import confUglify from './conf-uglify';
import confHtml from './conf-html';
export default [
// ['confUglify', confUglify],
// ['confDefault', confDefault],
['confHtml', confHtml],
];

View File

@ -0,0 +1,7 @@
const path = require('path')
module.exports = {
process (src, filename) {
return `module.exports = ${JSON.stringify(path.basename(filename))};`
}
}

View File

@ -0,0 +1,5 @@
const chai = require('chai');
global.expect = chai.expect;
global.jestExpect = global.expect;

View File

@ -0,0 +1,34 @@
module.exports = {
// root dir
// this is from all paths will be calculated,
// it also specify location of your .spec files!!
// @default '../src/'
rootDir: '../../../',
// should stop after error ?
// keep it off, or you won't see any console.logs!!
// @default: false
bail: false,
// verbose output
// @default: true
verbose: true,
// collect coverage
// @default: true
collectCoverage: false,
// ignored paths
modulePathIgnorePatterns: [
// '<rootDir>/something/',
],
// jest reporters
// define reports format
// @default: 'default' & 'json'
reporters: [
'default',
],
// testEnvironment: 'jsdom',
setupTestFrameworkScriptFile: '<rootDir>tools/jest/config/framework-config.js',
transform: {
'^.+.(js|jsx)$': 'babel-jest',
// '^.+.(css|scss)': '<rootDir>tools/unit-tests/jest/compilers/css-transform.js',
// '^(?!.*.(js|jsx|css|scss|json)$)': '<rootDir>tools/unit-tests/jest/compilers/file-transform.js'
},
};

View File

@ -2,6 +2,7 @@ const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin')
// Require WebpackAutoInject from npm installed modules ( preferred )
// var WebpackAutoInject = require('webpack-auto-inject-version');
@ -48,28 +49,37 @@ module.exports = {
],
},
plugins: [
new CleanWebpackPlugin(path.resolve(process.cwd(), 'dist')),
new WebpackAutoInject({
components: {
AutoIncreaseVersion: true,
InjectAsComment: true,
InjectByTag: true,
InjectAsComment: false,
},
componentsOptions: {
AutoIncreaseVersion: {
runInWatchMode: false, // it will increase version with every single build!
},
InjectAsComment: {
tag: 'Version: {version}, {date}',
},
InjectByTag: {
fileRegex: /\.+/,
dateFormat: 'h:MM:ss',
},
},
// components: {
// AutoIncreaseVersion: true,
// InjectAsComment: true,
// InjectByTag: true,
// },
// componentsOptions: {
// AutoIncreaseVersion: {
// runInWatchMode: false, // it will increase version with every single build!
// },
// InjectAsComment: {
// tag: 'Version: {version}, {date}',
// },
// InjectByTag: {
// fileRegex: /\.+/,
// dateFormat: 'h:MM:ss',
// },
// },
}),
new CompressionPlugin({
algorithm: 'gzip',
}),
new UglifyJsPlugin(),
// new CompressionPlugin({
// algorithm: 'gzip',
// }),
// new UglifyJsPlugin(),
],
};

File diff suppressed because it is too large Load Diff

6349
package-lock.json generated Normal file

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.1",
"repository": "radswiat/webpack-auto-inject-version",
"description": "Webpack plugin for auto inject version from package.json",
"main": "dist/WebpackAutoInjectVersion.js",
@ -27,14 +27,14 @@
"eslint": "^2.7.0",
"eslint-config-airbnb": "^6.2.0",
"eslint-loader": "^1.5.0",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-filenames": "^1.2.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jsdoc": "^3.5.0",
"eslint-plugin-jsx-control-statements": "^2.1.1",
"eslint-plugin-react": "^4.2.3",
"gutil": "^1.6.4",
"lodash": "^4.17.4",
"lodash": "^4.17.11",
"optimist": "^0.6.1",
"semver": "^5.3.0",
"webpack": "^2.3.3",

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;