Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
env: process.env,
}).promise;
} catch (e1) {
console.log(`SKIPPING ${oldFile}`);
continue;
}
if (isPeg) { continue; }
// Now run phpcbf, but it's allowed to return non-zero
try {
yield childProcess.execFile(
path.join(BASEDIR, 'vendor', 'bin', 'phpcbf'), [
newFile,
]).promise;
} catch (e2) { /* of course there were code style issues */ }
stdio: 'inherit',
}).on('close', function(code) {
if (code === 0) {
resolve(code);
} else {
reject(code);
}
}).on('error', reject);
});
};
var pPARSERTESTS = path.join(__dirname, '..', 'tests', 'parser', targetName);
var mwPARSERTESTS = path.join(mwpath, file.path);
// Fetch current Parsoid git hash.
var result = yield childProcess.execFile(
'git', ['log', '--max-count=1', '--pretty=format:%H'], {
cwd: __dirname,
env: process.env,
}).promise;
var phash = strip(result.stdout);
// A bit of user-friendly logging.
console.log('Parsoid git HEAD is', phash);
console.log('>>> cd', mwpath);
// Create a new mediawiki/core branch, based on the previous sync point.
yield mwexec('git fetch origin'.split(' '));
yield mwexec(['git', 'checkout', '-b', branch, oldhash]);
// Copy our locally-modified parser tests over to mediawiki/core.
// cp __dirname/tests/parser/parserTests.txt $mwpath/tests/parser
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 {
// Now run phpcbf, but it's allowed to return non-zero
try {
yield childProcess.execFile(
path.join(BASEDIR, 'vendor', 'bin', 'phpcbf'), [
newFile,
]).promise;
} catch (e2) { /* of course there were code style issues */ }
// Comment length warnings are bogus...
yield rewriteFile(
newFile, /^<\?php\n/,
'$&// phpcs:disable Generic.Files.LineLength.TooLong\n'
);
// So, were we successful? If not, disable phpcs for this file.
var codeStyleErrors = false;
try {
yield childProcess.execFile(
path.join(BASEDIR, 'vendor', 'bin', 'phpcs'), [
newFile,
]).promise;
} catch (e3) {
codeStyleErrors = true;
yield rewriteFile(
newFile, /^<\?php\n/,
'$&// phpcs:ignoreFile\n'
);
}
// Same idea, but for lint errors
var lintErrors = false;
try {
yield childProcess.execFile(
path.join(BASEDIR, 'vendor', 'bin', 'parallel-lint'), [
newFile,
return Promise.resolve().then(() => { // catch thrown errors
const cp = childProcess.execFile(phantomjsCmd, getPhantomJSArgs(options), { maxBuffer: Infinity });
writeBufferInChunks(cp.stdin, sourceBuffer);
return cp.promise.then(processResult);
});
};
var checkout = Promise.async(function *(commit) {
console.log('Checking out: ' + commit);
yield childProcess.execFile('git', ['checkout', commit], {
cwd: path.join(__dirname, '..'),
}).promise;
console.log('Restarting PHP');
yield childProcess.exec(
'sudo systemctl restart php7.2-fpm.service'
).promise;
});
var titles;
it('should calculate shades 1 through 6 when appropriate', async () => {
const fillableArgs = [
'-c', path.resolve('lib', 'test-helpers', 'colors-fillable.js'),
'-t', path.resolve('lib', 'test-helpers', templateName),
'-o', testOutputDir,
];
await child_process.execFile(pathToExecutable, fillableArgs).promise;
const wrapped = await wrap(() => fs.access(testOutputFile));
expect(wrapped).not.toThrow();
});
const wrapped = await wrap(() => child_process.execFile(pathToExecutable).promise);
expect(wrapped).toThrow();
const wrapped = await wrap(() => child_process.execFile(pathToExecutable, args).promise);
expect(wrapped).toThrow();
const wrapped = await wrap(() => child_process.execFile(pathToExecutable).promise);
expect(wrapped).toThrow();