in packages/create-web-scripts-library/src/index.ts [27:62]
export default async function createWebScriptsLibrary(projectName?: string) {
if (!projectName) {
throw new Error(messages.missingProjectName());
}
if (fs.existsSync(projectName) && projectName !== '.') {
throw new Error(messages.alreadyExists(projectName));
}
const { packageJson: cwslPkg } =
readPkgUp.sync({
cwd: __dirname,
}) || {};
const projectPath = path.resolve(process.cwd(), projectName);
const templatePath = path.resolve(__dirname, '..', 'template');
console.log(chalk.gray('Copying template...'));
await fs.copy(templatePath, projectPath);
console.log(chalk.gray('Writing over necessary files...'));
process.chdir(projectPath);
const newPkgPath = path.join(projectPath, 'package.json');
const newPkg = require(newPkgPath);
newPkg.name = projectName;
newPkg.devDependencies['@spotify/web-scripts'] =
(cwslPkg?.devDependencies || {})['@spotify/web-scripts'] ||
newPkg.devDependencies['@spotify/web-scripts'];
await fs.writeFile(newPkgPath, JSON.stringify(newPkg, null, 2));
console.log(chalk.gray('Installing dependencies...'));
process.chdir(projectPath);
await execa(getInstallCmd(), ['install']);
console.log(messages.start(projectName));
}