Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpack-auto-inject-version

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-auto-inject-version - npm Package Compare versions

Comparing version 0.1.13 to 0.2.0

dist/components/inject-as-comment.js

9

dist/components/auto-inc-version.js

@@ -8,2 +8,3 @@ var semver = require('semver');

var Promise = require('bluebird');
var log = require('../core/log');
var IncVersion = (function () {

@@ -23,3 +24,2 @@ function IncVersion(context) {

this.packageFile = this.openPackageFile();
var argv = process.argv;
if (u.isArgv('major')) {

@@ -35,4 +35,2 @@ this.major();

else {
console.log(chalk.bgRed("[@] " + config.SHORT + " error > ") + ' --major --minor --patch missing in arguments. ');
console.log(chalk.bgRed("[@] " + config.SHORT + " how to> ") + ' webpack -w --major');
this.reject();

@@ -52,4 +50,5 @@ }

}
console.log('');
console.log(chalk.bgGreen("[@] " + config.SHORT + " OK > ") + ' package.json updated : ' + _this.packageFile.version);
log.info("autoIncVersion : new version : " + newVersion);
log.info('package.json updated!');
_this.context.version = newVersion;
_this.resolve();

@@ -56,0 +55,0 @@ });

@@ -5,16 +5,21 @@ module.exports = {

PATH_PACKAGE: './package.json',
COMPONENTS: [
NON_WEBPACK_COMPONENTS: [
{
option: 'autoIncrease',
path: './components/auto-inc-version'
},
}
],
WEBPACK_COMPONENTS: [
{
option: 'injectIntoHtml',
path: './components/inject-into-html'
option: 'injectByTag',
path: './components/inject-by-tag'
},
{
option: 'injectIntoAnyFile',
path: './components/inject-into-any-file'
option: 'injectAsComment',
path: './components/inject-as-comment'
}
]
],
LOGS_TEXT: {
AIS_START: 'Auto inject version started'
}
};

@@ -7,2 +7,3 @@ var chalk = require('chalk');

var u = require('./core/utils');
var log = require('./core/log');
'use strict';

