Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test.serial("method `upgrade` runs only new migrations", async (t) => {
let count = 0;
let migrator = new Migrator({ cacheFilePath });
await fs.writeFile(cacheFilePath, 1); // migration index=1 has already been executed
migrator.add({
index: 1,
upgrade: () => count++,
});
migrator.add({
index: 3,
upgrade: () => count++,
});
let index = await migrator.upgrade();
t.is(count, 1);
t.is(index, 3);
});
let tmp = str.split('_');
for (let i = 0; i < tmp.length; i++) {
if (i > 0 || type == 'ucfirst') {
name += tmp[i].charAt(0).toUpperCase() + tmp[i].slice(1);
} else {
name += tmp[i];
}
}
return name;
});
// write file Router.ts in OUTPUT_DIR/router/
let routerContent = TplEngine.render('router/router', {
infos: gatewayInfoList,
});
await LibFs.writeFile(LibPath.join(OUTPUT_DIR, 'router', 'Router.ts'), routerContent);
// write file RouterAPITest.ts in OUTPUT_DIR/router/
let testContent = TplEngine.render('router/test', {
infos: gatewayInfoList,
});
await LibFs.writeFile(LibPath.join(OUTPUT_DIR, 'router', 'RouterAPITest.ts'), testContent);
// write file ${gatewayApiName}.ts in OUTPUT_DIR/router/${gatewayApiService}/
for (let gatewayInfo of gatewayInfoList) {
const relativePath = this._protoMsgImportInfos[`${gatewayInfo.packageName}${gatewayInfo.serviceName}`].protoFile.relativePath;
await mkdir(LibPath.join(OUTPUT_DIR, 'router', relativePath, gatewayInfo.serviceName));
let apiContent = TplEngine.render('router/api', {
info: gatewayInfo,
});
// normalize path so relative path ignores leading path.sep
if (!targetDir.endsWith(path.sep)) {
targetDir += path.sep
}
const gdrPath = path.join(targetDir, grdName)
// remove previously generated file
try {
await fs.unlink(gdrPath)
} catch (e) {}
// build file list from target dir
const filePaths = await getFileListDeep(targetDir)
const relativeFilePaths = filePaths.map(filePath => filePath.replace(targetDir, ''))
// get gdr string
const gdrFileContents = getGrdString(name, idPrefix, relativeFilePaths)
// write to file
await fs.writeFile(gdrPath, gdrFileContents, { encoding: 'utf8' })
}
]).then(function (results) {
var packageFileContent = processTemplate(results[1]);
var bowerFileContent = processTemplate(results[2]);
return Promise.all([
fs.writeFile(packageDestinationPath, packageFileContent),
fs.writeFile(bowerDestinationPath, bowerFileContent)
]);
})
.catch(function (error) {
return fs.readFile(file, 'utf8').then(data => {
const flattenedLinks = data
.replace(/\.\.\//g, '')
.replace(/(modules|interfaces|classes)\//g, '');
let caseFixedLinks = flattenedLinks;
for (const lower in lowerToUpperLookup) {
const re = new RegExp(lower, 'g');
caseFixedLinks = caseFixedLinks.replace(re, lowerToUpperLookup[lower]);
}
return fs.writeFile(file, caseFixedLinks);
});
}
function writeOutput(ts: string, argOut: string): Promise {
if (!argOut) {
try {
process.stdout.write(ts)
return Promise.resolve()
} catch (err) {
return Promise.reject(err)
}
}
return writeFile(argOut, ts)
}
.then(results => {
const [current, wechatSnippets, configSnippets] = results;
if (crypto.createHash('md5').update(current).digest('hex') === crypto.createHash('md5').update(wechatSnippets).digest('hex')) {
return;
}
return Promise.all([
fs.writeFile(wechatSnippetFile, wechatSnippets),
fs.writeFile(configSnippetFile, configSnippets)
]);
})
.catch(err => {
export function writeStrTo(fpath, fcontent) {
return writeFile(fpath, fcontent, 'utf8');
}
async exportScene(scene, projectName, exportInterfaceName) {
await fs.writeFile(
path.join(
this.baseDir,
projectName,
exportInterfaceName,
'scene',
`${scene.sceneName}.json`
),
JSON.stringify(scene, null, 2)
);
}