How to use the pn/fs.exists function in pn

To help you get started, we’ve selected a few pn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wikimedia / parsoid / tools / js2php.js View on Github external
Promise.async(function *() {
	const files = (yield childProcess.execFile(
		'git', ['ls-files'], {
			cwd: path.join(BASEDIR, 'lib'),
			env: process.env,
		}).promise).stdout.split(/\n/g).filter(s => !!s);
	for (let oldFile of files) {
		const newFile = path.join(BASEDIR, 'src', remapName(oldFile));
		oldFile = path.join(BASEDIR, 'lib', oldFile);
		console.assert(yield fs.exists(oldFile));
		if (!(yield fs.exists(newFile))) { continue; /* Skip this */ }
		/* check for the watermark string; only overwrite if it is present */
		/* this ensures we don't overwrite actually-ported files */
		if (!WATERMARK_RE.test(yield fs.readFile(newFile, 'utf8'))) { continue; }

		/* run our translation tool! */
		var isPeg = /\.pegjs$/.test(oldFile);
		try {
			var args = (isPeg ? [ '--braced' ] : [])
				.concat([
					'--namespace', 'Parsoid',
					'--watermark', WATERMARK,
					oldFile, newFile,
				]);
			yield childProcess.execFile(
				path.join(BASEDIR, 'node_modules', '.bin', 'js2php'), args, {
					cwd: BASEDIR,
github wikimedia / parsoid / tools / js2php.js View on Github external
Promise.async(function *() {
	const files = (yield childProcess.execFile(
		'git', ['ls-files'], {
			cwd: path.join(BASEDIR, 'lib'),
			env: process.env,
		}).promise).stdout.split(/\n/g).filter(s => !!s);
	for (let oldFile of files) {
		const newFile = path.join(BASEDIR, 'src', remapName(oldFile));
		oldFile = path.join(BASEDIR, 'lib', oldFile);
		console.assert(yield fs.exists(oldFile));
		if (!(yield fs.exists(newFile))) { continue; /* Skip this */ }
		/* check for the watermark string; only overwrite if it is present */
		/* this ensures we don't overwrite actually-ported files */
		if (!WATERMARK_RE.test(yield fs.readFile(newFile, 'utf8'))) { continue; }

		/* run our translation tool! */
		var isPeg = /\.pegjs$/.test(oldFile);
		try {
			var args = (isPeg ? [ '--braced' ] : [])
				.concat([
					'--namespace', 'Parsoid',
					'--watermark', WATERMARK,
					oldFile, newFile,
				]);
			yield childProcess.execFile(
				path.join(BASEDIR, 'node_modules', '.bin', 'js2php'), args, {
github wikimedia / parsoid / bin / parserTests.js View on Github external
}
		// FIXME: now that we're no longer using node-style callbacks,
		// there's no reason we need to use recursion for this loop.
		return this.processCase(i + 1, options, earlyExit);
	} else {
		// Sanity check in case any tests were removed but we didn't update
		// the blacklist
		var blacklistChanged = false;
		var allModes = options.wt2html && options.wt2wt && options.html2wt &&
			options.html2html && options.selser &&
			!(options.filter || options.regex || options.maxtests);

		// update the blacklist, if requested
		if (allModes || ScriptUtils.booleanOption(options['rewrite-blacklist'])) {
			let old = null;
			const oldExists = yield fs.exists(this.blackListPath);
			if (oldExists) {
				old = yield fs.readFile(this.blackListPath, 'utf8');
			}
			const testBlackList = options.modes.reduce((tbl, mode) => {
				this.stats.modes[mode].failList.forEach((fail) => {
					if (!tbl.hasOwnProperty(fail.title)) {
						tbl[fail.title] = {};
					}
					tbl[fail.title][mode] = fail.raw;
				});
				return tbl;
			}, {});
			const contents = JSON.stringify(testBlackList, null, "    ");
			if (ScriptUtils.booleanOption(options['rewrite-blacklist'])) {
				yield fs.writeFile(this.blackListPath, contents, 'utf8');
			} else if (allModes && oldExists) {
github wikimedia / parsoid / bin / parse.js View on Github external
parsoidOptions.localsettings = path.resolve(__dirname, parsoidOptions.localsettings);
	}

	var nock, dir, nocksFile;
	if (argv.record || argv.replay) {
		if (!argv.pageName) {
			throw new Error(
				'pageName must be specified to use --record or --replay'
			);
		}
		dir = path.resolve(__dirname, '../nocks/');
		if (!(yield fs.exists(dir))) {
			yield fs.mkdir(dir);
		}
		dir = dir + '/' + (domain || prefix || 'enwiki');
		if (!(yield fs.exists(dir))) {
			yield fs.mkdir(dir);
		}
		nocksFile = dir + '/' + encodeURIComponent(argv.pageName || 'stdin') + '.js';
		if (argv.record) {
			nock = require('nock');
			nock.recorder.rec({ dont_print: true });
		} else {
			require(nocksFile);
		}
	}

	var logLevels;
	if (!argv.verbose) {
		logLevels = ["fatal", "error", "warn"];
	}
github wikimedia / parsoid / tools / fetch-parserTests.txt.js View on Github external
var computeSHA1 = Promise.async(function *(targetName) {
	var targetPath = path.join(testDir, targetName);
	if (!(yield fs.exists(targetPath))) {
		return "";
	}
	var contents = yield fs.readFile(targetPath);
	return crypto.createHash('sha1').update(contents).digest('hex')
		.toLowerCase();
});
github wikimedia / parsoid / bin / parse.js View on Github external
parsoidOptions.expandExtensions = false;
	}

	if (parsoidOptions.localsettings) {
		parsoidOptions.localsettings = path.resolve(__dirname, parsoidOptions.localsettings);
	}

	var nock, dir, nocksFile;
	if (argv.record || argv.replay) {
		if (!argv.pageName) {
			throw new Error(
				'pageName must be specified to use --record or --replay'
			);
		}
		dir = path.resolve(__dirname, '../nocks/');
		if (!(yield fs.exists(dir))) {
			yield fs.mkdir(dir);
		}
		dir = dir + '/' + (domain || prefix || 'enwiki');
		if (!(yield fs.exists(dir))) {
			yield fs.mkdir(dir);
		}
		nocksFile = dir + '/' + encodeURIComponent(argv.pageName || 'stdin') + '.js';
		if (argv.record) {
			nock = require('nock');
			nock.recorder.rec({ dont_print: true });
		} else {
			require(nocksFile);
		}
	}

	var logLevels;