Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject)=>{
const {source, options={}, transform, identifier} = params;
const shouldFallback = typeof params.directory !== 'string' && directory !== os.tmpdir();
mkdirp(directory, (err)=>{
if (err) shouldFallback ? handleCache(os.tmpdir(), params) : reject(err);
const file = path.join(directory, filename(source, identifier, options));
read(file).then((succ)=>{
// cached file
resolve(succ);
}, (fail)=>{
// transform source
try {
params.transform(source, options).then((ret)=>{
write(file, ret).then((succ)=>{
resolve(ret);
}, (fail)=>{
if (!shouldFallback) {
reject(fail);
it('should use proper plural form', () => {
rmDirSync('debug');
mkdirp('debug');
const resultPath = 'debug/ngettext_result.js';
const input = 'const n = parseInt(process.env.TEST_N, 10);\n' +
'process.stdout.write(ngettext(msgid`plural form with ${ n } plural`, ' +
'`plural form with ${ n } plurals`, n));';
const result = babel.transform(input, options).code;
fs.writeFileSync(resultPath, result, { mode: 0o777 });
const { stdout: stdout1 } = childProcess.spawnSync('node', [resultPath],
{ env: Object.assign(process.env, { TEST_N: 1 }) });
expect(stdout1.toString()).to.eql('plural form with 1 plural [translated]');
const { stdout: stdout2 } = childProcess.spawnSync('node', [resultPath],
{ env: Object.assign(process.env, { TEST_N: 2 }) });
expect(stdout2.toString()).to.eql('plural form with 2 plurals [translated]');
});
packagesToSymlink.forEach(function (pkg) {
const srcDir = join(workingDir, pkg)
const srcName = require(join(srcDir, 'package.json')).name
const destinationDir = join(nodeDir, pkg)
if (isLink(destinationDir)) {
return log('symlinks for', symlinkToName, 'already exist...')
}
mkdirp(nodeDir, function (err) {
if (err) throw err
if (isScoped(srcName)) {
const [scope, name] = srcName.split('/')
mkdirp(join(nodeDir, scope), function (err) {
if (err) throw err
const dest = join(nodeDir, scope, name)
if (exists(dest)) {
return log(' ', srcName, 'already exists')
}
symlinkSync(srcDir, dest)
})
writeIfNeeded(() => {
mkdirp(dirname, (err) => {
if (err) {
debugMedia(`Error creating dir ${dirname}: ${err}`)
return saveDoneOnce(err)
}
request(url)
.on('error', (err) => {
debugMedia(`Error fetching media ${url}: ${err}`)
saveDoneOnce(err)
})
.pipe(fs.createWriteStream(filepath))
.on('close', saveDoneOnce)
})
})
}
function sources() {
mkdirp('sources/imgs')
mkdirp('sources/styles/components')
mkdirp('sources/sprites')
if (this.appFramework !== 'none') {
mkdirp(`sources/${this.appFramework}`)
}
}
function syncPluginTo(dest, done) {
mkdirp(dest, function (err) {
if (err) return done(err);
const source = path.resolve(__dirname) + '/';
const rsync = new Rsync();
rsync.source(source)
.destination(dest)
.flags('uav')
.recursive(true)
.set('delete')
.include(include)
.exclude(exclude)
.output(function (data) {
process.stdout.write(data.toString('utf8'));
});
return new Promise((resolve, reject) => {
mkdirp(
dirpath,
{
fs: this.fs
},
err => {
if (err) {
reject(err);
} else {
resolve();
}
}
);
});
}
mkdirp(arcdir, err => {
if(err) return callback(err)
mkdirp(tmpdir, err => {
if(err) return callback(err)
callback(null, new ShareStore(rootdir, arcdir, tmpdir, docstore))
})
})
})
fs.exists(dir, exists => {
if (exists) {
fs.copyFile(indexPath, path, cpError =>
cpError ? reject(cpError) : resolve(),
);
} else {
mkdirp(dir, mkError =>
mkError
? reject(mkError)
: fs.copyFile(indexPath, path, cpError =>
cpError ? reject(cpError) : resolve(),
),
);
}
});
}),
function syncPluginTo(dest, done) {
mkdirp(dest, function (err) {
if (err) return done(err);
const source = path.resolve(__dirname) + '/';
const rsync = new Rsync();
rsync.source(source)
.destination(dest)
.flags('uav')
.recursive(true)
.set('delete')
.include(include)
.exclude(exclude)
.output(function (data) {
process.stdout.write(data.toString('utf8'));
});