Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
143 additions
and
1,450 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
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,24 @@ | ||
const Fs = require('fs'); | ||
const Path = require('path'); | ||
const UglifyJS = require('uglify-es'); | ||
const TranspileJs = require('./compile-es6.es6.js'); | ||
const TranspileWc = require('./compile-w-c.es6.js'); | ||
const MakeDir = require('../utils/make-dir.es6.js'); | ||
|
||
module.exports.run = (file) => { | ||
if (file.match(/\.js/) && file.match(/\.es6\.js/) && !file.match(/\.w-c\.es6\.js/)) { | ||
// ES6 file so we need to transpile it | ||
TranspileJs.compileFile(file); | ||
} else if (file.match(/\.js/) && file.match(/\.es5\.js/)) { | ||
// ES5 file, we will copy the file and then minify it in place | ||
// Ensure that the directories exist or create them | ||
MakeDir.run(Path.dirname(file).replace('/build/media_source/', '/media/').replace('\\build\\media_source\\', '\\media\\')); | ||
Fs.copyFileSync(file, file.replace('/build/media_source/', '/media/').replace('\\build\\media_source\\', '\\media\\').replace('.es5.js', '.js')); | ||
Fs.writeFileSync(file.replace('/build/media_source/', '/media/').replace('\\build\\media_source\\', '\\media\\').replace('.es5.js', '.min.js'), UglifyJS.minify(Fs.readFileSync(file, 'utf8')).code, { encoding: 'utf8' }); | ||
// eslint-disable-next-line no-console | ||
console.log(`Es5 file copied/minified: ${file}`); | ||
} else if (file.match(/\.js/) && file.match(/\.w-c\.es6\.js/)) { | ||
// Web Component, so we need to transpile it | ||
TranspileWc.compile(file, options); | ||
} | ||
}; |
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,38 @@ | ||
const watch = require('watch'); | ||
const HandleJsFile = require('./javascript/handle-file.es6.js'); | ||
const Path = require('path'); | ||
const RootPath = require('./utils/rootpath.es6.js')._(); | ||
|
||
/** | ||
* Debounce | ||
* https://gist.github.com/nmsdvid/8807205 | ||
* | ||
* @param { function } callback The callback function to be executed | ||
* @param { integer } time The time to wait before firing the callback | ||
* @param { integer } interval The interval | ||
*/ | ||
const debounce = (callback, time = 250, interval) => (...args) => clearTimeout(interval, interval = setTimeout(callback, time, ...args)); | ||
|
||
module.exports.run = (options, path) => { | ||
let inputPath = Path.join(RootPath, 'build/media_source'); | ||
if (path) { | ||
inputPath = path; | ||
} | ||
watch.createMonitor(inputPath, (monitor) => { | ||
monitor.on("created", function (f, stat) { | ||
if (file.match(/\.js/) && (file.match(/\.es5\.js/) || file.match(/\.es6\.js/) || file.match(/\.w-c\.es6\.js/))) { | ||
debounce(HandleJsFile.run(file), 300) | ||
} | ||
// @todo css and scss | ||
}); | ||
monitor.on("changed", function (file, curr, prev) { | ||
if (file.match(/\.js/) && (file.match(/\.es5\.js/) || file.match(/\.es6\.js/) || file.match(/\.w-c\.es6\.js/))) { | ||
debounce(HandleJsFile.run(file), 300) | ||
} | ||
// @todo css and scss | ||
}); | ||
monitor.on("removed", function (f, stat) { | ||
// Handle this case as well | ||
}) | ||
}); | ||
}; |
Oops, something went wrong.