mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-06-05 22:09:23 +02:00
Transition to monorepo on a new Dev branch
This commit is contained in:
15
App/Source/node_modules/pug-cli/.npmignore
generated
vendored
Normal file
15
App/Source/node_modules/pug-cli/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
pids
|
||||
logs
|
||||
results
|
||||
npm-debug.log
|
||||
node_modules
|
||||
coverage
|
||||
cov-pt*
|
||||
test/temp
|
17
App/Source/node_modules/pug-cli/.travis.yml
generated
vendored
Normal file
17
App/Source/node_modules/pug-cli/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4"
|
||||
- "6"
|
||||
|
||||
after_success:
|
||||
- npm run coverage
|
||||
- npm i codecov
|
||||
- codecov -f ./coverage/lcov.info
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
91
App/Source/node_modules/pug-cli/HISTORY.md
generated
vendored
Normal file
91
App/Source/node_modules/pug-cli/HISTORY.md
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
# Change Log
|
||||
As with most npm modules, this project adheres to
|
||||
[Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [1.0.0-alpha6] - 2016-06-01
|
||||
|
||||
### Added
|
||||
- `--basedir` option is added for easier specification of that Pug option.
|
||||
- Node.js v6 is now tested.
|
||||
|
||||
## [1.0.0-alpha5] - 2016-05-18
|
||||
|
||||
### Changed
|
||||
- Files ending `.jade` are now recognized as Pug templates when a directory is provided as input.
|
||||
|
||||
## [1.0.0-alpha4] - 2016-05-18
|
||||
|
||||
### Changed
|
||||
- When `--watch` is specified, `watch` is no longer passed as an option to Pug. This should have no effect on users.
|
||||
|
||||
### Fixed
|
||||
- Fixed `--no-debug` option ([#23])
|
||||
|
||||
## [1.0.0-alpha3] - 2016-05-18
|
||||
|
||||
### Added
|
||||
- Node.js module as option file is supported as well.
|
||||
- Some examples have been added to the documentation on how to use `-O`.
|
||||
|
||||
## [1.0.0-alpha2] - 2016-05-18
|
||||
|
||||
### Changed
|
||||
- Pug has been updated to the latest alpha.
|
||||
- Unused dependencies have been removed.
|
||||
|
||||
## [1.0.0-alpha1] - 2016-03-23
|
||||
|
||||
### Removed
|
||||
- `-H` option, deprecated in 0.1.0, has been removed.
|
||||
- Support for `SIGINT` as signal for EOF, deprecated in 0.1.1, has been removed.
|
||||
|
||||
### Changed
|
||||
- The package is renamed to `pug-cli`.
|
||||
|
||||
### Fixed
|
||||
- Support for Windows has been fixed.
|
||||
|
||||
## [0.1.1] - 2015-09-29
|
||||
### Deprecated
|
||||
- Using `SIGINT` (`^C`) to signify end of input in standard input mode is deprecated, and will be removed in 1.0.0. Instead, use `^D` which means "end of file."
|
||||
|
||||
### Fixed
|
||||
- Fallback on options specified with `-O` if the corresponding CLI option is not specified.
|
||||
- Mark this module as preferred to be installed globally.
|
||||
- Fix copyright and update maintainers in package.json.
|
||||
- Fix links in HISTORY.md.
|
||||
- Fix compiling directories whose paths contain backslashes (`\`) (#11).
|
||||
|
||||
## [0.1.0] - 2015-07-24
|
||||
### Added
|
||||
- Silent mode (`-s`, `--silent`) which disables printing unimportant messages (#3, pugjs/pug#1905).
|
||||
|
||||
### Changed
|
||||
- Hierarchy mode (`-H`, `--hierarchy`) is made the default.
|
||||
- Both versions of Pug and the CLI are printed with `-V` or `--version`.
|
||||
- Unescaped Unicode line and paragraph separators (`U+2028` and `U+2029`) is now allowed in the `-O` option only when the input is considered to be JSON (#5, pugjs/pug#1949).
|
||||
- Non-JSON object files are allowed for the `-O` option as long as it can be parsed with the `eval()` function.
|
||||
|
||||
### Deprecated
|
||||
- Since the hierarchy mode (`-H`, `--hierarchy`) is made the default, the
|
||||
option is now redundant and will be removed in 1.0.0.
|
||||
|
||||
### Fixed
|
||||
- Capitalization in help message is kept consistent.
|
||||
- Fix grammar error in the help message (by @didoarellano).
|
||||
- Fix watch mode in more than one level of dependency hierarchy (pugjs/pug#1888).
|
||||
|
||||
## 0.0.1 - 2015-06-02
|
||||
### Added
|
||||
- Initial release.
|
||||
|
||||
[unreleased]: https://github.com/pugjs/pug-cli/compare/1.0.0-alpha5...master
|
||||
[1.0.0-alpha5]: https://github.com/pugjs/pug-cli/compare/1.0.0-alpha4...1.0.0-alpha5
|
||||
[1.0.0-alpha4]: https://github.com/pugjs/pug-cli/compare/1.0.0-alpha3...1.0.0-alpha4
|
||||
[1.0.0-alpha3]: https://github.com/pugjs/pug-cli/compare/1.0.0-alpha2...1.0.0-alpha3
|
||||
[1.0.0-alpha2]: https://github.com/pugjs/pug-cli/compare/1.0.0-alpha1...1.0.0-alpha2
|
||||
[1.0.0-alpha1]: https://github.com/pugjs/pug-cli/compare/0.1.1...1.0.0-alpha1
|
||||
[0.1.1]: https://github.com/pugjs/pug-cli/compare/0.1.0...0.1.1
|
||||
[0.1.0]: https://github.com/pugjs/pug-cli/compare/0.0.1...0.1.0
|
||||
|
||||
[#23]: https://github.com/pugjs/pug-cli/issues/23
|
21
App/Source/node_modules/pug-cli/LICENSE.md
generated
vendored
Normal file
21
App/Source/node_modules/pug-cli/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
Copyright (c) 2010-2014 TJ Holowaychuk
|
||||
Copyright (c) 2013-2015 Forbes Lindesay
|
||||
Copyright (c) 2015 Tiancheng "Timothy" Gu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
310
App/Source/node_modules/pug-cli/index.js
generated
vendored
Normal file
310
App/Source/node_modules/pug-cli/index.js
generated
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var program = require('commander');
|
||||
var mkdirp = require('mkdirp');
|
||||
var chalk = require('chalk');
|
||||
var pug = require('pug');
|
||||
|
||||
var basename = path.basename;
|
||||
var dirname = path.dirname;
|
||||
var resolve = path.resolve;
|
||||
var normalize = path.normalize;
|
||||
var join = path.join;
|
||||
var relative = path.relative;
|
||||
|
||||
// Pug options
|
||||
|
||||
var options = {};
|
||||
|
||||
// options
|
||||
|
||||
program
|
||||
.version(
|
||||
'pug version: ' + require('pug/package.json').version + '\n' +
|
||||
'pug-cli version: ' + require( './package.json').version
|
||||
)
|
||||
.usage('[options] [dir|file ...]')
|
||||
.option('-O, --obj <str|path>', 'JSON/JavaScript options object or file')
|
||||
.option('-o, --out <dir>', 'output the rendered HTML or compiled JavaScript to <dir>')
|
||||
.option('-p, --path <path>', 'filename used to resolve includes')
|
||||
.option('-b, --basedir <path>', 'path used as root directory to resolve absolute includes')
|
||||
.option('-P, --pretty', 'compile pretty HTML output')
|
||||
.option('-c, --client', 'compile function for client-side')
|
||||
.option('-n, --name <str>', 'the name of the compiled template (requires --client)')
|
||||
.option('-D, --no-debug', 'compile without debugging (smaller functions)')
|
||||
.option('-w, --watch', 'watch files for changes and automatically re-render')
|
||||
.option('-E, --extension <ext>', 'specify the output file extension')
|
||||
.option('-s, --silent', 'do not output logs')
|
||||
.option('--name-after-file', 'name the template after the last section of the file path (requires --client and overriden by --name)')
|
||||
.option('--doctype <str>', 'specify the doctype on the command line (useful if it is not specified by the template)')
|
||||
|
||||
|
||||
program.on('--help', function(){
|
||||
console.log(' Examples:');
|
||||
console.log('');
|
||||
console.log(' # Render all files in the `templates` directory:');
|
||||
console.log(' $ pug templates');
|
||||
console.log('');
|
||||
console.log(' # Create {foo,bar}.html:');
|
||||
console.log(' $ pug {foo,bar}.pug');
|
||||
console.log('');
|
||||
console.log(' # Using `pug` over standard input and output streams');
|
||||
console.log(' $ pug < my.pug > my.html');
|
||||
console.log(' $ echo \'h1 Pug!\' | pug');
|
||||
console.log('');
|
||||
console.log(' # Render all files in `foo` and `bar` directories to `/tmp`:');
|
||||
console.log(' $ pug foo bar --out /tmp');
|
||||
console.log('');
|
||||
console.log(' # Specify options through a string:');
|
||||
console.log(' $ pug -O \'{"doctype": "html"}\' foo.pug');
|
||||
console.log(' # or, using JavaScript instead of JSON');
|
||||
console.log(' $ pug -O "{doctype: \'html\'}" foo.pug');
|
||||
console.log('');
|
||||
console.log(' # Specify options through a file:');
|
||||
console.log(' $ echo "exports.doctype = \'html\';" > options.js');
|
||||
console.log(' $ pug -O options.js foo.pug');
|
||||
console.log(' # or, JSON works too');
|
||||
console.log(' $ echo \'{"doctype": "html"}\' > options.json');
|
||||
console.log(' $ pug -O options.json foo.pug');
|
||||
console.log('');
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
// options given, parse them
|
||||
|
||||
if (program.obj) {
|
||||
options = parseObj(program.obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse object either in `input` or in the file called `input`. The latter is
|
||||
* searched first.
|
||||
*/
|
||||
function parseObj (input) {
|
||||
try {
|
||||
return require(path.resolve(input));
|
||||
} catch (e) {
|
||||
var str;
|
||||
try {
|
||||
str = fs.readFileSync(program.obj, 'utf8');
|
||||
} catch (e) {
|
||||
str = program.obj;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
return eval('(' + str + ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
['path', 'filename'], // --path
|
||||
['debug', 'compileDebug'], // --no-debug
|
||||
['client', 'client'], // --client
|
||||
['pretty', 'pretty'], // --pretty
|
||||
['basedir', 'basedir'], // --basedir
|
||||
['doctype', 'doctype'], // --doctype
|
||||
].forEach(function (o) {
|
||||
options[o[1]] = program[o[0]] !== undefined ? program[o[0]] : options[o[1]];
|
||||
});
|
||||
|
||||
// --name
|
||||
|
||||
if (typeof program.name === 'string') {
|
||||
options.name = program.name;
|
||||
}
|
||||
|
||||
// --silent
|
||||
|
||||
var consoleLog = program.silent ? function() {} : console.log;
|
||||
|
||||
// left-over args are file paths
|
||||
|
||||
var files = program.args;
|
||||
|
||||
// object of reverse dependencies of a watched file, including itself if
|
||||
// applicable
|
||||
|
||||
var watchList = {};
|
||||
|
||||
// function for rendering
|
||||
var render = program.watch ? tryRender : renderFile;
|
||||
|
||||
// compile files
|
||||
|
||||
if (files.length) {
|
||||
consoleLog();
|
||||
if (program.watch) {
|
||||
process.on('SIGINT', function() {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
files.forEach(function (file) {
|
||||
render(file);
|
||||
});
|
||||
// stdio
|
||||
} else {
|
||||
stdin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch for changes on path
|
||||
*
|
||||
* Renders `base` if specified, otherwise renders `path`.
|
||||
*/
|
||||
function watchFile(path, base, rootPath) {
|
||||
path = normalize(path);
|
||||
|
||||
var log = ' ' + chalk.gray('watching') + ' ' + chalk.cyan(path);
|
||||
if (!base) {
|
||||
base = path;
|
||||
} else {
|
||||
base = normalize(base);
|
||||
log += '\n ' + chalk.gray('as a dependency of') + ' ';
|
||||
log += chalk.cyan(base);
|
||||
}
|
||||
|
||||
if (watchList[path]) {
|
||||
if (watchList[path].indexOf(base) !== -1) return;
|
||||
consoleLog(log);
|
||||
watchList[path].push(base);
|
||||
return;
|
||||
}
|
||||
|
||||
consoleLog(log);
|
||||
watchList[path] = [base];
|
||||
fs.watchFile(path, {persistent: true, interval: 200},
|
||||
function (curr, prev) {
|
||||
// File doesn't exist anymore. Keep watching.
|
||||
if (curr.mtime.getTime() === 0) return;
|
||||
// istanbul ignore if
|
||||
if (curr.mtime.getTime() === prev.mtime.getTime()) return;
|
||||
watchList[path].forEach(function(file) {
|
||||
tryRender(file, rootPath);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert error to string
|
||||
*/
|
||||
function errorToString(e) {
|
||||
return e.stack || /* istanbul ignore next */ (e.message || e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to render `path`; if an exception is thrown it is printed to stderr and
|
||||
* otherwise ignored.
|
||||
*
|
||||
* This is used in watch mode.
|
||||
*/
|
||||
function tryRender(path, rootPath) {
|
||||
try {
|
||||
renderFile(path, rootPath);
|
||||
} catch (e) {
|
||||
// keep watching when error occured.
|
||||
console.error(errorToString(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile from stdin.
|
||||
*/
|
||||
|
||||
function stdin() {
|
||||
var buf = '';
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', function(chunk){ buf += chunk; });
|
||||
process.stdin.on('end', function(){
|
||||
var output;
|
||||
if (options.client) {
|
||||
output = pug.compileClient(buf, options);
|
||||
} else {
|
||||
var fn = pug.compile(buf, options);
|
||||
var output = fn(options);
|
||||
}
|
||||
process.stdout.write(output);
|
||||
}).resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given path, compiling the pug files found.
|
||||
* Always walk the subdirectories.
|
||||
*
|
||||
* @param path path of the file, might be relative
|
||||
* @param rootPath path relative to the directory specified in the command
|
||||
*/
|
||||
|
||||
function renderFile(path, rootPath) {
|
||||
var re = /\.(?:pug|jade)$/;
|
||||
var stat = fs.lstatSync(path);
|
||||
// Found pug file
|
||||
if (stat.isFile() && re.test(path)) {
|
||||
// Try to watch the file if needed. watchFile takes care of duplicates.
|
||||
if (program.watch) watchFile(path, null, rootPath);
|
||||
if (program.nameAfterFile) {
|
||||
options.name = getNameFromFileName(path);
|
||||
}
|
||||
var fn = options.client
|
||||
? pug.compileFileClient(path, options)
|
||||
: pug.compileFile(path, options);
|
||||
if (program.watch && fn.dependencies) {
|
||||
// watch dependencies, and recompile the base
|
||||
fn.dependencies.forEach(function (dep) {
|
||||
watchFile(dep, path, rootPath);
|
||||
});
|
||||
}
|
||||
|
||||
// --extension
|
||||
var extname;
|
||||
if (program.extension) extname = '.' + program.extension;
|
||||
else if (options.client) extname = '.js';
|
||||
else extname = '.html';
|
||||
|
||||
// path: foo.pug -> foo.<ext>
|
||||
path = path.replace(re, extname);
|
||||
if (program.out) {
|
||||
// prepend output directory
|
||||
if (rootPath) {
|
||||
// replace the rootPath of the resolved path with output directory
|
||||
path = relative(rootPath, path);
|
||||
} else {
|
||||
// if no rootPath handling is needed
|
||||
path = basename(path);
|
||||
}
|
||||
path = resolve(program.out, path);
|
||||
}
|
||||
var dir = resolve(dirname(path));
|
||||
mkdirp.sync(dir);
|
||||
var output = options.client ? fn : fn(options);
|
||||
fs.writeFileSync(path, output);
|
||||
consoleLog(' ' + chalk.gray('rendered') + ' ' + chalk.cyan('%s'), normalize(path));
|
||||
// Found directory
|
||||
} else if (stat.isDirectory()) {
|
||||
var files = fs.readdirSync(path);
|
||||
files.map(function(filename) {
|
||||
return path + '/' + filename;
|
||||
}).forEach(function (file) {
|
||||
render(file, rootPath || path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sensible name for a template function from a file path
|
||||
*
|
||||
* @param {String} filename
|
||||
* @returns {String}
|
||||
*/
|
||||
function getNameFromFileName(filename) {
|
||||
var file = basename(filename).replace(/\.(?:pug|jade)$/, '');
|
||||
return file.toLowerCase().replace(/[^a-z0-9]+([a-z])/g, function (_, character) {
|
||||
return character.toUpperCase();
|
||||
}) + 'Template';
|
||||
}
|
37
App/Source/node_modules/pug-cli/package.json
generated
vendored
Normal file
37
App/Source/node_modules/pug-cli/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "pug-cli",
|
||||
"version": "1.0.0-alpha6",
|
||||
"description": "Pug's CLI interface",
|
||||
"bin": {
|
||||
"pug": "./index.js"
|
||||
},
|
||||
"preferGlobal": true,
|
||||
"keywords": [],
|
||||
"dependencies": {
|
||||
"chalk": "^1.0.0",
|
||||
"commander": "^2.8.1",
|
||||
"pug": "^2.0.0-alpha7",
|
||||
"mkdirp": "^0.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "*",
|
||||
"mocha": "*",
|
||||
"rimraf": "^2.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec --bail",
|
||||
"precoverage": "rimraf coverage && rimraf cov-pt*",
|
||||
"coverage": "istanbul cover --report none --dir cov-pt0 node_modules/mocha/bin/_mocha -- -R dot",
|
||||
"postcoverage": "istanbul report --include cov-pt\\*/coverage.json && rimraf cov-pt*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pugjs/pug-cli.git"
|
||||
},
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"maintainers": [
|
||||
"Timothy Gu <timothygu99@gmail.com>",
|
||||
"Forbes Lindesay <forbes@lindesay.co.uk>"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
3
App/Source/node_modules/pug-cli/test/dependencies/dependency1.pug
generated
vendored
Normal file
3
App/Source/node_modules/pug-cli/test/dependencies/dependency1.pug
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
html
|
||||
body
|
||||
block container
|
1
App/Source/node_modules/pug-cli/test/dependencies/dependency2.pug
generated
vendored
Normal file
1
App/Source/node_modules/pug-cli/test/dependencies/dependency2.pug
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
include dependency3.pug
|
1
App/Source/node_modules/pug-cli/test/dependencies/dependency3.pug
generated
vendored
Normal file
1
App/Source/node_modules/pug-cli/test/dependencies/dependency3.pug
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
strong dependency3
|
1
App/Source/node_modules/pug-cli/test/dependencies/include2.pug
generated
vendored
Normal file
1
App/Source/node_modules/pug-cli/test/dependencies/include2.pug
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
include dependency2.pug
|
619
App/Source/node_modules/pug-cli/test/index.js
generated
vendored
Normal file
619
App/Source/node_modules/pug-cli/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,619 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
var cp = require('child_process');
|
||||
var mkdirp = require('mkdirp');
|
||||
var rimraf = require('rimraf');
|
||||
|
||||
// Sets directory to output coverage data to
|
||||
// Incremented every time getRunner() is called.
|
||||
var covCount = 1;
|
||||
var isIstanbul = process.env.running_under_istanbul;
|
||||
|
||||
/*
|
||||
* I/O utilities for temporary directory.
|
||||
*/
|
||||
function j(paths) {
|
||||
return path.join.apply(path, paths);
|
||||
}
|
||||
|
||||
function t(paths) {
|
||||
paths = Array.isArray(paths) ? paths : [paths];
|
||||
var args = [__dirname, 'temp'].concat(paths);
|
||||
return j(args);
|
||||
}
|
||||
|
||||
function r(paths) {
|
||||
return fs.readFileSync(t(paths), 'utf8');
|
||||
}
|
||||
|
||||
function rs(paths) {
|
||||
return fs.createReadStream(t(paths));
|
||||
}
|
||||
|
||||
function w(paths, content) {
|
||||
return fs.writeFileSync(t(paths), content);
|
||||
}
|
||||
|
||||
function a(paths, content) {
|
||||
return fs.appendFileSync(t(paths), content);
|
||||
}
|
||||
|
||||
function u(paths) {
|
||||
return fs.unlinkSync(t(paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array containing the routine to run the pug CLI. If this file is
|
||||
* being processed with istanbul then this function will return a routine
|
||||
* asking istanbul to store coverage data to a unique directory
|
||||
* (cov-pt<covCount>/).
|
||||
*/
|
||||
function getRunner() {
|
||||
var pugExe = j([__dirname, '..', 'index.js']);
|
||||
|
||||
if (!isIstanbul) return [process.argv[0], [pugExe]];
|
||||
else {
|
||||
return [ 'istanbul',
|
||||
[ 'cover',
|
||||
'--print', 'none',
|
||||
'--report', 'none',
|
||||
'--root', process.cwd(),
|
||||
'--dir', process.cwd() + '/cov-pt' + (covCount++),
|
||||
pugExe,
|
||||
'--' ] ];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Run Pug CLI.
|
||||
*
|
||||
* @param args Array of arguments
|
||||
* @param [stdin] Stream of standard input
|
||||
* @param callback Function to call when the process finishes
|
||||
*/
|
||||
function run(args, stdin, callback) {
|
||||
if (arguments.length === 2) {
|
||||
callback = stdin;
|
||||
stdin = null;
|
||||
}
|
||||
var runner = getRunner();
|
||||
var proc = cp.execFile(runner[0], runner[1].concat(args), {
|
||||
cwd: t([])
|
||||
}, callback);
|
||||
if (stdin) stdin.pipe(proc.stdin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timing limits for a test case
|
||||
*/
|
||||
function timing(testCase) {
|
||||
if (isIstanbul) {
|
||||
testCase.timeout(20000);
|
||||
testCase.slow(3000);
|
||||
} else {
|
||||
testCase.timeout(12500);
|
||||
testCase.slow(2000);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Make temporary directories
|
||||
*/
|
||||
rimraf.sync(t([]));
|
||||
mkdirp.sync(t(['depwatch']));
|
||||
mkdirp.sync(t(['inputs', 'level-1-1']));
|
||||
mkdirp.sync(t(['inputs', 'level-1-2']));
|
||||
mkdirp.sync(t(['outputs', 'level-1-1']));
|
||||
mkdirp.sync(t(['outputs', 'level-1-2']));
|
||||
|
||||
/*
|
||||
* CLI utilities
|
||||
*/
|
||||
describe('miscellanea', function () {
|
||||
timing(this);
|
||||
it('--version', function (done) {
|
||||
run(['-V'], function (err, stdout) {
|
||||
if (err) done(err);
|
||||
assert.equal(stdout.trim(), 'pug version: ' + require('pug/package.json').version + '\npug-cli version: ' + require('../package.json').version);
|
||||
run(['--version'], function (err, stdout) {
|
||||
if (err) done(err);
|
||||
assert.equal(stdout.trim(), 'pug version: ' + require('pug/package.json').version + '\npug-cli version: ' + require('../package.json').version);
|
||||
done()
|
||||
});
|
||||
});
|
||||
});
|
||||
it('--help', function (done) {
|
||||
// only check that it doesn't crash
|
||||
run(['-h'], function (err, stdout) {
|
||||
if (err) done(err);
|
||||
run(['--help'], function (err, stdout) {
|
||||
if (err) done(err);
|
||||
done()
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('HTML output', function () {
|
||||
timing(this);
|
||||
it('works', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
|
||||
run(['--no-debug', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert(html === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('--extension', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.special-html', '<p>output not written</p>');
|
||||
|
||||
run(['--no-debug', '-E', 'special-html', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.special-html');
|
||||
assert(html === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('--basedir', function (done) {
|
||||
w('input.pug', 'extends /dependency1.pug');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '-b', j([__dirname, 'dependencies']), 'input.pug'], function (err, stdout) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert.equal(html, '<html><body></body></html>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
context('--obj', function () {
|
||||
it('JavaScript syntax works', function (done) {
|
||||
w('input.pug', '.foo= loc');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--obj', "{'loc':'str'}", 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert(html === '<div class="foo">str</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('JavaScript syntax does not accept UTF newlines', function (done) {
|
||||
w('input.pug', '.foo= loc');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--obj', "{'loc':'st\u2028r'}", 'input.pug'], function (err) {
|
||||
if (!err) return done(new Error('expecting error'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('JSON syntax accept UTF newlines', function (done) {
|
||||
w('input.pug', '.foo= loc');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--obj', '{"loc":"st\u2028r"}', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert.equal(html, '<div class="foo">st\u2028r</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('JSON file', function (done) {
|
||||
w('obj.json', '{"loc":"str"}');
|
||||
w('input.pug', '.foo= loc');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--obj', 'obj.json', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert(html === '<div class="foo">str</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('JavaScript module', function (done) {
|
||||
w('obj.js', 'module.exports = {loc: "str"};');
|
||||
w('input.pug', '.foo= loc');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--obj', 'obj.js', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert(html === '<div class="foo">str</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('stdio', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
run(['--no-debug'], rs('input.pug'), function (err, stdout, stderr) {
|
||||
if (err) return done(err);
|
||||
assert(stdout === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
context('--out', function () {
|
||||
it('works', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--out', 'outputs', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r(['outputs', 'input.html']);
|
||||
assert(html === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('works when input is a directory', function (done) {
|
||||
w(['inputs', 'input.pug'], '.foo bar 1');
|
||||
w(['inputs', 'level-1-1', 'input.pug'], '.foo bar 1-1');
|
||||
w(['inputs', 'level-1-2', 'input.pug'], '.foo bar 1-2');
|
||||
w(['outputs', 'input.html'], 'BIG FAT HEN 1');
|
||||
w(['outputs', 'level-1-1', 'input.html'], 'BIG FAT HEN 1-1');
|
||||
w(['outputs', 'level-1-2', 'input.html'], 'BIG FAT HEN 1-2');
|
||||
|
||||
run(['--no-debug', '--hierarchy', '--out', 'outputs', 'inputs'], function (err) {
|
||||
if (err) return done(err);
|
||||
var html = r(['outputs', 'input.html']);
|
||||
assert(html === '<div class="foo">bar 1</div>');
|
||||
var html = r(['outputs', 'level-1-1', 'input.html']);
|
||||
assert(html === '<div class="foo">bar 1-1</div>');
|
||||
var html = r(['outputs', 'level-1-2', 'input.html']);
|
||||
assert(html === '<div class="foo">bar 1-2</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('--silent', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '-s', 'input.pug'], function (err, stdout) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert.equal(html, '<div class="foo">bar</div>');
|
||||
assert.equal(stdout, '');
|
||||
|
||||
w('input.html', '<p>output not written</p>');
|
||||
run(['--no-debug', '--silent', 'input.pug'], function (err, stdout) {
|
||||
if (err) return done(err);
|
||||
var html = r('input.html');
|
||||
assert.equal(html, '<div class="foo">bar</div>');
|
||||
assert.equal(stdout, '');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('client JavaScript output', function () {
|
||||
timing(this);
|
||||
it('works', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.js', 'throw new Error("output not written");');
|
||||
run(['--no-debug', '--client', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var template = Function('', r('input.js') + ';return template;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('--name', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.js', 'throw new Error("output not written");');
|
||||
run(['--no-debug', '--client', '--name', 'myTemplate', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var template = Function('', r('input.js') + ';return myTemplate;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('--name --extension', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.special-js', 'throw new Error("output not written");');
|
||||
run(['--no-debug', '--client', '-E', 'special-js', 'input.pug'], function (err) {
|
||||
if (err) return done(err);
|
||||
var template = Function('', r('input.special-js') + ';return template;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('stdio', function (done) {
|
||||
w('input.pug', '.foo bar');
|
||||
w('input.js', 'throw new Error("output not written");');
|
||||
run(['--no-debug', '--client'], rs('input.pug'), function (err, stdout) {
|
||||
if (err) return done(err);
|
||||
var template = Function('', stdout + ';return template;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('--name-after-file', function (done) {
|
||||
w('input-file.pug', '.foo bar');
|
||||
w('input-file.js', 'throw new Error("output not written");');
|
||||
run(['--no-debug', '--client', '--name-after-file', 'input-file.pug'], function (err, stdout, stderr) {
|
||||
if (err) return done(err);
|
||||
var template = Function('', r('input-file.js') + ';return inputFileTemplate;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('--name-after-file _InPuTwIthWEiRdNaMME.pug', function (done) {
|
||||
w('_InPuTwIthWEiRdNaMME.pug', '.foo bar');
|
||||
w('_InPuTwIthWEiRdNaMME.js', 'throw new Error("output not written");');
|
||||
run(['--no-debug', '--client', '--name-after-file', '_InPuTwIthWEiRdNaMME.pug'], function (err, stdout, stderr) {
|
||||
if (err) return done(err);
|
||||
var template = Function('', r('_InPuTwIthWEiRdNaMME.js') + ';return InputwithweirdnammeTemplate;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('--watch', function () {
|
||||
var watchProc;
|
||||
var stdout = '';
|
||||
|
||||
function cleanup() {
|
||||
stdout = '';
|
||||
if (!watchProc) return;
|
||||
|
||||
watchProc.stderr.removeAllListeners('data');
|
||||
watchProc.stdout.removeAllListeners('data');
|
||||
watchProc.removeAllListeners('error');
|
||||
watchProc.removeAllListeners('close');
|
||||
}
|
||||
|
||||
after(function () {
|
||||
cleanup();
|
||||
watchProc.kill('SIGINT');
|
||||
watchProc = null;
|
||||
});
|
||||
|
||||
beforeEach(cleanup);
|
||||
|
||||
afterEach(function (done) {
|
||||
// pug --watch can only detect changes that are at least 1 second apart
|
||||
setTimeout(done, 1000);
|
||||
});
|
||||
|
||||
it('pass 1: initial compilation', function (done) {
|
||||
timing(this);
|
||||
|
||||
w('input-file.pug', '.foo bar');
|
||||
w('input-file.js', 'throw new Error("output not written (pass 1)");');
|
||||
var cmd = getRunner();
|
||||
cmd[1].push('--no-debug', '--client', '--name-after-file', '--watch', 'input-file.pug');
|
||||
watchProc = cp.spawn(cmd[0], cmd[1], {
|
||||
cwd: t([])
|
||||
});
|
||||
|
||||
watchProc.stdout.setEncoding('utf8');
|
||||
watchProc.stderr.setEncoding('utf8');
|
||||
watchProc.on('error', done);
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if (/rendered/.test(stdout)) {
|
||||
cleanup();
|
||||
|
||||
var template = Function('', r('input-file.js') + ';return inputFileTemplate;')();
|
||||
assert(template() === '<div class="foo">bar</div>');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
});
|
||||
it('pass 2: change the file', function (done) {
|
||||
w('input-file.js', 'throw new Error("output not written (pass 2)");');
|
||||
|
||||
watchProc.on('error', done);
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if (/rendered/.test(stdout)) {
|
||||
cleanup();
|
||||
|
||||
var template = Function('', r('input-file.js') + ';return inputFileTemplate;')();
|
||||
assert(template() === '<div class="foo">baz</div>');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
|
||||
w('input-file.pug', '.foo baz');
|
||||
});
|
||||
it('pass 3: remove the file then add it back', function (done) {
|
||||
w('input-file.js', 'throw new Error("output not written (pass 3)");');
|
||||
|
||||
watchProc.on('error', done)
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if (/rendered/.test(stdout)) {
|
||||
cleanup();
|
||||
|
||||
var template = Function('', r('input-file.js') + ';return inputFileTemplate;')();
|
||||
assert(template() === '<div class="foo">bat</div>');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
|
||||
u('input-file.pug');
|
||||
setTimeout(function () {
|
||||
w('input-file.pug', '.foo bat');
|
||||
}, 250);
|
||||
});
|
||||
it('pass 4: intentional errors in the pug file', function (done) {
|
||||
var stderr = '';
|
||||
var errored = false;
|
||||
|
||||
watchProc.on('error', done);
|
||||
watchProc.on('close', function() {
|
||||
errored = true;
|
||||
return done(new Error('Pug should not terminate in watch mode'));
|
||||
});
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if (/rendered/.test(stdout)) {
|
||||
stdout = '';
|
||||
return done(new Error('Pug compiles an erroneous file w/o error'));
|
||||
}
|
||||
});
|
||||
watchProc.stderr.on('data', function(buf) {
|
||||
stderr += buf;
|
||||
if (!/Invalid indentation/.test(stderr)) return;
|
||||
stderr = '';
|
||||
var template = Function('', r('input-file.js') + ';return inputFileTemplate;')();
|
||||
assert(template() === '<div class="foo">bat</div>');
|
||||
|
||||
watchProc.stderr.removeAllListeners('data');
|
||||
watchProc.stdout.removeAllListeners('data');
|
||||
watchProc.removeAllListeners('error');
|
||||
watchProc.removeAllListeners('exit');
|
||||
// The stderr event will always fire sooner than the close event.
|
||||
// Wait for it.
|
||||
setTimeout(function() {
|
||||
if (!errored) done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
w('input-file.pug', [
|
||||
'div',
|
||||
' div',
|
||||
'\tarticle'
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('--watch with dependencies', function () {
|
||||
var watchProc;
|
||||
var stdout = '';
|
||||
|
||||
before(function () {
|
||||
function copy(file) {
|
||||
w(['depwatch', file],
|
||||
fs.readFileSync(j([__dirname, 'dependencies', file])));
|
||||
}
|
||||
copy('include2.pug');
|
||||
copy('dependency2.pug');
|
||||
copy('dependency3.pug');
|
||||
});
|
||||
|
||||
function cleanup() {
|
||||
stdout = '';
|
||||
|
||||
if (!watchProc) return;
|
||||
|
||||
watchProc.stderr.removeAllListeners('data');
|
||||
watchProc.stdout.removeAllListeners('data');
|
||||
watchProc.removeAllListeners('error');
|
||||
watchProc.removeAllListeners('close');
|
||||
}
|
||||
|
||||
after(function () {
|
||||
cleanup();
|
||||
watchProc.kill('SIGINT');
|
||||
watchProc = null;
|
||||
});
|
||||
|
||||
beforeEach(cleanup);
|
||||
|
||||
afterEach(function (done) {
|
||||
// pug --watch can only detect changes that are at least 1 second apart
|
||||
setTimeout(done, 1000);
|
||||
});
|
||||
|
||||
it('pass 1: initial compilation', function (done) {
|
||||
timing(this);
|
||||
|
||||
w(['depwatch', 'include2.html'], 'output not written (pass 1)');
|
||||
w(['depwatch', 'dependency2.html'], 'output not written (pass 1)');
|
||||
var cmd = getRunner();
|
||||
cmd[1].push('--watch', 'include2.pug', 'dependency2.pug');
|
||||
watchProc = cp.spawn(cmd[0], cmd[1], {
|
||||
cwd: t('depwatch')
|
||||
});
|
||||
|
||||
watchProc.stdout.setEncoding('utf8');
|
||||
watchProc.stderr.setEncoding('utf8');
|
||||
watchProc.on('error', done);
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if ((stdout.match(/rendered/g) || []).length === 2) {
|
||||
cleanup();
|
||||
|
||||
var output = r(['depwatch', 'include2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong>');
|
||||
output = r(['depwatch', 'dependency2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong>');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
});
|
||||
it('pass 2: change a dependency', function (done) {
|
||||
timing(this);
|
||||
|
||||
w(['depwatch', 'include2.html'], 'output not written (pass 2)');
|
||||
w(['depwatch', 'dependency2.html'], 'output not written (pass 2)');
|
||||
|
||||
watchProc.on('error', done);
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if ((stdout.match(/rendered/g) || []).length === 2) {
|
||||
cleanup();
|
||||
|
||||
var output = r(['depwatch', 'include2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong><p>Hey</p>');
|
||||
output = r(['depwatch', 'dependency2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong><p>Hey</p>');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
|
||||
a(['depwatch', 'dependency2.pug'], '\np Hey\n');
|
||||
});
|
||||
it('pass 3: change a deeper dependency', function (done) {
|
||||
timing(this);
|
||||
|
||||
w(['depwatch', 'include2.html'], 'output not written (pass 3)');
|
||||
w(['depwatch', 'dependency2.html'], 'output not written (pass 3)');
|
||||
|
||||
watchProc.on('error', done)
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if ((stdout.match(/rendered/g) || []).length === 2) {
|
||||
cleanup();
|
||||
|
||||
var output = r(['depwatch', 'include2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong><p>Foo</p><p>Hey</p>');
|
||||
output = r(['depwatch', 'dependency2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong><p>Foo</p><p>Hey</p>');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
|
||||
a(['depwatch', 'dependency3.pug'], '\np Foo\n');
|
||||
});
|
||||
it('pass 4: change main file', function (done) {
|
||||
timing(this);
|
||||
|
||||
w(['depwatch', 'include2.html'], 'output not written (pass 4)');
|
||||
w(['depwatch', 'dependency2.html'], 'output not written (pass 4)');
|
||||
|
||||
watchProc.on('error', done);
|
||||
watchProc.stdout.on('data', function(buf) {
|
||||
stdout += buf;
|
||||
if ((stdout.match(/rendered/g) || []).length === 1) {
|
||||
cleanup();
|
||||
|
||||
var output = r(['depwatch', 'include2.html']);
|
||||
assert.equal(output.trim(), '<strong>dependency3</strong><p>Foo</p><p>Hey</p><p>Baz</p>');
|
||||
output = r(['depwatch', 'dependency2.html']);
|
||||
assert.equal(output.trim(), 'output not written (pass 4)');
|
||||
|
||||
return done();
|
||||
}
|
||||
});
|
||||
|
||||
a(['depwatch', 'include2.pug'], '\np Baz\n');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user