-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a332f17
commit 64beb68
Showing
16 changed files
with
3,810 additions
and
263 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
|
||
/** | ||
* | ||
*/ | ||
|
||
const closureCompiler = require('google-closure-compiler').gulp({ | ||
// extraArguments: ['-Xms2048m'] | ||
}); | ||
|
||
/** | ||
* defaultCompile passes defaults to the closureCompiler | ||
* | ||
* @param {string} outName whatever defaultCompile produces. | ||
* | ||
* @return {object} whatever closureCompiler returns. | ||
*/ | ||
var defaultCompile = function(outName) { | ||
return closureCompiler({ | ||
js_output_file: 'glift-core.js', | ||
language_in: 'ECMASCRIPT5_STRICT', | ||
// TODO(kashomon): Turn on ADVANCED_OPTIMIZATIONS when all the right | ||
// functions have been marked @export, where appropriate | ||
// compilation_level: 'ADVANCED_OPTIMIZATIONS', | ||
// | ||
// Note that warning_level=VERBOSE corresponds to: | ||
// | ||
// --jscomp_warning=checkTypes | ||
// --jscomp_error=checkVars | ||
// --jscomp_warning=deprecated | ||
// --jscomp_error=duplicate | ||
// --jscomp_warning=globalThis | ||
// --jscomp_warning=missingProperties | ||
// --jscomp_warning=undefinedNames | ||
// --jscomp_error=undefinedVars | ||
// | ||
// Do some advanced Javascript checks. | ||
// https://github.com/google/closure-compiler/wiki/Warnings | ||
jscomp_error: [ | ||
'accessControls', | ||
'checkRegExp', | ||
'checkTypes', | ||
'checkVars', | ||
'const', | ||
'constantProperty', | ||
'deprecated', | ||
'duplicate', | ||
'globalThis', | ||
'missingProperties', | ||
'missingProvide', | ||
'missingReturn', | ||
'undefinedNames', | ||
'undefinedVars', | ||
'visibility', | ||
// We don't turn requires into Errors, because the closure compiler | ||
// reorders the sources based on the requires. | ||
// 'missingRequire', | ||
], | ||
}); | ||
}; | ||
|
||
module.exports = defaultCompile; |
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,105 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Package dev is entirely used for sharing Gulp build-related code across | ||
* various Glift-projects. | ||
*/ | ||
|
||
// | ||
// Beware! Below lie demons unvanquished. | ||
// | ||
|
||
/** | ||
* Takes an ordering array and an ignore glob-array and generates a glob array | ||
* appropriate for gulp. What this does is take an array of paths (both files | ||
* and directorys), and recursively generates directory-based globs. | ||
* | ||
* Glift (and co) have an idiosyncratic way of genserating namespaces. | ||
* Namepsaces are created files with the same name as a directory. For example, | ||
* src/foo should have a file that defines glift.foo = {}; Thus, these files | ||
* must go first before all other files that depend on that namespace. | ||
* | ||
* As an expanded example, consider the following directories: | ||
* | ||
* src/ | ||
* foo/ | ||
* abc.js | ||
* foo.js | ||
* zed.js | ||
* bar/ | ||
* bbc.js | ||
* bar.js | ||
* zod.js | ||
* biff/ | ||
* biff.js | ||
* boff.js | ||
* | ||
* So, when called as such: | ||
* jsSrcGlobGen(['src']) | ||
* | ||
* The following array would be produced: | ||
* [ | ||
* 'src/*.js', 'src/foo/foo.js', 'src/foo/*.js', 'src/bar/bar.js', | ||
* 'src/bar/biff/biff.js', 'src/bar/biff/*.js' | ||
* ] | ||
* | ||
* Note: for convenience, users may pass in a set of normal node-glob style | ||
* globs that will be appended to the generated globs. | ||
* | ||
* I.e., if jsSrcGlobGen is called with | ||
* jsSrcGlobGen(['src'], ['!src/**' + '/*_test.js']) | ||
* | ||
* Then, assuming the directory structure above, the output array will be | ||
* [ 'src/*.js', ..., !src/**' + ' /*_test.js'] | ||
* | ||
* (note: Concatenation is used to avoid comment-breaks). | ||
*/ | ||
var jsSrcGlobGen = function(ordering, addGlobs) { | ||
if (typeof ordering !== 'object' || !ordering.length) { | ||
throw new Error( | ||
'Ordering must be a non-empty array of paths. ' + | ||
'Was: ' + (typeof ordering) + ':' + String(ordering)); | ||
} | ||
|
||
var out = []; | ||
var addGlobs = addGlobs || []; | ||
|
||
var rread = function(dirPath) { | ||
var components = dirPath.split(path.sep); | ||
var last = components[components.length - 1]; | ||
|
||
var nsfile = path.join(dirPath, last + '.js'); | ||
if (fs.existsSync(nsfile)) { | ||
out.push(nsfile); | ||
} | ||
out.push(path.join(dirPath, '*.js')); | ||
|
||
fs.readdirSync(dirPath).forEach((f) => { | ||
var fpath = path.join(dirPath, f) | ||
var fd = fs.lstatSync(fpath); | ||
if (fd.isDirectory()) { | ||
rread(fpath) | ||
} | ||
}); | ||
} | ||
|
||
ordering.forEach((fpath) => { | ||
if (!fs.existsSync(fpath)) { | ||
console.warn('Path does not exist: ' + path); | ||
return; | ||
} | ||
var fd = fs.lstatSync(fpath); | ||
if (!fd.isDirectory()) { | ||
out.push(fpath); | ||
} else { | ||
rread(fpath); | ||
} | ||
}) | ||
|
||
return out.concat(addGlobs); | ||
}; | ||
|
||
module.exports = jsSrcGlobGen; |
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,86 @@ | ||
'strict' | ||
|
||
const glob = require('glob'); | ||
const path = require('path'); | ||
const through = require('through2'); | ||
const fs = require('fs'); | ||
|
||
/** | ||
* Package dev is entirely used for sharing Gulp build-related code across | ||
* various Glift-projects. | ||
*/ | ||
|
||
/** | ||
* A function to update the HTML files. The idea is that updateHtmlFiles takes a | ||
* glob of files and treats them as templates. It goes through and add | ||
* sources to these files then outputs them to the specified outDir | ||
* | ||
* @param {string} filesGlob The glob of html files. | ||
* @param {string} header The header marker to indicate where to dump the JS | ||
* sources. | ||
* @param {string} footer The footer marker to indicate where to dump the JS | ||
* sources. | ||
* @param {string} outDir the output dir for the templated files. | ||
* @param {string} template the template to use. | ||
* | ||
* @return an object stream | ||
* Note: this gets the 'srcs' as part of the Vinyl file stream. | ||
*/ | ||
var updateHtmlFiles = function(params) { | ||
var files = glob.sync(params.filesGlob); | ||
var header = params.header; | ||
var footer = params.footer; | ||
var regexp = new RegExp(`(${header})(.|\n)*(${footer})`, 'g') | ||
var outDir = params.outDir; | ||
|
||
var dirHeader = params.dirHeader; | ||
var all = []; | ||
var template = params.template || '<script type="text/javascript" src="%s"></script>'; | ||
|
||
return through.obj(function(file, enc, cb) { | ||
all.push(file); | ||
cb(); | ||
}, function(cb) { | ||
var htmldir = path.dirname(files[0]) | ||
|
||
var tags = []; | ||
var lastdir = null | ||
all.forEach((f) => { | ||
var relpath = path.relative(htmldir, f.path) | ||
|
||
var dir = path.dirname(f.path) | ||
if (dir !== lastdir) { | ||
tags.push(dirHeader.replace('%s', path.relative(htmldir, dir))) | ||
lastdir = dir | ||
} | ||
|
||
tags.push(template.replace('%s', relpath)) | ||
this.push(f) | ||
}) | ||
|
||
var text = tags.join('\n'); | ||
|
||
if (!fs.existsSync(outDir)){ | ||
fs.mkdirSync(outDir); | ||
} | ||
|
||
files.forEach((fname) => { | ||
var parsedPath = path.parse(fname) | ||
var outPath = path.join(outDir, parsedPath.base) | ||
if (!fs.existsSync(outPath)) { | ||
// First we write the template files. | ||
var contents = fs.readFileSync(fname, {encoding: 'UTF-8'}) | ||
fs.writeFileSync(outPath, contents) | ||
} | ||
// Then, read from the newly-written file and overwrite the template | ||
// sections. | ||
var contents = fs.readFileSync(outPath, {encoding: 'UTF-8'}) | ||
var replaced = contents.replace(regexp, '$1\n' + text + '\n$3') | ||
fs.writeFileSync(outPath, replaced) | ||
}); | ||
|
||
cb(); | ||
}) | ||
}; | ||
|
||
module.exports = updateHtmlFiles; |
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 |
---|---|---|
|
@@ -7,5 +7,5 @@ glift.global = { | |
* | ||
* Not yet stable. | ||
*/ | ||
'core-version': '0.9.1' | ||
'core-version': '0.9.2' | ||
}; |
Oops, something went wrong.