Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
datamodel,
datamodelPath,
schemaDir,
transpile,
runtimePath,
browser,
outputDir,
generator,
version,
dmmf,
datasources,
binaryPaths,
})
debug(`makeDir: ${outputDir}`)
await makeDir(outputDir)
await Promise.all(
Object.entries(fileMap).map(async ([fileName, file]) => {
const filePath = path.join(outputDir, fileName)
// The deletion of the file is necessary, so VSCode
// picks up the changes.
if (await exists(filePath)) {
await remove(filePath)
}
await writeFile(filePath, file)
}),
)
const inputDir = testMode
? eval(`require('path').join(__dirname, '../../runtime')`) // tslint:disable-line
: eval(`require('path').join(__dirname, '../runtime')`) // tslint:disable-line
// if users use a custom output dir
async _createNewTmpDir () {
this.path = tmp.tmpNameSync({ dir: TempDirectory.TEMP_DIRECTORIES_ROOT, prefix: this.namePrefix + '-' });
await makeDir(this.path);
this.lockFile = new LockFile(this.path);
this.lockFile.init();
}
async _ensureOutStream (outStream) {
if (typeof outStream !== 'string')
return outStream;
const fullReporterOutputPath = resolvePathRelativelyCwd(outStream);
await makeDir(path.dirname(fullReporterOutputPath));
return fs.createWriteStream(fullReporterOutputPath);
}
if (example) {
const found = await hasExample(example)
if (!found) {
console.error(
`Could not locate an example named ${chalk.red(
`"${example}"`
)}. Please check your spelling and try again.`
)
process.exit(1)
}
}
const root = path.resolve(appPath)
const appName = path.basename(root)
await makeDir(root)
if (!isFolderEmpty(root, appName)) {
process.exit(1)
}
const useYarn = useNpm ? false : shouldUseYarn()
const isOnline = !useYarn || (await getOnline())
const originalDirectory = process.cwd()
const displayedCommand = useYarn ? 'yarn' : 'npm'
console.log(`Creating a new Next.js app in ${chalk.green(root)}.`)
console.log()
await makeDir(root)
process.chdir(root)
if (example) {
async function copyWellKnown (assets) {
await makeDir(join(DIST, '.well-known'))
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)
private async mkDirPackageSlug(): Promise {
return makeDir(this.packageSlugPath);
}
const logger = getLogger(args);
const path = args.path ? resolve(args.cwd, args.path) : args.cwd;
logger.info("Initialize in", path);
const exist = await exists(path);
if (exist && !args.force) {
throw new CLIError("Already exists", {
output: `Already exists. Use "--force" to overwrite existing files.`
});
}
for (const name of ["components", "environments", "templates"]) {
const dir = join(path, name);
debug("Creating directory", dir);
await makeDir(dir);
}
await updatePkg(join(path, "package.json"), {
dependencies: {
"@kosko/env": "^0.4.1",
"kubernetes-models": "^0.5.0"
}
});
const configPath = join(path, "kosko.toml");
debug("Writing config", configPath);
await writeFile(configPath, DEFAULT_CONFIG);
logger.success(
`We are almost there. Run "npm install" to finish the setup.`
);
const writeFile = async (pathName: string, data: string | object) => {
await makeDir(path.join(pathName.replace(path.basename(pathName), '')));
await fs.writeFile(pathName, typeof data === 'string' ? data : JSON.stringify(data, null, 2));
};
async save(RequestResponse) {
const Request = RequestResponse.request;
Request._hash = this.hash.request(Request);
const Response = RequestResponse.response;
Response._hash = this.hash.response(Response);
await makeDir(this.getFilePathByRequest(Request));
const fileName = `${Request.method}.${Request._hash}.${Response._hash}.json`;
const filePath = `${this.getFilePathByRequest(Request)}${path.sep}${fileName}`;
const data = JSON.stringify(RequestResponse, null, 2);
return new Promise((resolve, reject) => {
fs.writeFile(filePath, data, (err) => {
if (err) {
reject(err);
} else {
const mock = new MockFile(path.relative(this.directory, filePath));
this.addMock(mock);
resolve(true);
}
});
});
export async function maybeCreateGlobalConfigAndFolder() {
const reposPath = getReposPath();
const globalConfigPath = getGlobalConfigPath();
const configTemplate = await getConfigTemplate();
await makeDir(reposPath);
const didCreate = await maybeCreateGlobalConfig(
globalConfigPath,
configTemplate
);
await ensureCorrectPermissions(globalConfigPath);
return didCreate;
}