Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace dependancy depreications #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.log
package-lock.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ npm install gulp-html2string
In your project's gulpfile.js, create the following task:

```javascript

const path = require('path');
var html2string = require('gulp-html2string');
var rename = require("gulp-rename");

gulp.task('html2js', function () {
return gulp.src('html/*.html')
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

'use strict';
var map = require('map-stream');
var gutil = require('gulp-util');
var compile = require('./lib/compile');

module.exports = function(options) {
Expand Down
14 changes: 9 additions & 5 deletions lib/compile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var path = require('path');
var minify = require('html-minifier').minify;
var utils = require('./utils');
var gutil = require('gulp-util');
//var gutil = require('gulp-util');
var log = require("fancy-log");

var escapeContent = function(content, quoteChar, indentString) {
var bsRegexp = new RegExp('\\\\', 'g');
Expand All @@ -26,7 +27,7 @@ var getContent = function(contents, quoteChar, indentString, htmlmin) {
try{
content = minify(content, htmlmin);
} catch(err) {
gutil.log(filepath + '\n' + err);
log(filepath + '\n' + err);
}
}

Expand Down Expand Up @@ -60,15 +61,18 @@ module.exports = function(file, options, callback) {
options.target= options.target || 'js';
options.htmlmin= options.htmlmin || {};
options.useStrict= options.useStrict || false;
options.templateName = options.templateName || false;

function getModule(filepath) {

var templateName = path.relative(options.base, filepath);
if (!options.templateName) {
options.templateName = file.stem;
}

if (options.target === 'js') {
return compileTemplate(options.objName, options.createObj, templateName, file.contents.toString(), options.quoteChar, options.indentString, options.useStrict, options.htmlmin);
return compileTemplate(options.objName, options.createObj, options.templateName, file.contents.toString(), options.quoteChar, options.indentString, options.useStrict, options.htmlmin);
} else {
gutil.log('Unknow target "' + options.target + '" specified');
log('Unknow target "' + options.target + '" specified');
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
*/

var gutil = require('gulp-util');
var fs = require('fs');
var path = require('path');

Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "gulp-html2string",
"version": "0.1.1",
"version": "0.2.1",
"description": "Converts static HTML templates to JavaScript strings.",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"engines": {
"node": ">=0.10.0"
"node": ">=8.10.0"
},
"repository": {
"type": "git",
Expand All @@ -23,21 +23,24 @@
],
"contributors": [
"Xiyang Chen <[email protected]>",
"xvfeng"
"xvfeng",
"AQuietDoggo <[email protected]>"
],
"license": "GPLv3",
"license": "MIT",
"bugs": {
"url": "https://github.com/Rise-Vision/gulp-html2string/issues"
},
"homepage": "https://github.com/Rise-Vision/gulp-html2string",
"devDependencies": {
"mocha": "~1.20.1"
"mocha": "^5.2.0"
},
"dependencies": {
"gulp": "~3.8.1",
"gulp-util": "~2.2.17",
"html-minifier": "^0.6.2",
"fancy-log": "^1.3.3",
"gulp": "^4.0.0",
"html-minifier": "^3.5.21",
"map-stream": "^0.1.0",
"through2": "~0.5.1"
"minimatch": "^3.0.4",
"through2": "~0.5.1",
"vinyl": "^2.2.0"
}
}
19 changes: 11 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
'use strict';

var assert = require('assert');
var gutil = require('gulp-util');
//var gutil = require('gulp-util');
var vinyl = require("vinyl");
var templateStrBuilder = require('../index.js');
var join = require('path').join;
var fs = require('fs');

it('should compile HTML templates', function (cb) {
var stream = templateStrBuilder({objName: 'TEH_TEMPLATES', createObj: true, base: __dirname});
var stream = templateStrBuilder({objName: 'TEH_TEMPLATES', createObj: true, base: __dirname, templateName:"test"});

stream.on('data', function (data) {
assert.equal(data.contents.toString(),
'if(typeof TEH_TEMPLATES === \'undefined\') {var TEH_TEMPLATES = {};}\n' +
'TEH_TEMPLATES[\'' + 'test-template.html' + '\'] = "<html>\\n" +' +
'TEH_TEMPLATES[\'' + 'test' + '\'] = "<html>\\n" +' +
'\n "<head></head>\\n" +' +
'\n "<body class=\\\"hello\\\">Test, \'single quote\', \\\"double quote\\\"<body>\\n" +' +
'\n "</html>\\n" +' +
'\n ""; ');
cb();
});

stream.write(new gutil.File({
path: join(__dirname, './test-template.html'),
contents: fs.readFileSync(join(__dirname, './test-template.html'))
}));
var htmlTemplate = new vinyl({
'base' : __dirname,
'path' : './test/test-template.html',
'contents' : fs.readFileSync(join(__dirname, './test-template.html'))
});

stream.write(htmlTemplate);

stream.end();
});
Expand Down