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

htmlprocessor

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlprocessor - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

10

index.js

@@ -15,3 +15,3 @@ /*

var HTMLProcessor = require('./lib/htmlprocessor');
var utils = require('./lib/utils')
var utils = require('./lib/utils');

@@ -51,2 +51,7 @@ module.exports = function (files, options) {

// create options.list directory if needed
if (options && options.list) {
utils.mkdir(path.dirname(options.list));
}
files.src.forEach(function (filepath) {

@@ -58,3 +63,6 @@ var content = html.process(filepath);

console.log('File', '"' + dest + '"', 'created.');
if (options && options.list) {
console.log('File', '"' + options.list + '"', 'created.');
}
});
};

9

lib/blocktypes.js

@@ -110,5 +110,4 @@ /*

remove: function (content, block, blockLine, blockContent) {
var blockRegExp = utils.blockToRegExp(blockLine);
return content.replace(blockRegExp, '');
// Replace blockLine with surrounding new line symbols with empty string
return content.split(this.linefeed + blockLine + this.linefeed).join('');
},

@@ -120,3 +119,3 @@

// Clean template output and fix indent
compiledTmpl = block.indent + compiledTmpl.trim().replace(/([\r\n])\s*/g, '$1' + block.indent);
compiledTmpl = block.indent + compiledTmpl.trim().replace(/(\r\n|\n)\s*/g, '$1' + block.indent);

@@ -143,3 +142,3 @@ return content.replace(blockLine, compiledTmpl.replace(/\$/g, '$$$'));

// Add indentation and remove any last new line
fileContent = block.indent + fileContent.replace(/\r\n$/, '');
fileContent = block.indent + fileContent.replace(/(\r\n|\n)$/, '');

@@ -146,0 +145,0 @@ while ((i = content.indexOf(blockLine)) !== -1) {

@@ -16,4 +16,5 @@ /*

var blockTypes = require('./blocktypes');
var listFile = null;
var getBlocks = function (content, marker) {
var getBlocks = function (content, marker, filepath) {
/*

@@ -30,2 +31,8 @@ * <!-- build:<type>[:target] [value] -->

// <link rel="stylesheet" href="js/bower_components/bootstrap/dist/css/bootstrap.css" />
var cssHref = new RegExp('^\\s*<\\s*\\LINK.*HREF=["' + "'" + ']([^"' + "'" + ']*)["' + "'" + '].*$', 'i');
// <script src="js/bower_components/xdate/src/xdate.js"></script>
var jsSrc = new RegExp('^\\s*<\\s*\\SCRIPT.*SRC=["' + "'" + ']([^"' + "'" + ']*)["' + "'" + '].*$', 'i');
// Normalize line endings and split in lines

@@ -58,2 +65,15 @@ var lines = content.replace(/\r\n/g, '\n').split(/\n/);

block.raw.push(line);
if (listFile) {
var match = line.match(cssHref);
if (match != null) {
//call the write option where you need to append new data
listFile.write(filepath + ":" + match[1] + "\n");
}
else {
match = line.match(jsSrc);
if (match != null) {
listFile.write(filepath + ":" + match[1] + "\n");
}
}
}
}

@@ -125,4 +145,3 @@

var blockContent = this._getBlockContent(block);
var blockRegExp = utils.blockToRegExp(blockLine);
var result = content.replace(blockRegExp, '\r\n\r\n' + blockContent);
var result = content.split(blockLine).join(blockContent);

@@ -160,7 +179,16 @@ return result;

if (this.options && this.options.list) {
//Set our log file as a writestream variable with the 'a' flag
listFile = fs.createWriteStream(this.options.list, {
flags: "a",
encoding: "encoding",
mode: parseInt('744', 8)
});
}
// Parse the file content to look for build comment blocks
var blocks = getBlocks(this.content, this.options.commentMarker);
var blocks = getBlocks(this.content, this.options.commentMarker, filepath);
// Replace found blocks
var content = this._replaceBlocks(blocks, filepath);
content = this._replaceBlocks(blocks, filepath);

@@ -167,0 +195,0 @@ return content;

@@ -18,11 +18,2 @@ /*

var escapeRegExp = function (str) {
return str.replace(/([.?*+\^=!:$\[\]\\(){}|\-])/g, '\\$1');
};
utils.blockToRegExp = function (blockLine) {
var escaped = escapeRegExp(blockLine);
return new RegExp(escaped.replace(/^\s*|[\r\n]+\s*/g, '\\s*').replace(/\n{1}$/g, '\\n'));
};
utils.read = function (filepath, encoding) {

@@ -35,3 +26,3 @@ var contents;

}
return contents.replace(/\r\n|\r/g, '\n');
return contents;
};

@@ -38,0 +29,0 @@