@@ -14,30 +15,38 @@ var WebpackAutoInject = (function () {

this.version = packageFile.version;
log.call('info', 'AIS_START');
this.executeNoneWebpackComponents();
}
WebpackAutoInject.prototype.apply = function (compiler) {
this.compiler = compiler;
this.components = config.COMPONENTS;
this.executeComponents();
this.executeWebpackComponents();
};
WebpackAutoInject.prototype.executeComponents = function () {
WebpackAutoInject.prototype.executeNoneWebpackComponents = function () {
this.executeComponents(config.NON_WEBPACK_COMPONENTS, function () {
});
};
WebpackAutoInject.prototype.executeWebpackComponents = function () {
this.executeComponents(config.WEBPACK_COMPONENTS, function () {
});
};
WebpackAutoInject.prototype.executeComponents = function (components, done) {
var _this = this;
if (!this.components.length) {
console.log(chalk.bgRed('AIS: DONE!'));
if (!components.length) {
done();
return;
}
var comp = this.components.shift();
if (this.options[comp.option]) {
var inst = new (require(comp.path))(this);
inst.apply().then(function () {
_this.executeComponents();
}, function (err) { console.log(err); });
var comp = components.shift();
if (!this.options[comp.option]) {
this.executeComponents(components, done);
return;
}
else {
this.executeComponents();
}
var inst = new (require(comp.path))(this);
inst.apply().then(function () {
_this.executeComponents(components, done);
}, function (err) { _this.executeComponents(components, done); });
};
WebpackAutoInject.options = {
autoIncrease: true,
injectIntoHtml: true,
injectIntoHtmlRegex: /^index\.html$/,
injectIntoAnyFile: true
injectAsComment: true,
injectByTag: true,
injectByTagFileRegex: /^index\.html$/
};

@@ -44,0 +53,0 @@ return WebpackAutoInject;

{
"name": "webpack-auto-inject-version",
"version": "0.1.13",
"version": "0.2.0",
"repository": "radswiat/webpack-auto-inject-version",

@@ -13,3 +13,2 @@ "description": "Webpack plugin for auto inject version from package.json",

"devDependencies": {
"chalk": "^1.1.3",
"typings": "^1.4.0"

@@ -19,4 +18,5 @@ },

"bluebird": "^3.4.6",
"semver": "^5.3.0"
"semver": "^5.3.0",
"chalk": "^1.1.3"
}
}
# In development
## What
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 any place in your HTML by special tag <{version}>
- inject version from package.json into any place in CSS/JS file by special tag <{version}>
- auto increase version by --major, --minor, --patch and then inject as chosen
## Desc
AIV can inject version number for all your bundle files (css,js,html).<br><br>

@@ -41,12 +48,5 @@ Example js:

module.exports = {
plugins: [
new WebpackAutoInject({
autoIncrease : boolean,
injectIntoHtml : boolean,
injectIntoHtmlRegex : regex,
injectIntoAnyFile : boolean
})
new WebpackAutoInject(options)
]
}

@@ -58,9 +58,7 @@ ```

## Options
By default you don't need to pass any options, all options from Usage section are set by default.<br><br>
<br>
### autoIncrease
Auto increase package.json number. <br>
This option requires extra argument to be sent to webpack build. <br>
It happens before anything else to make sure that your new version is injected into your files.<br>
Arguments: --major --minor --patch<br><br>

@@ -81,9 +79,11 @@

### injectIntoHtml
Inject version number ( increased if autoIncrease is set correctly ) into HTML template<br>
For this to work you need to place <{version}> inside your html file.<br><br>
Example:
### injectByTag
Inject version number into your file<br>
Version will replace the <{version}> tag.<br>
```html
<span>My awesome project | <{version}></span>
```
```js
var version = '<{version}>';
```
Default: true

@@ -95,4 +95,7 @@

### injectIntoHtmlRegex
Regex to find your html file, where injectIntoHtml should try to find your <{version}> tag.<br>
### injectByTagFileRegex
Regex against file name. If match, injectByTag will try to find version tag and replace it.
Only html files: /^(.){1,}\.html$/ <br>
Only js files: ^(.){1,}\.js$ <br>
Any file: (.){1,} <br>
Default: /^index\.html$/

@@ -104,4 +107,4 @@

### injectIntoAnyFile
This will inject your version file as a comment into any css,js,html file.<br>
### injectAsComment
This will inject your version as a comment into any css,js,html file.<br>
Default: true

@@ -1,8 +0,9 @@

var semver = require('semver');
var config = require('../config');
var path = require('path');
var fs = require('fs');
var u = require('../core/utils');
var chalk = require('chalk');
var Promise = require('bluebird');
const semver = require('semver');
const config = require('../config');
const path = require('path');
const fs = require('fs');
const u = require('../core/utils');
const chalk = require('chalk');
const Promise = require('bluebird');
const log = require('../core/log');

@@ -31,3 +32,2 @@ class IncVersion{

this.packageFile = this.openPackageFile();
let argv = process.argv;
if( u.isArgv('major') ) {

@@ -41,4 +41,2 @@ this.major();

}else {
console.log(chalk.bgRed(`[@] ${config.SHORT} error > `)+' --major --minor --patch missing in arguments. ');
console.log(chalk.bgRed(`[@] ${config.SHORT} how to> `)+' webpack -w --major');
this.reject();

@@ -64,4 +62,5 @@ }

if(err) {this.reject(err); return console.log(err);}
console.log('');
console.log(chalk.bgGreen(`[@] ${config.SHORT} OK > `)+' package.json updated : ' + this.packageFile.version);
log.info(`autoIncVersion : new version : ${newVersion}`)
log.info('package.json updated!');
this.context.version = newVersion;
this.resolve();

@@ -68,0 +67,0 @@ });

@@ -5,16 +5,21 @@ module.exports = {

PATH_PACKAGE : './package.json',
COMPONENTS : [
NON_WEBPACK_COMPONENTS : [
{
option : 'autoIncrease',
path : './components/auto-inc-version'
},
}
],
WEBPACK_COMPONENTS : [
{
option : 'injectIntoHtml',
path : './components/inject-into-html'
option : 'injectByTag',
path : './components/inject-by-tag'
},
{
option : 'injectIntoAnyFile',
path : './components/inject-into-any-file'
option : 'injectAsComment',
path : './components/inject-as-comment'
}
]
],
LOGS_TEXT : {
AIS_START : 'Auto inject version started'
}
}
/// <reference path='../typings/index.d.ts' />
var chalk = require('chalk');
var fs = require('fs');
var path = require('path');
var config = require('./config');
var Promise = require('bluebird');
var u = require('./core/utils');
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const config = require('./config');
const Promise = require('bluebird');
const u = require('./core/utils');
const log = require('./core/log');

@@ -16,11 +17,18 @@ 'use strict';

private version;
private components;
/**
* Default options
*/
static options = {
autoIncrease : true,
injectIntoHtml : true,
injectIntoHtmlRegex : /^index\.html$/,
injectIntoAnyFile : true
injectAsComment : true,
injectByTag : true,
injectByTagFileRegex : /^index\.html$/
}
/**
* Constructor,
* called on webpack config load
* @param options
*/
constructor(options) {

@@ -30,28 +38,62 @@ this.options = u.merge(WebpackAutoInject.options, options);

this.version = packageFile.version;
log.call('info', 'AIS_START');
this.executeNoneWebpackComponents();
}
/**
* Webpack apply call,
* when webpack is initialized and
* plugin has been called by webpack
* @param compiler
*/
protected apply(compiler) {
this.compiler = compiler;
this.executeWebpackComponents();
}
this.components = config.COMPONENTS;
/**
* Execute none webpack components
* - runs as soon as possible,
* > without waiting for webpack init
*/
private executeNoneWebpackComponents() {
this.executeComponents(config.NON_WEBPACK_COMPONENTS, () => {
});
}
this.executeComponents();
/**
* Execute webpack components
* - runs when webpack is initialized
* and plugins is called by webpack
*/
private executeWebpackComponents() {
this.executeComponents(config.WEBPACK_COMPONENTS, () => {
});
}
private executeComponents() {
/**
* Execute components,
* - general layer for comp execution
* - used for both, webpack and non webpack comp
*/
private executeComponents(components, done) {
if(!this.components.length) { console.log(chalk.bgRed('AIS: DONE!')); return;}
// no more components,
// finish
if(!components.length) { done(); return;}
let comp = this.components.shift();
// take first component
let comp = components.shift();
if(this.options[comp.option]) {
let inst = new (require(comp.path))(this);
inst.apply().then(() => {
this.executeComponents();
}, (err) => {console.log(err);})
}else{
this.executeComponents();
// if component is disabled, call next component
if(!this.options[comp.option]) {
this.executeComponents(components, done);
return;
}
// execute component
let inst = new (require(comp.path))(this);
inst.apply().then(() => {
this.executeComponents(components, done);
}, (err) => {this.executeComponents(components, done);})
}

@@ -58,0 +100,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc