Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* mkdir output dir */
mkdirp.sync(outputDir)
/* gen new files */
writeFileSync(outputFile, html, { encoding: 'utf8' })
// log
if (!silent) {
console.log('>', key, '-', title, '\n', outputFile)
}
}
})
/* copy static assets */
copy(join(__dirname, '..', '..', 'static'), join(outDir, 'static')).then(result => {
console.log(`> FlyBook was generated at ${outDir}`)
})
/* copy assets which is used in docs */
const files: string[] = glob.sync(
join(docDir, '**', '!(*.md|*.markdown|*.mdown|*.mkdn|*.mkd|*.mdwn|*.mkdown|toc.yml)'),
{
ignore: [join(docDir, 'node_modules', '**')],
nodir: true
}
)
files.map(file => normalize(file)).forEach(file => {
copySync(file, file.replace(docDir, outDir))
})
}
await mkdirp(join(outDir, '_next', buildId))
// Copy static directory
if (existsSync(join(dir, 'static'))) {
log(' copying "static" directory')
await cp(
join(dir, 'static'),
join(outDir, 'static'),
{ expand: true }
)
}
// Copy .next/static directory
if (existsSync(join(distDir, CLIENT_STATIC_FILES_PATH))) {
log(' copying "static build" directory')
await cp(
join(distDir, CLIENT_STATIC_FILES_PATH),
join(outDir, '_next', CLIENT_STATIC_FILES_PATH)
)
}
// Get the exportPathMap from the config file
if (typeof nextConfig.exportPathMap !== 'function') {
console.log(`> No "exportPathMap" found in "${CONFIG_FILE}". Generating map from "./pages"`)
nextConfig.exportPathMap = async (defaultMap) => {
return defaultMap
}
}
// Start the rendering process
const renderOpts = {
dir,
defaultPathMap['/404'] = { page }
continue
}
defaultPathMap[page] = { page }
}
// Initialize the output directory
const outDir = options.outdir
await del(join(outDir, '*'))
// await mkdirp(join(outDir, '_joy', buildId))
// Copy static directory
if (existsSync(join(dir, 'static'))) {
log(' copying "static" directory')
await cp(
join(dir, 'static'),
join(outDir, 'static'),
{ expand: true }
)
}
// Copy .joy/static directory
if (existsSync(join(distDir, CLIENT_STATIC_FILES_PATH))) {
log(' copying "static build" directory')
await cp(
join(distDir, CLIENT_STATIC_FILES_PATH),
join(outDir, '_joy', CLIENT_STATIC_FILES_PATH)
)
}
// Get the exportPathMap from the config file
},
transform: (src: string, dest: string, stats: unknown) => {
return through((chunk: any, enc: any, done: any) => {
let output: string = chunk.toString();
replacers.forEach((replacer: IReplacer) => {
output = replaceString(output, replacer.slot, replacer.slotValue);
});
done(null, output);
});
},
};
try {
await recursiveCopy(entryFolderPath, outputPath, recursiveCopyOptions);
console.info(`Files outed to: '${outputPath}'`);
return outputtedFilesAndFolders.filter(Boolean);
} catch (error) {
console.error(`Copy failed: ${error}`);
return [`Copy failed: ${error}`];
}
}
if (exists && !response.force) {
process.stderr.write(chalk.red('Error: Cannot initialize in the current directory, please specify a different destination or use --force\n'));
process.exit(1);
}
let spinner = ora({
text: 'Creating project',
color: 'magenta'
}).start();
if (!exists) {
await Promise.promisify(mkdirp)(target);
}
await copy(
path.resolve(__dirname, '../..', template),
target,
{ filter: ['**/*', '!build'] }
);
spinner.text = 'Initializing project';
await initialize(response.yarn, target);
let pkg = JSON.parse(await fs.readFile(path.resolve(target, 'package.json')));
pkg.scripts = await pkgScripts(response.yarn, pkg);
try {
await fs.stat(path.resolve(target, 'src'));
}
export const copy = (
sourcePath: string,
destPath: string,
viewData: ViewData,
): CopyOperation[] => {
const recuriveCopyOptions = {
overwrite: true,
dot: true,
rename: (filePath: string) => {
const destinationPath = toDestinationPath(filePath, viewData)
logDebug("Copy %s to %s", filePath, destinationPath)
return destinationPath
},
}
return recursiveCopy(sourcePath, destPath, recuriveCopyOptions)
.on(recursiveCopy.events.COPY_FILE_COMPLETE, onCopyComplete)
.on(recursiveCopy.events.ERROR, onCopyError)
}
rimraf(`${target}/src/widgets/WidgetName/`, async () => {
await copy(`${target}/src/`, dest + "/");
await copy(`${target}/tests/`, tests + "/");
rimraf(`${target}/**`, resolve);
});
});
await Promise.all(FILES.map(async i => {
if (i.endsWith('/')) {
let from = join(SRC, 'well-known', i.slice(0, -1))
let to = join(DIST, i.slice(0, -1))
let files = await copyDir(from, to)
for (let file of files) {
if (file.dest !== to) {
assets.add(file.dest)
}
}
} else {
let from = join(SRC, 'well-known', i)
let to = join(DIST, i)
if (i === 'security.txt') to = join(DIST, '.well-known', i)
assets.add(to)
await fs.copyFile(from, to)
}
}))
}