{
"name": "htmlprocessor",
"description": "Process html file using special comments",
"version": "0.1.9",
"version": "0.1.10",
"author": {

@@ -6,0 +6,0 @@ "name": "Denis Ciccale",

@@ -53,3 +53,112 @@ # htmlprocessor [![Build Status](https://travis-ci.org/dciccale/node-htmlprocessor.svg?branch=master)](https://travis-ci.org/dciccale/node-htmlprocessor) [![NPM version](https://badge.fury.io/js/htmlprocessor.png)](http://badge.fury.io/js/htmlprocessor)

## New option
Create a list of files that were replaced and use that list to streamline the build process.
Note: This new option does not affect in any way the previous existing functionality (i.e. it's backward compatible).
```bash
$ htmlprocessor file-to-process.html -o processed/file.html --list wrk/replacement.list
```
Assumning you have this code in an HTML (or JSP)
```bash
.
.
.
<!-- build:css content/myApplication.min.css -->
<link rel="stylesheet" href="js/bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="content/bootstrap-responsive.min.css" needed />
<link rel="stylesheet" href="js/bower_components/angular-date-range-picker/build/angular-date-range-picker.css" />
<link rel="stylesheet" href="js/bower_components/angular-grid/ng-grid.css" />
<link rel="stylesheet" href="content/styles.css" />
<link rel="stylesheet" href="content/myApplicationStyles.css" />
<link rel="stylesheet" href="content/angular-slider.css" />
<!--/build-->
.
.
.
<!-- build:js js/myApplication.min.js -->
<script src="js/bower_components/jquery/dist/jquery.js"></script>
<script src="js/bower_components/angular/angular.js"></script>
<script src="js/bower_components/angular-route/angular-route.js"></script>
<script src="js/bower_components/angular-animate/angular-animate.js"></script>
<script src="js/bower_components/angular-touch/angular-touch.js"></script>
<script src="js/angular-slider.js"></script>
<script src="js/bindonce.js"></script>
<script src="js/bower_components/angular-cookies/angular-cookies.js"></script>
<script src="js/bower_components/xdate/src/xdate.js"></script>
<script src="js/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="js/bower_components/angular-grid/build/ng-grid.js"></script>
<script src="js/bower_components/angular-google-chart/ng-google-chart.js"></script>
<script src="js/bower_components/clone/clone.js"></script>
<!-- App libs -->
<script src="app/app.js"></script>
<script src="app/filters/filters.js"></script>
<script src="app/services/services.js"></script>
<script src="app/directives/various.js"></script>
<script src="app/controllers/controllers.js"></script>
<script src="app/controllers/settings.js"></script>
<script src="app/controllers/time.js"></script>
<script src="app/controllers/applications.js"></script>
<!--/build-->
.
.
.
```
The file "wrk/replacement.list" will contain something like this:
```bash
file-to-process.html:js/bower_components/bootstrap/dist/css/bootstrap.css
file-to-process.html:content/bootstrap-responsive.min.css
file-to-process.html:js/bower_components/angular-date-range-picker/build/angular-date-range-picker.css
file-to-process.html:js/bower_components/angular-grid/ng-grid.css
file-to-process.html:content/styles.css
file-to-process.html:content/myApplicationStyles.css
file-to-process.html:content/angular-slider.css
file-to-process.html:js/bower_components/jquery/dist/jquery.js
file-to-process.html:js/bower_components/angular/angular.js
file-to-process.html:js/bower_components/angular-route/angular-route.js
file-to-process.html:js/bower_components/angular-animate/angular-animate.js
file-to-process.html:js/bower_components/angular-touch/angular-touch.js
file-to-process.html:js/angular-slider.js
file-to-process.html:js/bindonce.js
file-to-process.html:js/bower_components/angular-cookies/angular-cookies.js
file-to-process.html:js/bower_components/xdate/src/xdate.js
file-to-process.html:js/bower_components/angular-bootstrap/ui-bootstrap-tpls.js
file-to-process.html:js/bower_components/angular-grid/build/ng-grid.js
file-to-process.html:js/bower_components/angular-google-chart/ng-google-chart.js
file-to-process.html:js/bower_components/clone/clone.js
file-to-process.html:app/app.js
file-to-process.html:app/filters/filters.js
file-to-process.html:app/services/services.js
file-to-process.html:app/directives/various.js
file-to-process.html:app/controllers/controllers.js
file-to-process.html:app/controllers/settings.js
file-to-process.html:app/controllers/time.js
file-to-process.html:app/controllers/applications.js
```
And you can use these commands to concatenate and eventually minify without having to update the build to tell
it where it should pickup each files. Also, in this way it orders the global file content in the same manner
as your individual includes originally were.
```bash
bash -c "cat `cat wrk/replacement.list | grep '\.js$' | cut -d: -f2` > dist/js/myApplication.js"
bash -c "cat `cat wrk/replacement.list | grep '\.css$' | cut -d: -f2` > dist/css/myApplication.css"
```
If you processed more than a single "html" file, you can change the grep like this:
```bash
... | grep 'file-to-process.html:.*\.js$' | ... > dist/js/myApplication.js
... | grep 'other-file-to-process.html:.*\.js$' | ... > dist/js/myApplicationOther.js
```
The originating file name is included in the list file for that very purpose.
## License
See [LICENSE.txt](https://raw.github.com/dciccale/node-htmlprocessor/master/LICENSE-MIT)

Sorry, the diff of this file is not supported yet

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