Skip to content

Commit

Permalink
Issue #386 [Enhancement][WIP] Add target-injector package
Browse files Browse the repository at this point in the history
  • Loading branch information
t2ym committed Sep 29, 2020
1 parent 5e9dc82 commit f0b7c99
Show file tree
Hide file tree
Showing 12 changed files with 1,072 additions and 7 deletions.
20 changes: 14 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ gulp.task('bundles',
)
);

gulp.task('injector-helpers');

gulp.task('inject',
gulp.series(
'update-no-hook-authorization',
'update-no-hook-authorization-in-html',
'encode-demo-html',
)
);

gulp.task('@thin-hook/build');

gulp.task('@thin-hook/build-test');
Expand All @@ -386,6 +396,7 @@ gulp.task('frontend',

gulp.task('_demo',
gulp.series(
'injector-helpers',
//'integrity-service-helpers',
//'validation-console',
'clean-gzip-json',
Expand All @@ -405,9 +416,7 @@ gulp.task('_demo',
//'import-maps'
//'bundles',
'integrity-js',
'update-no-hook-authorization',
'update-no-hook-authorization-in-html',
'encode-demo-html',
'inject',
'cache-bundle',
'integrity-json',
'gzip-json',
Expand All @@ -417,6 +426,7 @@ gulp.task('_demo',

gulp.task('demo',
gulp.series(
'injector-helpers',
'integrity-service-helpers',
'validation-console',
'clean-gzip-json',
Expand All @@ -440,9 +450,7 @@ gulp.task('demo',
'policy',
'disable-devtools',
'integrity-js',
'update-no-hook-authorization',
'update-no-hook-authorization-in-html',
'encode-demo-html',
'inject',
'cache-bundle',
'integrity-json',
'gzip-json',
Expand Down
61 changes: 60 additions & 1 deletion 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 @@ -68,6 +68,7 @@
"@thin-hook/demo-convert-skinny": "file:plugins/demo-convert-skinny",
"@thin-hook/demo-gulpfile-js": "file:plugins/demo-gulpfile-js",
"@thin-hook/examples": "file:examples/plugins/examples",
"@thin-hook/injector-helpers": "file:plugins/injector-helpers",
"argparse": "^1.0.10",
"body-parser": "^1.18.2",
"browserify": "^14.0.0",
Expand Down Expand Up @@ -103,6 +104,7 @@
"scenarist": "^1.1.8",
"selenium-standalone": "^6.15.3",
"target-configurator": "^0.1.7",
"target-injector": "file:plugins/target-injector",
"through2": "^2.0.3",
"transform-loader": "^0.2.4",
"tty-browserify": "0.0.0",
Expand Down
58 changes: 58 additions & 0 deletions plugins/injector-helpers/configurator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
@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 { InjectorFactory, InjectionHandlerBase } = require('target-injector');
const { HtmlInjectionHandlerFactory } = require('target-injector/HtmlInjectionHandlerFactory.js');
const { JsInjectionHandlerFactory } = require('target-injector/JsInjectionHandlerFactory.js');

const { Parser } = require("htmlparser2");
const { DomHandler } = require("domhandler");
const cssauron = require('cssauron');

const parser = require('espree'); // can be esprima or acorn
const estraverse = 'estraverse'; // hand a string specifier to patch the component in InjectorFactory
const esquery = require('esquery');

const pluginName = 'injector-helpers';

const configurator = function (targetConfig) {
const configPath = path.resolve(this.path.base, this.path.config, pluginName);
const destPath = path.resolve(this.path.base, this.path.root);
const pluginDirname = __dirname;

return (done) => {
const Injector = InjectorFactory({
html: {
factory: HtmlInjectionHandlerFactory,
components: {
Parser, DomHandler, cssauron,
},
extensions: [ '.html', '.htm' ],
},
js: {
factory: JsInjectionHandlerFactory,
components: {
parser, estraverse, esquery, /*, parserOptions: parserOptions */
},
extensions: [ '.js', '.mjs' ],
},
});

this.inject = this.inject || {};
this.inject.components = this.inject.components || {};
this.inject.components.targetConfig = this;
this.inject.components.Injector = Injector;
this.inject.components.InjectionHandlerBase = InjectionHandlerBase;
this.inject.components.HtmlInjectionHandlerFactory = HtmlInjectionHandlerFactory;
this.inject.components.JsInjectionHandlerFactory = JsInjectionHandlerFactory;
done();
}
}

module.exports = {
configurator,
name: pluginName,
dependencies: [],
};
31 changes: 31 additions & 0 deletions plugins/injector-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@thin-hook/injector-helpers",
"version": "0.0.0",
"description": "Wrapper to inject code into target",
"main": "Injector.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": {
"cssauron": "^1.4.0",
"domhandler": "^3.1.0",
"espree": "*",
"esquery": "^1.3.1",
"estraverse": "*",
"htmlparser2": "*"
}
}
Loading

0 comments on commit f0b7c99

Please sign in to comment.