Skip to content

Commit

Permalink
Issue #386 [Enhancement][WIP] Add @thin-hook/demo-convert-skinny and …
Browse files Browse the repository at this point in the history
…@thin-hook/demo-convert-full plugins
  • Loading branch information
t2ym committed Sep 11, 2020
1 parent 73b4cb1 commit 9eaa35b
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 42 deletions.
44 changes: 2 additions & 42 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,9 @@ let currentHtml = '';
let lastJs = 'old';
let currentJs = '';

gulp.task('demo:convert:skinny', () => {
return gulp.src([ 'demo/**/*' ], { base: 'demo' })
.pipe(through.obj((file, enc, callback) => {
if (file.path.match(/\.html$/)) {
let html = String(file.contents);
html = html.replace(/<!--__BEGIN__-->/g, '<!--{{{').replace(/<!--__END__-->/g, '}}}-->').replace(/\/\*__BEGIN__\*\//g, '/*{{{').replace(/\/\*__END__\*\//g, '}}}*/');
file.contents = new Buffer(html);
callback(null, file);
}
else if (file.path.match(/\.js$/)) {
let js = String(file.contents);
js = js.replace(/\/\*__BEGIN__\*\//g, '/*{{{').replace(/\/\*__END__\*\//g, '}}}*/');
file.contents = new Buffer(js);
callback(null, file);
}
else {
callback(null, null);
}
}))
.pipe(gulp.dest('demo'))
});
gulp.task('@thin-hook/demo-convert-skinny');

gulp.task('demo:convert:full', () => {
return gulp.src([ 'demo/**/*' ], { base: 'demo' })
.pipe(through.obj((file, enc, callback) => {
if (file.path.match(/\.html$/)) {
let html = String(file.contents);
html = html.replace(/<!--{{{/g, '<!--__BEGIN__-->').replace(/}}}-->/g, '<!--__END__-->').replace(/\/\*{{{/g, '/*__BEGIN__*/').replace(/}}}\*\//g, '/*__END__*/');
file.contents = new Buffer(html);
callback(null, file);
}
else if (file.path.match(/\.js$/)) {
let js = String(file.contents);
js = js.replace(/\/\*{{{/g, '/*__BEGIN__*/').replace(/}}}\*\//g, '/*__END__*/');
file.contents = new Buffer(js);
callback(null, file);
}
else {
callback(null, null);
}
}))
.pipe(gulp.dest('demo'))
});
gulp.task('@thin-hook/demo-convert-full');

gulp.task('integrity-service-helpers', shell.task(targetConfig.commands['integrity-service-helpers']));

Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
},
"devDependencies": {
"@jsenv/node-module-import-map": "^12.0.1",
"@thin-hook/demo-convert-full": "file:plugins/demo-convert-full",
"@thin-hook/demo-convert-skinny": "file:plugins/demo-convert-skinny",
"@thin-hook/examples": "file:examples/plugins/examples",
"argparse": "^1.0.10",
"body-parser": "^1.18.2",
Expand Down
38 changes: 38 additions & 0 deletions plugins/demo-convert-full/configurator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
@license https://github.com/t2ym/thin-hook/blob/master/LICENSE.md
Copyright (c) 2020, Tetsuya Mori <t2y3141592@gmail.com>. All rights reserved.
*/
const path = require('path');
const through = require('through2');

const pluginName = '@thin-hook/demo-convert-full';

const configurator = function (targetConfig) {
const destPath = path.resolve(this.path.base, this.path.root);

return () => this.gulp.src([ path.resolve(destPath, '**/*') ], { base: destPath })
.pipe(through.obj((file, enc, callback) => {
if (file.path.match(/\.html$/)) {
let html = String(file.contents);
html = html.replace(/<!--{{{/g, '<!--__BEGIN__-->').replace(/}}}-->/g, '<!--__END__-->').replace(/\/\*{{{/g, '/*__BEGIN__*/').replace(/}}}\*\//g, '/*__END__*/');
file.contents = Buffer.from(html);
callback(null, file);
}
else if (file.path.match(/\.js$/)) {
let js = String(file.contents);
js = js.replace(/\/\*{{{/g, '/*__BEGIN__*/').replace(/}}}\*\//g, '/*__END__*/');
file.contents = Buffer.from(js);
callback(null, file);
}
else {
callback(null, null);
}
}))
.pipe(this.gulp.dest(destPath))
}

module.exports = {
configurator,
name: pluginName,
dependencies: [],
};
26 changes: 26 additions & 0 deletions plugins/demo-convert-full/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@thin-hook/demo-convert-full",
"version": "0.0.0",
"description": "thin-hook plugin for demo convertion to full mode",
"main": "configurator.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/t2ym/thin-hook.git"
},
"keywords": [
"thin-hook",
"plugin"
],
"author": "Tetsuya Mori <t2y3141592@gmail.com>",
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/t2ym/thin-hook/issues"
},
"homepage": "https://github.com/t2ym/thin-hook#readme",
"dependencies": {
"through2": "^2.0.3"
}
}
38 changes: 38 additions & 0 deletions plugins/demo-convert-skinny/configurator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
@license https://github.com/t2ym/thin-hook/blob/master/LICENSE.md
Copyright (c) 2020, Tetsuya Mori <t2y3141592@gmail.com>. All rights reserved.
*/
const path = require('path');
const through = require('through2');

const pluginName = '@thin-hook/demo-convert-skinny';

const configurator = function (targetConfig) {
const destPath = path.resolve(this.path.base, this.path.root);

return () => this.gulp.src([ path.resolve(destPath, '**/*') ], { base: destPath })
.pipe(through.obj((file, enc, callback) => {
if (file.path.match(/\.html$/)) {
let html = String(file.contents);
html = html.replace(/<!--__BEGIN__-->/g, '<!--{{{').replace(/<!--__END__-->/g, '}}}-->').replace(/\/\*__BEGIN__\*\//g, '/*{{{').replace(/\/\*__END__\*\//g, '}}}*/');
file.contents = Buffer.from(html);
callback(null, file);
}
else if (file.path.match(/\.js$/)) {
let js = String(file.contents);
js = js.replace(/\/\*__BEGIN__\*\//g, '/*{{{').replace(/\/\*__END__\*\//g, '}}}*/');
file.contents = Buffer.from(js);
callback(null, file);
}
else {
callback(null, null);
}
}))
.pipe(this.gulp.dest(destPath))
}

module.exports = {
configurator,
name: pluginName,
dependencies: [],
};
26 changes: 26 additions & 0 deletions plugins/demo-convert-skinny/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@thin-hook/demo-convert-skinny",
"version": "0.0.0",
"description": "thin-hook plugin for demo convertion to skinny mode",
"main": "configurator.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/t2ym/thin-hook.git"
},
"keywords": [
"thin-hook",
"plugin"
],
"author": "Tetsuya Mori <t2y3141592@gmail.com>",
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/t2ym/thin-hook/issues"
},
"homepage": "https://github.com/t2ym/thin-hook#readme",
"dependencies": {
"through2": "^2.0.3"
}
}

0 comments on commit 9eaa35b

Please sign in to comment.