injector.targets = function(filePath) { var html = $.load(fs.readFileSync(filePath)); var targets = this.reduce(html);//_.map(this.reduce(html)); return targets; };
/** * Build the YUIDoc for the sdk * @method yuidoc */ function yuidoc() { console.log('Generating YUIDoc...'); var builder, docOptions = { quiet: true, norecurse: true, paths: ['./sdk/src'], outdir: './docs/sdk/', themedir: './docs/src/sdk-template' }, json, readmeMd = fs.readFileSync('README.md', ENCODING); json = (new Y.YUIDoc(docOptions)).run(); // massage in some meta information from F2.json json.project = { cacheBuster: f2Info.sdk.cacheBuster, docsAssets: '../', version: f2Info.sdk.version }; docOptions = Y.Project.mix(json, docOptions); // hasClassMembers // ensures that the class has members and isn't just an empty namespace Y.Handlebars.registerHelper('hasClassMembers', function() { for (var i = 0, len = json.classitems.length; i < len; i++) { //console.log(json.classitems[i].class, this.name); if (json.classitems[i].class === this.name) { return ''; } } return 'hide'; }); // title tag Y.Handlebars.registerHelper('htmlTitle',function () { var name = this.displayName || this.name, title = name; if (title) { title = 'F2 - ' + title; } else { title = 'F2 - The Open Financial Framework'; } return title; }); // insert readme markdown Y.Handlebars.registerHelper('readme', function() { return builder.markdown(readmeMd, true); }); builder = new Y.DocBuilder(docOptions, json); builder.compile(function() { console.log('COMPLETE'); nextStep(); }); };
var preparingData = function() { var fsOptions = {encoding: 'utf8'}; var uiBase = fs.readFileSync('./less/amui.less', fsOptions); var widgetsStyleDeps = []; var widgetsStyle = ''; var widgetsStyleWithDeps = ''; var WIDGET_DIR = './widget'; var rejectWidgets = ['.DS_Store', 'blank', 'layout2', 'layout3', 'layout4', 'container', 'powered_by', 'tech_support', 'toolbar', 'switch_mode']; var allWidgets = _.reject(fs.readdirSync(WIDGET_DIR), function(widget) { return rejectWidgets.indexOf(widget) > -1; }); var modules = []; var modulesBasic = []; var modulesWidgets = []; allPlugins = fs.readdirSync('./js'); plugins = fs.readdirSync('./js'); var partials = '(function(undefined){\n'; partials += ' \'use strict\';\n\n'; partials += ' var registerAMUIPartials = function(hbs) {\n'; allWidgets.forEach(function(widget, i) { // read widget package.json var pkg = fs.readJsonFileSync(path. join(WIDGET_DIR, widget, 'package.json')); var srcPath = '../widget/' + widget + '/src/'; if (i === 0) { widgetsStyleDeps = _.union(widgetsStyleDeps, pkg.styleBase); } widgetsStyleDeps = _.union(widgetsStyleDeps, pkg.styleDependencies); jsWidgets.push(pkg.script); jsWidgets = _.union(jsWidgets, pkg.jsDependencies); widgetsStyle += '\r\n// ' + widget + '\r\n'; widgetsStyle += '@import "' + srcPath + pkg.style + '";' + '\r\n'; _.forEach(pkg.themes, function(item, index) { if (!item.hidden && item.name) { widgetsStyle += '@import "' + srcPath + widget + '.' + item.name + '.less";' + '\r\n'; } }); // read tpl var tpl = fs.readFileSync(path. join(WIDGET_DIR, widget, 'src', widget + '.hbs'), fsOptions); partials += format(' hbs.registerPartial(\'%s\', %s);\n\n', widget, JSON.stringify(tpl)); }); widgetsStyleDeps.forEach(function(dep) { widgetsStyleWithDeps += format('@import "%s";\n', dep); }); fs.writeFileSync('./less/amazeui.less', uiBase + widgetsStyle); fs.writeFileSync('./less/amazeui.widgets.less', widgetsStyleWithDeps + widgetsStyle); /** * Prepare JavaScript Data */ // for amazeui.basic.js jsBasic = _.union(config.js.base, allPlugins); // for amazeui.js jsAll = _.union(jsBasic, jsWidgets); jsWidgets = _.union(config.js.base, jsWidgets); pluginsNotUsed = _.difference(plugins, jsWidgets); pluginsUsed = _.remove(plugins, function(plugin) { return pluginsNotUsed.indexOf(plugin) == -1; }); jsWidgets = _.union(config.js.base, pluginsUsed, jsWidgets); // seajs.use[''...] jsAll.forEach(function(js) { var basename = path.basename(js, '.js'); modules.push(basename); if (basename !== 'amazeui' || basename !== 'amazeui.legacy') { initAll += 'require(\'./' + basename + '\');\n'; } if (jsWidgets.indexOf(js) > -1) { modulesWidgets.push(basename); } if (jsBasic.indexOf(js) > -1) { modulesBasic.push(basename); } }); initAll += '\nmodule.exports = $.AMUI;\n'; // initAll = 'require(' + JSON.stringify(modules) + ');'; initBasic = 'require(' + JSON.stringify(modulesBasic) + ');'; initWidgets = 'require(' + JSON.stringify(modulesWidgets) + ');'; // sort for concat jsWidgetsSorted = _.union(jsWidgets, [initWidgets]); jsAllSorted = _.union(jsAll); jsBasicSorted = _.union(jsBasic, [initBasic]); partials += ' };\n\n'; partials += ' if (typeof module !== \'undefined\' && module.exports) {\n'; partials += ' module.exports = registerAMUIPartials;\n' + ' }\n\n'; partials += ' this.Handlebars && registerAMUIPartials(this.Handlebars);\n'; partials += '}).call(this);\n'; // write partials fs.writeFileSync(path.join('./vendor/amazeui.hbs.partials.js'), partials); fs.writeFileSync(path.join('./js/amazeui.js'), initAll); };
CustomReplace.prototype.getConfig = function (srcDir) { var configPath = path.join(srcDir, this.options.configPath); return JSON.parse(fs.readFileSync(configPath, { encoding: 'utf8' })); };
function getNodeDefinitions(filename) { var regExp = /<script.+?type=['"]text\/javascript['"].*?>([\S\s]*?)<\/script>/ig; var content = fs.readFileSync(filename,'utf8'); // console.error(filename); var parts = []; var match; while((match = regExp.exec(content)) !== null) { var block = match[1]; parts.push(match[1]); } if (parts.length === 0) { throw new Error("No <script> sections found"); } var defs = {}; var errors = []; var count = 0; parts.forEach(function(p) { try { var a = acorn.parse(p); // walk.simple(a,{Property(node) { if (node.key.name === 'defaults') console.log(node.value.properties.map(function(n) { return n.key.name})); }}) walk.simple(a,{ CallExpression(node) { if (node.callee.property && node.callee.property.name === 'registerType') { var nodeTypeNode = node.arguments[0]; var nodeDefNode = node.arguments[1]; if (nodeTypeNode.type === 'Literal') { var defType = nodeTypeNode.value; if (nodeDefNode.type === 'ObjectExpression') { defs[defType] = {}; count++; nodeDefNode.properties.forEach(function(nodeDef) { if (nodeDef.key.name === 'defaults') { if (!nodeDef.value.properties) { errors.push({ code:"defaults-not-inline" }); } else { defs[defType].defaults = {}; nodeDef.value.properties.forEach(function(n) { defs[defType].defaults[n.key.name] = {}; }); } } else if (nodeDef.key.name === 'credentials') { if (!nodeDef.value.properties) { errors.push({ code:"credentials-not-inline" }); } else { defs[defType].credentials = nodeDef.value.properties.map(function(n) { return n.key.name; }); } } else if (nodeDef.key.name === 'icon') { if (nodeDef.value.type === 'Literal') { defs[defType].icon = nodeDef.value.value; } else { errors.push({ code:"icon-not-inline" }); } } else if (nodeDef.key.name === 'color') { if (nodeDef.value.type === 'Literal') { defs[defType].color = nodeDef.value.value; } else { errors.push({ code:"color-not-inline" }); } } else if (nodeDef.key.name === 'inputs') { if (nodeDef.value.type === 'Literal') { defs[defType].inputs = nodeDef.value.value; } else { errors.push({ code:"inputs-not-inline" }); } } else if (nodeDef.key.name === 'outputs') { if (nodeDef.value.type === 'Literal') { defs[defType].outputs = nodeDef.value.value; } else { errors.push({ code:"outputs-not-inline" }); } } }); } else { errors.push({ code:"non-objectexpression", message:util.inspect(nodeDefNode) }); } } else { errors.push({ code:"non-literal", message:util.inspect(nodeTypeNode) }); } } } }); } catch(err) { errors.push({ code:"parse", message: "at:"+err.pos+" "+p.substr(Math.max(0,err.pos-10),20) }); throw err; } }); if (count === 0) { if (errors.length > 0) { throw new Error("Syntax errors parsing <script>:\n "+errors.map(function(err) { return err.message; }).join("\n ")); } throw new Error("No type definitions found"); } if (errors.length > 0) { defs.__errors__ = errors; } return defs; }
requirejs.optimize(require_config, function (modules) { var key, port = 8000; //Clean up optimizer fse.deleteSync(output_directory + '/js'); fse.copySync(output_directory + '/tmp/main.js', output_directory + '/js/main.js'); fse.deleteSync(output_directory + '/tmp'); console.log('Success: ' + modules); index_template = hogan.compile(fse.readFileSync('index.html').toString()); server.use(express.logger()); server.use(express.compress()); server.use(express.static(__dirname + '/' + output_directory)); for (key in views) { if (views.hasOwnProperty(key)) { server.get('/' + key, (function (key) { return function (request, response) { var data = request.params, view = views[key], parallel_options = {}; view.models.forEach(function (model) { model = models[model]; parallel_options[model.name] = function (callback) { requestHttp({ url: model.url, json: true }, function (err, response, body) { callback(err, body); }); }; }); async.parallel(parallel_options, function (err, results) { if (err) { throw err; } var key; for (key in results) { if (results.hasOwnProperty(key)) { data[key] = results[key]; } } response.send(index_template.render({ content: view.template.render(data) })); }); }; }(key))); } } server.get('*', function (request, response) { response.send(404, index_template.render({ content: views['404'].template.render({}) })); }); server.use(function(error, request, response, next) { console.log('Error!: ' + error.stack); response.send(500, 'Internal Server Error'); }); if (process.argv.length >= 3) { port = process.argv[2]; } server.listen(port); console.log('Listening on port ' + port); }, function (error) {
exports.getHelp = function() { return fs.readFileSync(__dirname + '/../cli.md').toString(); };
.map(p => fs.readFileSync(p).toString())
// dependencies // npm install fs-extra // npm install dot var fs = require('fs-extra'); var dot = require('dot'); dot.templateSettings.strip = false; var paths = { html: 'html/file.html' }; paths.source = 'source/' + paths.html; var sourceHtml = fs.readFileSync(paths.source, 'utf8'); var tplFn = dot.template(sourceHtml); var tplResult = tplFn({ name: 'Walker', lists: [ { name: 'Tom', age: 22 }, { name: 'Mr.Zhang', age: 18 }, { name: 'Mr.Wang',
function () { excludesFilePath = tempFolder + Path.sep + '.excludes'; vaultIgnore = VaultIgnoreParser.compile(Fs.readFileSync(excludesFilePath, 'utf8')); return buildSyncStatusList(filters, vaultIgnore, tempFolder + Path.sep + JCR_ROOT + filter).then( function (_fileSyncStatus) { fileSyncStatus = _fileSyncStatus; } ).then( function () { return exists(tempFolder + Path.sep + JCR_ROOT + filter).then( function () { return copy( tempFolder + Path.sep + JCR_ROOT + filter, path, function (file) { var rPath = getRemotePath(file); var relativePath = Path.relative(tempFolder + Path.sep + JCR_ROOT, file); if (copyFilter(file, fileSyncStatus)) { pathsFromRemote[rPath] = true; var tempHash = tempHashes[relativePath]; var localHash = localHashes[relativePath]; if (localHash) { return !(localHash === tempHash); } return true; } return false; } ); }, function (err) { /** * if the file-system entry doesn't exist it means that it might have got * deleted on the server; do nothing */ } ); } ).then( function () { var shouldDeleteLocalFiles = false, emptyFileSyncStatus = true; for (var f in fileSyncStatus) { if (fileSyncStatus.hasOwnProperty(f)) { emptyFileSyncStatus = false; var entry = fileSyncStatus[f]; if (Path.basename(f) !== '.content.xml' && entry.result !== Constants.sync.FILTER_IGNORED) { shouldDeleteLocalFiles = true; break; } } } if (emptyFileSyncStatus) { shouldDeleteLocalFiles = true; } if (shouldDeleteLocalFiles) { getFolderContents(path).then( function (files) { var i, file, rPath; for (i = 0; i < files.length; i++) { file = files[i]; rPath = getRemotePath(file); if (!pathsFromRemote[rPath] && vaultIgnore.accepts(rPath.slice(1))) { if (!fileIsInBasicExcludes(file)) { fileSyncStatus[rPath] = { path: file, result: Constants.sync.DELETED_FROM_REMOTE }; remove(file).done(); } } } } ).done(); } } ).then( function () { return remove(tempFolder); } ); }
function getTemplate(filePath) { var tmpl = fs.readFileSync(filePath, 'utf-8'); var data = extractMeta(tmpl); return data; }
function (excludesFilePath) { if (action === PUSH) { vaultIgnore = VaultIgnoreParser.compile(Fs.readFileSync(excludesFilePath, 'utf8')); return buildSyncStatusList(filters, vaultIgnore, path).then( function (_fileSyncStatus) { fileSyncStatus = _fileSyncStatus; } ).then( function () { return exists(path).then( function () { return copy( path, tempFolder + Path.sep + JCR_ROOT + Path.sep + (filterFolderPath === filter ? filterFolderPath : filter), function (file) { return copyFilter(file, fileSyncStatus); } ); } ); } ).then( function () { return remove(tempFolder + Path.sep + '.excludes'); } ).then( function () { var filterSyncStatusFilters = {}, filters = [], syncPath, f; // we need to get the set of filters for what we're pushing for (syncPath in fileSyncStatus) { if (fileSyncStatus.hasOwnProperty(syncPath)) { var entry = fileSyncStatus[syncPath]; if (entry.result && entry.filter instanceof Filter) { f = entry.filter; filterSyncStatusFilters[f.root] = f; } } } for (syncPath in filterSyncStatusFilters) { if (filterSyncStatusFilters.hasOwnProperty(syncPath)) { filters.push(filterSyncStatusFilters[syncPath]); } } return createPackageMetaInf(tempFolder, remotePath, filters, 'tmp/repo', packageName, packageVersion.toString()); } ).then( function () { return createContentPackageArchive(tempFolder, 'pkg'); } ).then( function (zipFileName) { return PackMgr.uploadPackage(server, acceptSelfSigned, user, password, zipFileName).then( function () { return PackMgr.installPackage(server, acceptSelfSigned, user, password, fullPackageName).then( function () { return PackMgr.deletePackage(server, acceptSelfSigned, user, password, fullPackageName); } ); } ); } ).then( function () { return remove(tempFolder); } ); } else if (action === PULL) { var zipFileName = '', localHashes, tempHashes; return createPackageMetaInf(tempFolder, remotePath, filters, 'tmp/repo', packageName, packageVersion.toString()).then( function () { return createContentPackageArchive(tempFolder, 'pkg').then( function (_zipFileName) { zipFileName = _zipFileName; return PackMgr.uploadPackage(server, acceptSelfSigned, user, password, zipFileName) .then( function () { return PackMgr.buildPackage(server, acceptSelfSigned, user, password, fullPackageName); } ); } ) } ).then( function () { return getTempWorkingFolder().then( function (newTempWorkingFolder) { return copy( tempFolder + Path.sep + '.excludes', newTempWorkingFolder + Path.sep + '.excludes' ).then( function () { return remove(tempFolder).then( function () { tempFolder = newTempWorkingFolder; } ); } ); } ); } ).then( function () { return PackMgr.downloadPackage( server, acceptSelfSigned, user, password, fullPackageName, tempFolder, 'pkg.zip' ).then( function (downloadedPackage) { return PackMgr.deletePackage(server, acceptSelfSigned, user, password, fullPackageName).then( function () { return extractContentPackageArchive(tempFolder, downloadedPackage); } ); } ).then( function () { return getFolderContents(path).then( function (files) { return prepareHashesForFiles(path, files).then( function (_hashes) { localHashes = _hashes; } ) } ); } ).then( function () { var relativeSyncPath = Path.relative(getRootPath(path), path); var tempSyncPath = tempFolder + Path.sep + relativeSyncPath; return getFolderContents(tempSyncPath).then( function (files) { return prepareHashesForFiles(tempSyncPath, files).then( function (_hashes) { tempHashes = _hashes; } ) } ); } ); } ).then( function () { excludesFilePath = tempFolder + Path.sep + '.excludes'; vaultIgnore = VaultIgnoreParser.compile(Fs.readFileSync(excludesFilePath, 'utf8')); return buildSyncStatusList(filters, vaultIgnore, tempFolder + Path.sep + JCR_ROOT + filter).then( function (_fileSyncStatus) { fileSyncStatus = _fileSyncStatus; } ).then( function () { return exists(tempFolder + Path.sep + JCR_ROOT + filter).then( function () { return copy( tempFolder + Path.sep + JCR_ROOT + filter, path, function (file) { var rPath = getRemotePath(file); var relativePath = Path.relative(tempFolder + Path.sep + JCR_ROOT, file); if (copyFilter(file, fileSyncStatus)) { pathsFromRemote[rPath] = true; var tempHash = tempHashes[relativePath]; var localHash = localHashes[relativePath]; if (localHash) { return !(localHash === tempHash); } return true; } return false; } ); }, function (err) { /** * if the file-system entry doesn't exist it means that it might have got * deleted on the server; do nothing */ } ); } ).then( function () { var shouldDeleteLocalFiles = false, emptyFileSyncStatus = true; for (var f in fileSyncStatus) { if (fileSyncStatus.hasOwnProperty(f)) { emptyFileSyncStatus = false; var entry = fileSyncStatus[f]; if (Path.basename(f) !== '.content.xml' && entry.result !== Constants.sync.FILTER_IGNORED) { shouldDeleteLocalFiles = true; break; } } } if (emptyFileSyncStatus) { shouldDeleteLocalFiles = true; } if (shouldDeleteLocalFiles) { getFolderContents(path).then( function (files) { var i, file, rPath; for (i = 0; i < files.length; i++) { file = files[i]; rPath = getRemotePath(file); if (!pathsFromRemote[rPath] && vaultIgnore.accepts(rPath.slice(1))) { if (!fileIsInBasicExcludes(file)) { fileSyncStatus[rPath] = { path: file, result: Constants.sync.DELETED_FROM_REMOTE }; remove(file).done(); } } } } ).done(); } } ).then( function () { return remove(tempFolder); } ); } ); } }
async function generateLockFile(tmpDir, logger) { logger.debug(`Spawning npm install to create ${tmpDir}/package-lock.json`); let lockFile = null; let stdout; let stderr; try { const startTime = process.hrtime(); let cmd; try { // See if renovate is installed locally const installedPath = path.join( await getInstalledPath('npm', { local: true, }), 'bin/npm-cli.js' ); cmd = `node ${installedPath}`; } catch (localerr) { logger.debug('No locally installed npm found'); // Look inside globally installed renovate try { const renovateLocation = await getInstalledPath('renovate'); const installedPath = path.join( await getInstalledPath('npm', { local: true, cwd: renovateLocation, }), 'bin/npm-cli.js' ); cmd = `node ${installedPath}`; } catch (nestederr) { logger.debug('Could not find globally nested npm'); // look for global npm try { const installedPath = path.join( await getInstalledPath('npm'), 'bin/npm-cli.js' ); cmd = `node ${installedPath}`; } catch (globalerr) { logger.warn('Could not find globally installed npm'); cmd = 'npm'; } } } logger.debug(`Using npm: ${cmd}`); cmd = `${cmd} --version && ${cmd} install`; cmd += ' --ignore-scripts'; // TODO: Switch to native util.promisify once using only node 8 ({ stdout, stderr } = await exec(cmd, { cwd: tmpDir, shell: true, env: { NODE_ENV: 'dev', PATH: process.env.PATH }, })); logger.debug(`npm stdout:\n${stdout}`); logger.debug(`npm stderr:\n${stderr}`); const duration = process.hrtime(startTime); const seconds = Math.round(duration[0] + duration[1] / 1e9); lockFile = fs.readFileSync(path.join(tmpDir, 'package-lock.json'), 'utf8'); logger.info( { seconds, type: 'package-lock.json', stdout, stderr }, 'Generated lockfile' ); } catch (err) /* istanbul ignore next */ { logger.warn( { err, stdout, stderr, }, 'npm install error' ); } return lockFile; }
return script.replace(/\@import "(.*)";/g, function(match, url){ return replace(fs.readFileSync(process.cwd() + '/assets/' + req.url.substr(0, req.url.lastIndexOf('/') + 1) + url, { encoding: 'utf8' })); });
var getAMDConfigFieldPath = function(project, key) { var buildPath = util.getAMDBuildPath(project); var content = fs.readFileSync(buildPath, 'utf8'); var data = eval("(" + content + ")"); return path.resolve(path.dirname(buildPath), data[key]); };
read: function (type) { return fs.readFileSync(filePaths[type], { encoding: 'utf8' }); }
keyboards.forEach((keyboard) => { if(!program.keyboards.length || program.keyboards.indexOf(keyboard.shortname+'/'+keyboard.id) >= 0) { // Validate each of the test files against the first tested compiler+engine version let localFailCount = 0; const localFail = knownFailures.hasOwnProperty([keyboard.id]) ? (msg) => { if(++localFailCount == 1) console.warn(`WARN: Not failing test because ${keyboard.id} is in known-failures.`); console.warn(`WARN: ${msg}`); } : fail; try { const baseResultFilename = path.join(KEYBOARDS_ROOT, keyboard.shortname, keyboard.id, 'tests', `${keyboard.id}-${baseCompilerVersion}-${baseEngineVersion}.results`); const baseResult = fs.readFileSync(baseResultFilename, 'utf8'); const baseResultJSON = JSON.parse(baseResult); const testsFilename = path.join(KEYBOARDS_ROOT, keyboard.shortname, keyboard.id, 'tests', `${keyboard.id}.tests`); const testsJSON = JSON.parse(fs.readFileSync(testsFilename, 'utf8')); const numTests = Object.keys(testsJSON.inputTests).length; // First, check the base result for errors for(let k in baseResultJSON) { if(typeof baseResultJSON[k] !== 'string') { let input = `${testsJSON.inputTests[k].context ? `"${testsJSON.inputTests[k].context}" ` : ""}+ ${keyname(testsJSON.inputTests[k].modifier, testsJSON.inputTests[k].key)}`; localFail(`${keyboard.shortname}/${keyboard.id}[${k}]: error in test: ${input}: ${baseResultJSON[k].error}`, 5); } } // Make sure every test is in the base result set if(Object.keys(baseResultJSON).length != numTests) { localFail(`${keyboard.shortname}/${keyboard.id}: base result set has fewer results (${Object.keys(baseResultJSON).length}) than expected (${numTests})`, 6); } //console.log(baseResultFilename, baseResult); testedCompilerVersions.forEach((cv) => { testedEngineVersions.forEach((ev) => { const resultFilename = path.join(KEYBOARDS_ROOT, keyboard.shortname, keyboard.id, 'tests', `${keyboard.id}-${cv}-${ev}.results`); const result = fs.readFileSync(resultFilename, 'utf8'); //console.log(resultFilename, result); // Naive string test first if(result !== baseResult) { // Now, report first mismatch and total number of mismatches after parsing JSON const resultJSON = JSON.parse(result); let errors = 0, prefix = `${keyboard.shortname}/${keyboard.id}`; for(let k in baseResultJSON) { if(resultJSON[k] !== baseResultJSON[k]) { if(++errors == 1 || program.logAllFailures) { let ix = k.toString(), whitespace = ' '.repeat(prefix.length + ix.length + 6), input = `${testsJSON.inputTests[k].context ? `"${testsJSON.inputTests[k].context}" ` : ""}+ ${keyname(testsJSON.inputTests[k].modifier, testsJSON.inputTests[k].key)}`; console.error(`${prefix}[${ix}]: expected: ${input} > "${baseResultJSON[k]}"`); console.error(`${whitespace}actual: ${input} > "${resultJSON[k]}"`); } } } localFail(`${keyboard.shortname}/${keyboard.id} ${errors}/${numTests} test(s) mismatched between (${baseCompilerVersion} / ${baseEngineVersion}) and (${cv} / ${ev})`, 4); } }); }); } catch(e) { localFail(`Failed to load test results for ${keyboard.shortname}/${keyboard.id}: ${typeof e == 'object' ? e.message : e}`, 7); } } });
].forEach(function (testObject) { assert.equal( fs.readFileSync(testObject.actual, { encoding: 'utf8' }), fs.readFileSync(testObject.expected, { encoding: 'utf8' }) ); });
/** * Build "Login Done" page for the specified version. * * @param {!Object} options */ function buildLoginDoneVersion(version, options) { options = options || {}; console.log('Bundling amp-login-done.html/js'); function copyHandler(name, err) { if (err) { return $$.util.log($$.util.colors.red('copy error: ', err)); } $$.util.log($$.util.colors.green('copied ' + name)); } var path = 'extensions/amp-access/' + version + '/'; var htmlPath = path + 'amp-login-done.html'; var jsPath = path + 'amp-login-done.js'; var watch = options.watch; if (watch === undefined) { watch = argv.watch || argv.w; } // Building extensions is a 2 step process because of the renaming // and CSS inlining. This watcher watches the original file, copies // it to the destination and adds the CSS. if (watch) { // Do not set watchers again when we get called by the watcher. var copy = Object.create(options); copy.watch = false; $$.watch(path + '/*', function() { buildLoginDoneVersion(version, copy); }); } // Build HTML. console.log('Processing ' + htmlPath); var html = fs.readFileSync(htmlPath, 'utf8'); var minHtml = html.replace( '../../../dist/v0/amp-login-done-' + version + '.max.js', 'https://cdn.ampproject.org/v0/amp-login-done-' + version + '.js'); mkdirSync('dist'); mkdirSync('dist/v0'); fs.writeFileSync('dist/v0/amp-login-done-' + version + '.html', minHtml); // Build JS. var js = fs.readFileSync(jsPath, 'utf8'); var builtName = 'amp-login-done-' + version + '.max.js'; var minifiedName = 'amp-login-done-' + version + '.js'; var latestName = 'amp-login-done-latest.js'; return gulp.src(path + '/*.js') .pipe($$.file(builtName, js)) .pipe(gulp.dest('build/all/v0/')) .on('end', function() { compileJs('./build/all/v0/', builtName, './dist/v0/', { watch: false, includePolyfills: true, minify: options.minify || argv.minify, minifiedName: minifiedName, preventRemoveAndMakeDir: options.preventRemoveAndMakeDir, latestName: latestName, }); }); }
setTimeout(function() { var f = fs.readFileSync(fileToTest); f.should.have.length(4); fs.unlinkSync(fileToTest); done(); },wait);
FirefoxProfile.prototype._addonDetails = function(addonPath, cb) { var details = { 'id': null, 'name': null, 'unpack': true, 'version': null, 'isNative': false }, self = this; function getNamespaceId(doc, url) { var namespaces = doc[Object.keys(doc)[0]].$, pref = null ; Object.keys(namespaces).forEach(function(prefix) { if (namespaces[prefix] === url) { pref = prefix.replace('xmlns:', ''); return false; } }); return pref; } // Attempt to parse the `install.rdf` inside the extension var doc; try { doc = fs.readFileSync(path.join(addonPath, 'install.rdf')); } // If not found, this is probably a jetpack style addon, so parse // the `package.json` file for addon details catch (e) { var manifest = require(path.join(addonPath, 'package.json')); // Jetpack addons are packed by default details.unpack = false; details.isNative = true; Object.keys(details).forEach(function (prop) { if (manifest[prop] !== undefined) { details[prop] = manifest[prop]; } }); cb && cb(details); return; } parseString(doc, function (err, doc) { var em = getNamespaceId(doc, 'http://www.mozilla.org/2004/em-rdf#'), rdf = getNamespaceId(doc, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); // first description var rdfNode = unprefix(doc, 'RDF', rdf); var description = unprefix(rdfNode, 'Description', rdf); if (description && description[0]) { description = description[0]; } Object.keys(description.$).forEach(function(attr) { if (details[attr.replace(em + ':', '')] !== undefined) { details[attr.replace(em + ':', '')] = description.$[attr]; } }); Object.keys(description).forEach(function(attr) { if (details[attr.replace(em + ':', '')] !== undefined) { // to convert boolean strings into booleans details[attr.replace(em + ':', '')] = self._sanitizePref(description[attr][0]); } }); cb && cb(details); }); };
setTimeout(function() { var f = fs.readFileSync(fileToTest).toString(); f.should.have.length(5); f.should.equal("fine\n"); done(); },wait);
const getRouterFileContent = (source) => { const dependence = `import Vue from 'vue'\n`; let routerContents = fs.readFileSync(source).toString(); routerContents = dependence + routerContents; return routerContents; }
function buildFrontEnd(){ var pattern_assembler = new pa(), media_hunter = new mh(), styleGuideExcludes = patternlab.config.styleGuideExcludes, styleguidePatterns = []; patternlab.buckets = []; patternlab.bucketIndex = []; patternlab.patternPaths = {}; patternlab.viewAllPaths = {}; //sort all patterns explicitly. patternlab.patterns = patternlab.patterns.sort(function(a,b){ if (a.name > b.name) { return 1; } if (a.name < b.name) { return -1; } // a must be equal to b return 0; }); //find mediaQueries media_hunter.find_media_queries('./source/css', patternlab); // check if patterns are excluded, if not add them to styleguidePatterns if (styleGuideExcludes && styleGuideExcludes.length) { for (i = 0; i < patternlab.patterns.length; i++) { // skip underscore-prefixed files if(isPatternExcluded(patternlab.patterns[i])){ if(patternlab.config.debug){ console.log('Omitting ' + patternlab.patterns[i].key + " from styleguide pattern exclusion."); } continue; } var key = patternlab.patterns[i].key; var typeKey = key.substring(0, key.indexOf('-')); var isExcluded = (styleGuideExcludes.indexOf(typeKey) > -1); if (!isExcluded) { styleguidePatterns.push(patternlab.patterns[i]); } } } else { styleguidePatterns = patternlab.patterns; } //build the styleguide var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'styleguide.mustache'), 'utf8'), styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), styleguideHtml); //build the viewall pages var prevSubdir = '', prevGroup = '', i; for (i = 0; i < patternlab.patterns.length; i++) { // skip underscore-prefixed files if(isPatternExcluded(patternlab.patterns[i])){ if(patternlab.config.debug){ console.log('Omitting ' + patternlab.patterns[i].key + " from view all rendering."); } continue; } var pattern = patternlab.patterns[i]; //create the view all for the section // check if the current section is different from the previous one if (pattern.patternGroup != prevGroup){ prevGroup = pattern.patternGroup; var viewAllPatterns = [], patternPartial = "viewall-" + pattern.patternGroup, j; for (j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].patternGroup === pattern.patternGroup) { //again, skip any sibling patterns to the current one that may have underscores if(isPatternExcluded(patternlab.patterns[j])){ if(patternlab.config.debug){ console.log('Omitting ' + patternlab.patterns[j].key + " from view all sibling rendering."); } continue; } viewAllPatterns.push(patternlab.patterns[j]); } } var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'viewall.mustache'), 'utf8'); var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); fs.outputFileSync(paths.public.patterns + pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + '/index.html', viewAllHtml); } //create the view all for the subsection // check if the current sub section is different from the previous one if (pattern.subdir !== prevSubdir) { prevSubdir = pattern.subdir; var viewAllPatterns = [], patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup, j; for (j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].subdir === pattern.subdir) { //again, skip any sibling patterns to the current one that may have underscores if(isPatternExcluded(patternlab.patterns[j])){ if(patternlab.config.debug){ console.log('Omitting ' + patternlab.patterns[j].key + " from view all sibling rendering."); } continue; } viewAllPatterns.push(patternlab.patterns[j]); } } var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'viewall.mustache'), 'utf8'); var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); fs.outputFileSync(paths.public.patterns + pattern.flatPatternPath + '/index.html', viewAllHtml); } } //build the patternlab website var patternlabSiteTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'index.mustache'), 'utf8'); //loop through all patterns.to build the navigation //todo: refactor this someday for(var i = 0; i < patternlab.patterns.length; i++){ var pattern = patternlab.patterns[i]; var bucketName = pattern.name.replace(/\\/g, '-').split('-')[1]; //check if the bucket already exists var bucketIndex = patternlab.bucketIndex.indexOf(bucketName); if(bucketIndex === -1){ // skip underscore-prefixed files. don't create a bucket on account of an underscored pattern if(isPatternExcluded(pattern)){ continue; } //add the bucket var bucket = new of.oBucket(bucketName); //add patternPath and viewAllPath patternlab.patternPaths[bucketName] = {}; patternlab.viewAllPaths[bucketName] = {}; //get the navItem var navItemName = pattern.subdir.split('/').pop(); navItemName = navItemName.replace(/(\d).(-)/g, ''); //get the navSubItem var navSubItemName = pattern.patternName.replace(/-/g, ' '); //test whether the pattern struture is flat or not - usually due to a template or page var flatPatternItem = false; if(navItemName === bucketName){ flatPatternItem = true; } //assume the navItem does not exist. var navItem = new of.oNavItem(navItemName); //assume the navSubItem does not exist. var navSubItem = new of.oNavSubItem(navSubItemName); navSubItem.patternPath = pattern.patternLink; navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name //add the patternState if it exists if(pattern.patternState){ navSubItem.patternState = pattern.patternState; } //if it is flat - we should not add the pattern to patternPaths if(flatPatternItem){ bucket.patternItems.push(navSubItem); //add to patternPaths addToPatternPaths(bucketName, pattern); } else{ bucket.navItems.push(navItem); bucket.navItemsIndex.push(navItemName); navItem.navSubItems.push(navSubItem); navItem.navSubItemsIndex.push(navSubItemName); //add to patternPaths addToPatternPaths(bucketName, pattern); //add the navViewAllItem var navViewAllItem = new of.oNavSubItem("View All"); navViewAllItem.patternPath = pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + "/index.html"; navViewAllItem.patternPartial = "viewall-" + pattern.patternGroup; bucket.patternItems.push(navViewAllItem); patternlab.viewAllPaths[bucketName]['viewall'] = pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length); } //add the bucket. patternlab.buckets.push(bucket); patternlab.bucketIndex.push(bucketName); //done } else{ //find the bucket var bucket = patternlab.buckets[bucketIndex]; //get the navItem //if there is one or more slashes in the subdir, get everything after //the last slash. if no slash, get the whole subdir string and strip //any numeric + hyphen prefix var navItemName = pattern.subdir.split('/').pop().replace(/^\d*\-/, ''); //get the navSubItem var navSubItemName = pattern.patternName.replace(/-/g, ' '); //assume the navSubItem does not exist. var navSubItem = new of.oNavSubItem(navSubItemName); navSubItem.patternPath = pattern.patternLink; navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name //add the patternState if it exists if(pattern.patternState){ navSubItem.patternState = pattern.patternState; } //test whether the pattern struture is flat or not - usually due to a template or page var flatPatternItem = false; if(navItemName === bucketName){ flatPatternItem = true; } //if it is flat - we should not add the pattern to patternPaths if(flatPatternItem){ // skip underscore-prefixed files if(isPatternExcluded(pattern)){ continue; } //add the navItem to patternItems bucket.patternItems.push(navSubItem); //add to patternPaths addToPatternPaths(bucketName, pattern); } else{ // only do this if pattern is included if(!isPatternExcluded(pattern)){ //check to see if navItem exists var navItemIndex = bucket.navItemsIndex.indexOf(navItemName); if(navItemIndex === -1){ var navItem = new of.oNavItem(navItemName); //add the navItem and navSubItem navItem.navSubItems.push(navSubItem); navItem.navSubItemsIndex.push(navSubItemName); bucket.navItems.push(navItem); bucket.navItemsIndex.push(navItemName); } else{ //add the navSubItem var navItem = bucket.navItems[navItemIndex]; navItem.navSubItems.push(navSubItem); navItem.navSubItemsIndex.push(navSubItemName); } } //check if we are moving to a new sub section in the next loop if (!patternlab.patterns[i + 1] || pattern.patternSubGroup !== patternlab.patterns[i + 1].patternSubGroup) { //add the navViewAllSubItem var navViewAllSubItem = new of.oNavSubItem(""); navViewAllSubItem.patternName = "View All"; navViewAllSubItem.patternPath = pattern.flatPatternPath + "/index.html"; navViewAllSubItem.patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup; navItem.navSubItems.push(navViewAllSubItem); navItem.navSubItemsIndex.push("View All"); } // just add to patternPaths addToPatternPaths(bucketName, pattern); } } patternlab.viewAllPaths[bucketName][pattern.patternSubGroup] = pattern.flatPatternPath; } //the patternlab site requires a lot of partials to be rendered. //patternNav var patternNavTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/patternNav.mustache'), 'utf8'); var patternNavPartialHtml = pattern_assembler.renderPattern(patternNavTemplate, patternlab); //ishControls var ishControlsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/ishControls.mustache'), 'utf8'); patternlab.config.mqs = patternlab.mediaQueries; var ishControlsPartialHtml = pattern_assembler.renderPattern(ishControlsTemplate, patternlab.config); //patternPaths var patternPathsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/patternPaths.mustache'), 'utf8'); var patternPathsPartialHtml = pattern_assembler.renderPattern(patternPathsTemplate, {'patternPaths': JSON.stringify(patternlab.patternPaths)}); //viewAllPaths var viewAllPathsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/viewAllPaths.mustache'), 'utf8'); var viewAllPathsPartialHtml = pattern_assembler.renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)}); //render the patternlab template, with all partials var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, {}, { 'ishControls': ishControlsPartialHtml, 'patternNav': patternNavPartialHtml, 'patternPaths': patternPathsPartialHtml, 'viewAllPaths': viewAllPathsPartialHtml }); fs.outputFileSync(path.resolve(paths.public.root, 'index.html'), patternlabSiteHtml); }
var contents = PACKAGE_FILES.map(function(f) { return fs.readFileSync(f, ENCODING); });
function buildPatterns(deletePatternDir){ patternlab.data = fs.readJSONSync(path.resolve(paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json')); patternlab.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8'); patternlab.footer = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'pattern-header-footer/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.partials = {}; patternlab.data.link = {}; var pattern_assembler = new pa(), entity_encoder = new he(), pattern_exporter = new pe(), patterns_dir = paths.source.patterns; pattern_assembler.combine_listItems(patternlab); //diveSync once to perform iterative populating of patternlab object diveSync(patterns_dir, { filter: function(path, dir) { if(dir){ var remainingPath = path.replace(patterns_dir, ''); var isValidPath = remainingPath.indexOf('/_') === -1; return isValidPath; } return true; } }, function(err, file){ //log any errors if(err){ console.log(err); return; } pattern_assembler.process_pattern_iterative(path.resolve(file), patternlab); }); //diveSync again to recursively include partials, filling out the //extendedTemplate property of the patternlab.patterns elements diveSync(patterns_dir, { filter: function(path, dir) { if(dir){ var remainingPath = path.replace(patterns_dir, ''); var isValidPath = remainingPath.indexOf('/_') === -1; return isValidPath; } return true; } }, function(err, file){ //log any errors if(err){ console.log(err); return; } pattern_assembler.process_pattern_recursive(path.resolve(file), patternlab); }); //now that all the main patterns are known, look for any links that might be within data and expand them //we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference pattern_assembler.parse_data_links(patternlab); //delete the contents of config.patterns.public before writing if(deletePatternDir){ fs.emptyDirSync(paths.public.patterns); } //render all patterns last, so lineageR works patternlab.patterns.forEach(function(pattern, index, patterns){ //render the pattern, but first consolidate any data we may have var allData = JSON.parse(JSON.stringify(patternlab.data)); allData = pattern_assembler.merge_data(allData, pattern.jsonFileData); //render the extendedTemplate with all data pattern.patternPartial = pattern_assembler.renderPattern(pattern.extendedTemplate, allData); //add footer info before writing var patternFooter = pattern_assembler.renderPattern(patternlab.footer, pattern); //write the compiled template to the public patterns directory fs.outputFileSync(paths.public.patterns + pattern.patternLink, patternlab.header + pattern.patternPartial + patternFooter); //write the mustache file too fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', '.mustache'), entity_encoder.encode(pattern.template)); //write the encoded version too fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', '.escaped.html'), entity_encoder.encode(pattern.patternPartial)); }); //export patterns if necessary pattern_exporter.export_patterns(patternlab); }
(async() => { const tmpDir = tmp.dirSync({ unsafeCleanup: true }); process.stdout.write("downloading '" + urlTldsAlpha + "'..."); const responseTldsAlpha = await request(urlTldsAlpha); if (responseTldsAlpha.statusCode != 200) { console.log("error"); console.error(meName + ": (FATAL) response status code " + responseTldsAlpha.statusCode + " from URL '" + urlTldsAlpha + "'"); process.exit(1); return; } if (!responseTldsAlpha.body) { console.log("error"); console.error(meName + ": (FATAL) empty response body " + responseTldsAlpha.statusCode + " from URL '" + urlTldsAlpha + "'"); process.exit(1); return; } const fileTldsAlphaTxt = tmpDir.name + '/tlds-alpha-by-domain.txt'; const fileNewTldsCsv = tmpDir.name + '/tlds.csv'; fs.writeFileSync(fileTldsAlphaTxt, responseTldsAlpha.body, 'utf8'); fs.writeFileSync(fileNewTldsCsv, '', 'utf8'); console.log('success'); process.stdout.write("downloading '" + urlDomainsDb + "'..."); const responseDomainsDb = await request(urlDomainsDb); if (responseDomainsDb.statusCode != 200) { console.log("error"); console.error(meName + ": (FATAL) response status code " + responseDomainsDb.statusCode + " from URL '" + urlDomainsDb + "'"); process.exit(1); return; } if (!responseDomainsDb.body) { console.log("error"); console.error(meName + ": (FATAL) empty response body " + responseDomainsDb.statusCode + " from URL '" + urlDomainsDb + "'"); process.exit(1); return; } const htmlDomainsDb = responseDomainsDb.body; var $ = cheerio.load(htmlDomainsDb); console.log('success'); process.stdout.write("building country / TLD hashmap..."); let tld2CountryName = {}; let missingTld = []; countries.all.forEach((c) => { let tld = country.tld(c.alpha3, 'ISO3'); if (!tld) { missingTld.push(c.alpha3); return; } tld2CountryName[tld] = c.name; }); console.log('done'); if (!program.quiet) { console.log(meName + ': NOTICE: the following "countries" did not have an assigned top level domain: ' + missingTld.join(', ')); } process.stdout.write("building description / TLD hashmap..."); let tld2Desc = {}; let parser = parse({ delimiter: ',' }); const csvPosMap = { domain: 0, description: 1, } parser.on('readable', function() { let tldData; while (tldData = parser.read()) { let tld = { domain: null, description: null, }; let prop; for (prop in tld) { if (typeof(tldData[csvPosMap[prop]]) !== 'undefined') { tld[prop] = tldData[csvPosMap[prop]]; } } if (tld.domain && tld.description) { tld2Desc[tld.domain] = tld.description; } } }); parser.write(fs.readFileSync(fileTldDescCsv)); parser.end(function() { console.log("done"); const tdPosMap = { domain: 0, type: 1, manager: 2, }; let tldSet = []; process.stdout.write("parsing IANA data..."); $('#tld-table').find('tr').each((i, element) => { let tld = { domain: null, type: null, manager: null, }; let tldData = []; // console.log('i ' + i); // console.log(element); $(element).find("td").each((iTd, elementTd) => { // console.log('iTd...'); // console.log(iTd); tldData.push($(elementTd).text()); }); for (var prop in tld) { if (typeof(tldData[tdPosMap[prop]]) !== 'undefined') { tld[prop] = tldData[tdPosMap[prop]]; } } if (!tld.domain) { return; } tld.domain = tld.domain.replace(/\s/g, '').replace(/\./g, ''); tldSet.push(tld); }); console.log('done'); const stringifier = stringify({ delimiter: ',' }); stringifier.on('readable', () => { let row; while (row = stringifier.read()) { fs.appendFileSync(fileNewTldsCsv, row, 'utf8') } }); process.stdout.write("serializing new 'tlds.csv'..."); for (var i = 0; i < tldSet.length; i++) { let tld = tldSet[i]; let csvRow = [tld.domain]; if ((tld.type == 'country-code') && (typeof(tld2CountryName[tld.domain]) !== 'undefined')) { csvRow.push(tld2CountryName[tld.domain]); } else { if (typeof(tld2Desc[tld.domain]) !== 'undefined') { csvRow.push(tld2Desc[tld.domain]); } else { csvRow.push(tld.manager); } } csvRow.push(tld.type); stringifier.write(csvRow); } stringifier.end(); console.log('done'); if (fs.existsSync(fileTldsCsv)) { const newMd5 = md5File.sync(fileNewTldsCsv); const csvMd5 = md5File.sync(fileTldsCsv); if (csvMd5 == newMd5) { console.error(meName + ": (NOTICE) ignoring newly generated 'tlds.csv' file that is identical to the existing file (md5: " + csvMd5 + ", path: " + fileTldsCsv + ")"); return; } const pathinfoTldsCsv = pathinfo(fileTldsCsv); const fileBackupTldsCsv = pathinfoTldsCsv.dirname + pathinfoTldsCsv.sep + pathinfoTldsCsv.basename + '-' + csvMd5 + '-backup.csv'; if (!fs.existsSync(fileBackupTldsCsv)) { fs.copySync(fileTldsCsv, fileBackupTldsCsv); } } process.stdout.write("saving new 'tlds.csv'..."); fs.copySync(fileNewTldsCsv, fileTldsCsv); console.log('done'); }); })();
exports.setupDefaultValues = function(config) { // to be able to run sitespeed.io you need a array of urls, a URL or a file if ((!config.url) && (!config.urls) && (!config.sites) && (!config.configFile)) { throw new Error('You must specify either a URL to test, a array with URL:s or a configuration file'); } // if we have default values not set in the config // add them from the default config Object.keys(defaultConfig).forEach(function(key) { if (!config.hasOwnProperty(key)) { config[key] = defaultConfig[key]; } }); // to make it easy later on, we add: // config.browertime = the browser(s) that will be run in browsertime (not phantomjs/slimerjs) // config.headlessTimings - boolean to run headless timings or not if (config.browser) { var b = config.browser.split(','), configuredBrowsers = b.filter(function(browser) { return defaultConfig.supportedBrowsers.indexOf(browser.toLowerCase()) > -1; }); if (configuredBrowsers.indexOf('headless') > -1) { config.headlessTimings = true; if (configuredBrowsers.length > 1) { var i = configuredBrowsers.indexOf('headless'); configuredBrowsers.splice(i, 1); config.browsertime = configuredBrowsers; } } else { config.browsertime = configuredBrowsers; } } // should we test YSlow rules, default is true config.runYslow = config.noYslow ? false : true; // Parse the proxy info as a real URL if (config.proxy) { config.urlProxyObject = urlParser.parse(config.proxy); } if (!config.connection) { config.connection = 'cable'; } // decide which rules to use ... if (config.profile === 'mobile') { config.rules = require('../conf/mobileRules.json'); config.ruleSet = 'sitespeed.io-mobile'; config.userAgent = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25'; config.viewPort = '320x444'; config.connection = 'mobile3g'; } else { // TODO this should be moved to the cli if (config.limitFile) { config.rules = fileHelper.getFileAsJSON(config.limitFile); } else { config.rules = require('../conf/desktopRules.json'); } // The rest use the default/configured one, will that work? :) } if (config.runYslow) { config.summaryBoxes = ['ruleScore']; config.sitesColumns = ['requests', 'criticalPathScore', 'pageWeight', 'cacheTime', 'ruleScore' ]; config.pageColumns = ['yslow.assets.js', 'yslow.assets.css', 'yslow.assets.image', 'yslow.requests', 'rules.expiresmod.items', 'yslow.pageWeight', 'rules.avoidscalingimages.items', 'rules.criticalpath' ]; } else { config.summaryBoxes = []; config.sitesColumns = []; config.pageColumns = []; } if (config.gpsiKey) { config.summaryBoxes.push('scoreGPSI'); config.sitesColumns.push('scoreGPSI'); config.pageColumns.push('gpsi.gscore'); } config.summaryBoxes.push('criticalPathScore', 'jsSyncInHead', 'jsPerPage', 'cssPerPage', 'cssImagesPerPage', 'fontsPerPage', 'imagesPerPage', 'requests', 'requestsWithoutExpires', 'requestsWithoutGzip', 'docWeight', 'jsWeightPerPage', 'cssWeightPerPage', 'imageWeightPerPage', 'pageWeight', 'browserScaledImages', 'spofPerPage', 'numberOfDomains', 'singleDomainRequests', 'redirectsPerPage', 'cacheTime', 'timeSinceLastMod'); if (config.wptHost) { config.summaryBoxes.push('firstViewTTFBWPT', 'firstViewSpeedIndexWPT', 'repeatViewSpeedIndexWPT', 'firstViewVisualCompleteWPT', 'repeatViewVisualCompleteWPT'); config.sitesColumns.push('firstViewSpeedIndexWPT', 'repeatViewSpeedIndexWPT'); } if (config.browsertime) { config.summaryBoxes.push('serverResponseTime', 'backEndTime', 'frontEndTime', 'domContentLoadedTime', 'speedIndex', 'pageLoadTime', 'firstPaint'); config.sitesColumns.push('serverResponseTime', 'domContentLoadedTime'); config.pageColumns.push('timings.serverResponseTime.median', 'timings.domContentLoadedTime.median'); } // only show real browsers data if we configured both of them else if (config.headlessTimings) { config.summaryBoxes.push('domContentLoadedTimeHeadless', 'pageLoadTimeHeadless'); config.sitesColumns.push('domContentLoadedTimeHeadless'); config.pageColumns.push('headless.domContentLoadedTime.median'); } // if we configure columns, lets override everything if (config.columns) { config.pageColumns = config.columns[0].split(','); } if (config.boxes) { if (config.boxes[0].indexOf('+') === 0) { config.boxes[0].split(',').forEach(function(box) { if (box.indexOf('+') === 0) { config.summaryBoxes.push(box.substring(1)); } else { config.summaryBoxes.push(box); } }); } else { config.summaryBoxes = config.boxes[0].split(','); } } config.dataDir = 'data'; config.supportedBrowsers = defaultConfig.supportedBrowsers; if (config.depth) { config.deep = config.depth; } // If we supply a configuration file, then it will override all current conf, meaning // we can easily use the same conf over and over again if (config.configFile) { // keep track of new url:s var oldConfig = config; config = JSON.parse(fs.readFileSync(config.configFile)); if (oldConfig.url) { config.url = oldConfig.url; config.urls = undefined; config.file = undefined; } else if (oldConfig.urls) { config.url = undefined; config.urls = oldConfig.urls; config.file = undefined; } else if (oldConfig.file) { config.url = undefined; config.urls = undefined; config.file = oldConfig.file; } } // The run always has a fresh date config.run = {}; config.run.date = new Date(); // Setup the absolute result dir var startPath = path.resolve(config.resultBaseDir); if (!config.outputFolderName) { config.startFolder = moment(config.run.date).format('YYYY-MM-DD-HH-mm-ss'); } else { config.startFolder = config.outputFolderName; } if (config.url) { config.urlObject = urlParser.parse(config.url); if (config.suppressDomainFolder) { config.run.absResultDir = path.join(startPath, config.startFolder); } else { config.run.absResultDir = path.join(startPath, config.urlObject.hostname, config.startFolder); } } else if (config.urls) { // if we have a file, use that, else take the first domain name and create the dir if (config.file) { config.run.absResultDir = path.join(startPath, path.basename(config.file), config.startFolder); } else { if (config.suppressDomainFolder) { config.run.absResultDir = path.join(startPath, config.startFolder); } else { var firstUrl = urlParser.parse(config.urls[0]); config.run.absResultDir = path.join(startPath, firstUrl.hostname, config.startFolder); } } } else if (config.sites) { // The log file will end up here config.run.absResultDir = path.join(startPath, 'sites', config.startFolder); } return config; };
.then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts'); expect(existsSync(testPath)).to.equal(true); var contents = fs.readFileSync(testPath, 'utf8'); expect(contents.indexOf('selector: \'test-mycomp\'') === -1).to.equal(false); });
function getFile(path) { console.log('Trying to read this file : ' + path); return fs.readFileSync(path,{'encoding':'utf8'}); }