-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #386 [Enhancement][WIP] Add target-injector package
- Loading branch information
Showing
12 changed files
with
1,072 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>. 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: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>", | ||
"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": "*" | ||
} | ||
} |
Oops, something went wrong.