Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
chore(workflows): add override files to replace certain files in temp…
Browse files Browse the repository at this point in the history
…late (#26)
  • Loading branch information
fuxingloh authored Oct 9, 2023
1 parent c1475b4 commit 4bbd141
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/create-levain-app/src/TemplateProgram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile, writeFile } from 'node:fs/promises';
import { readFile, rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

import execa from 'execa';
Expand All @@ -15,7 +15,7 @@ export class TemplateProgram {
await pacote.extract(packageSpec, installDir);

await overridePackageJson(installDir, projectConfig);
// await removeFiles(installDir);
await overrideFiles(installDir);

console.log(` Installing dependencies...`);
await execa('npm', ['install'], { cwd: installDir });
Expand All @@ -27,6 +27,9 @@ export class TemplateProgram {
}
}

/**
* Override the package.json file in the template.
*/
async function overridePackageJson(installDir: string, projectConfig: ProjectConfig): Promise<void> {
const packageJsonPath = join(installDir, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
Expand All @@ -36,11 +39,13 @@ async function overridePackageJson(installDir: string, projectConfig: ProjectCon
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
}

// async function removeFiles(installDir: string): Promise<void> {
// for (const file of [
// '.npmignore',
// 'LICENSE',
// ]) {
// await rm(join(installDir, file));
// }
// }
/**
* Override certain files in the template.
*/
async function overrideFiles(installDir: string): Promise<void> {
// Move the .npmignore file to .gitignore due to npm's behavior of replacing .gitignore with .npmignore.
await execa('mv', ['.npmignore', '.gitignore'], { cwd: installDir });

// Remove the LICENSE file from the template such that it doesn't assume the user is using the MIT license.
await rm(join(installDir, 'LICENSE'));
}

1 comment on commit 4bbd141

@vercel
Copy link

@vercel vercel bot commented on 4bbd141 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.