-
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] Use "this" instead of targetConfig wher…
…e possible
- Loading branch information
Showing
13 changed files
with
166 additions
and
183 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
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 |
---|---|---|
|
@@ -5,25 +5,25 @@ Copyright (c) 2020, Tetsuya Mori <[email protected]>. All rights reserved. | |
const path = require('path'); | ||
|
||
// return globs for target entries in integrity.json | ||
const targets = (targetConfig) => { | ||
const destPath = path.resolve(targetConfig.path.base, targetConfig.path.root); | ||
const targets = function (targetConfig) { | ||
const destPath = path.resolve(this.path.base, this.path.root); | ||
return [ | ||
path.resolve(targetConfig.path.hook, 'hook.min.js'), | ||
path.resolve(this.path.hook, 'hook.min.js'), | ||
path.resolve(destPath, '**/*'), | ||
path.resolve(targetConfig.path.base, 'bower_components/**/*'), | ||
path.resolve(this.path.base, this.path.components, '**/*'), | ||
// integrity.json itself | ||
'!' + path.resolve(destPath, 'integrity.json'), | ||
'!' + path.resolve(destPath, '**/*.gz'), | ||
'!' + path.resolve(destPath, 'errorReport.json'), | ||
// decoded index.html | ||
'!' + path.resolve(destPath, targetConfig.path.decodedIndexHtml), | ||
'!' + path.resolve(destPath, this.path.decodedIndexHtml), | ||
// encoded index.html | ||
'!' + path.resolve(destPath, targetConfig.path.encodedIndexHtml), | ||
'!' + path.resolve(targetConfig.path.base, 'bower_components/**/test/**/*'), | ||
'!' + path.resolve(targetConfig.path.base, 'bower_components/**/demo/**/*'), | ||
'!' + path.resolve(destPath, this.path.encodedIndexHtml), | ||
'!' + path.resolve(this.path.base, this.path.components, '**/test/**/*'), | ||
'!' + path.resolve(this.path.base, this.path.components, '**/demo/**/*'), | ||
]; | ||
} | ||
|
||
module.exports = { | ||
targets: targets, | ||
targets, | ||
}; |
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 |
---|---|---|
|
@@ -3,27 +3,23 @@ | |
Copyright (c) 2020, Tetsuya Mori <[email protected]>. All rights reserved. | ||
*/ | ||
const path = require('path'); | ||
const { preprocess } = require('preprocess'); | ||
const through = require('through2'); | ||
const gulp = require('gulp'); | ||
const fs = require('fs'); | ||
|
||
const pluginName = 'cache-bundle-automation-json'; | ||
|
||
const configurator = (targetConfig) => { | ||
const configPath = path.resolve(targetConfig.path.base, targetConfig.path.config, pluginName); | ||
const destPath = path.resolve(targetConfig.path.base, targetConfig.path.root); | ||
const configurator = function (targetConfig) { | ||
const destPath = path.resolve(this.path.base, this.path.root); | ||
const pluginDirname = __dirname; | ||
const sourceFile = targetConfig[pluginName] && targetConfig[pluginName].sourceFile | ||
? targetConfig[pluginName].sourceFile | ||
const sourceFile = this[pluginName] && this[pluginName].sourceFile | ||
? this[pluginName].sourceFile | ||
: 'cache-bundle.json'; | ||
return (done) => { | ||
const cacheAutomationScript = fs.readFileSync(targetConfig['automation-secret'].cacheAutomationScriptPath, 'utf-8'); | ||
const cacheAutomationScript = fs.readFileSync(this['automation-secret'].cacheAutomationScriptPath, 'utf-8'); | ||
fs.writeFileSync(path.resolve(destPath, sourceFile), JSON.stringify({ | ||
"version": targetConfig['get-version'].version, | ||
"version": this['get-version'].version, | ||
"https://thin-hook.localhost.localdomain/automation.json": JSON.stringify({ | ||
"state": "init", // update state in the script to perform operations including reloading | ||
"serverSecret": targetConfig['automation-secret'].serverSecret, | ||
"serverSecret": this['automation-secret'].serverSecret, | ||
"script": cacheAutomationScript, | ||
}, null, 0) | ||
}, null, 2)); | ||
|
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 |
---|---|---|
|
@@ -5,20 +5,18 @@ Copyright (c) 2020, Tetsuya Mori <[email protected]>. All rights reserved. | |
const path = require('path'); | ||
const { preprocess } = require('preprocess'); | ||
const through = require('through2'); | ||
const gulp = require('gulp'); | ||
|
||
const pluginName = 'disable-devtools'; | ||
|
||
const configurator = (targetConfig) => { | ||
const configPath = path.resolve(targetConfig.path.base, targetConfig.path.config, pluginName); | ||
const destPath = path.resolve(targetConfig.path.base, targetConfig.path.root); | ||
const devtoolsDisabled = targetConfig.mode.devtoolsDisabled; | ||
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 devtoolsDisabled = this.mode.devtoolsDisabled; | ||
const pluginDirname = __dirname; | ||
const sourceFile = targetConfig[pluginName] && targetConfig[pluginName].sourceFile | ||
? targetConfig[pluginName].sourceFile | ||
const sourceFile = this[pluginName] && this[pluginName].sourceFile | ||
? this[pluginName].sourceFile | ||
: 'disable-devtools.js'; | ||
return () => gulp.src([ path.resolve(pluginDirname, sourceFile) ]) | ||
// 1st pass | ||
return () => this.gulp.src([ path.resolve(pluginDirname, sourceFile) ]) | ||
.pipe(through.obj((file, enc, callback) => { | ||
let script = String(file.contents); | ||
script = preprocess(script, | ||
|
@@ -37,26 +35,7 @@ const configurator = (targetConfig) => { | |
file.contents = Buffer.from(script); | ||
callback(null, file); | ||
})) | ||
/* | ||
// 2nd pass | ||
.pipe(through.obj((file, enc, callback) => { | ||
let script = String(file.contents); | ||
script = preprocess(script, | ||
{ | ||
SPACE: ' ', | ||
EQUAL: '=', | ||
SEMICOLON: ';', | ||
}, | ||
{ | ||
type: 'js', | ||
srcDir: configPath, // in demo-config/policy/ | ||
} | ||
); | ||
file.contents = Buffer.from(script); | ||
callback(null, file); | ||
})) | ||
*/ | ||
.pipe(gulp.dest(destPath)); | ||
.pipe(this.gulp.dest(destPath)); | ||
} | ||
|
||
module.exports = { | ||
|
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 |
---|---|---|
|
@@ -3,28 +3,24 @@ | |
Copyright (c) 2020, Tetsuya Mori <[email protected]>. All rights reserved. | ||
*/ | ||
const path = require('path'); | ||
const { preprocess } = require('preprocess'); | ||
const through = require('through2'); | ||
const gulp = require('gulp'); | ||
const fs = require('fs'); | ||
|
||
const pluginName = 'dummy-integrity'; | ||
|
||
const configurator = (targetConfig) => { | ||
const configPath = path.resolve(targetConfig.path.base, targetConfig.path.config, pluginName); | ||
const destPath = path.resolve(targetConfig.path.base, targetConfig.path.root); | ||
const configurator = function (targetConfig) { | ||
const destPath = path.resolve(this.path.base, this.path.root); | ||
const pluginDirname = __dirname; | ||
const sourceFile = targetConfig[pluginName] && targetConfig[pluginName].sourceFile | ||
? targetConfig[pluginName].sourceFile | ||
const sourceFile = this[pluginName] && this[pluginName].sourceFile | ||
? this[pluginName].sourceFile | ||
: 'integrity.json'; | ||
return (done) => { | ||
// generate a dummy demo/integrity.json for cache-bundle generation | ||
const cacheAutomationScript = fs.readFileSync(targetConfig['automation-secret'].cacheAutomationScriptPath, 'utf-8'); | ||
const cacheAutomationScript = fs.readFileSync(this['automation-secret'].cacheAutomationScriptPath, 'utf-8'); | ||
fs.writeFileSync(path.resolve(destPath, sourceFile), JSON.stringify({ | ||
"version": targetConfig['get-version'].version, | ||
"version": this['get-version'].version, | ||
"https://thin-hook.localhost.localdomain/automation.json": JSON.stringify({ | ||
"state": "init", // update state in the script to perform operations including reloading | ||
"serverSecret": targetConfig['automation-secret'].serverSecret, | ||
"serverSecret": this['automation-secret'].serverSecret, | ||
"script": cacheAutomationScript, | ||
}, null, 0) | ||
}, null, 2)); | ||
|
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 |
---|---|---|
|
@@ -3,19 +3,16 @@ | |
Copyright (c) 2020, Tetsuya Mori <[email protected]>. All rights reserved. | ||
*/ | ||
const path = require('path'); | ||
const { preprocess } = require('preprocess'); | ||
const through = require('through2'); | ||
const gulp = require('gulp'); | ||
|
||
const pluginName = 'get-version'; | ||
|
||
const configurator = (targetConfig) => { | ||
const configPath = path.resolve(targetConfig.path.base, targetConfig.path.config, pluginName); | ||
const destPath = path.resolve(targetConfig.path.base, targetConfig.path.root); | ||
const configurator = function (targetConfig) { | ||
const destPath = path.resolve(this.path.base, this.path.root); | ||
const pluginDirname = __dirname; | ||
const sourceFile = targetConfig.path.decodedIndexHtml || 'original-index.html'; | ||
const sourceFile = this.path.decodedIndexHtml || 'original-index.html'; | ||
let version = 'version_1'; | ||
return (done) => gulp.src([path.resolve(destPath, sourceFile)]) | ||
return (done) => this.gulp.src([path.resolve(destPath, sourceFile)]) | ||
.pipe(through.obj((file, enc, callback) => { | ||
let html = String(file.contents); | ||
let versionIndex = html.indexOf('/hook.min.js?version=') + '/hook.min.js?version='.length; | ||
|
@@ -24,9 +21,8 @@ const configurator = (targetConfig) => { | |
callback(null, file); | ||
})) | ||
.pipe(through.obj((file, enc, callback) => { | ||
targetConfig[pluginName] = targetConfig[pluginName] || {}; | ||
targetConfig[pluginName].version = version; | ||
//console.log('targetConfig', targetConfig); | ||
this[pluginName] = this[pluginName] || {}; | ||
this[pluginName].version = version; | ||
done(); | ||
})); | ||
} | ||
|
Oops, something went wrong.