Skip to content

Commit

Permalink
feat: allow to skip some files
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Aug 30, 2024
1 parent 11a80a0 commit 2a5302e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ export async function create({
name,
root,
templates,
skipFiles,
getTemplateName,
mapESLintTemplate,
}: {
name: string;
root: string;
skipFiles?: string[];
templates: string[];
getTemplateName: (argv: Argv) => Promise<string>;
mapESLintTemplate: (templateName: string) => ESLintTemplateName | null;
Expand Down Expand Up @@ -214,12 +216,14 @@ export async function create({
from: commonFolder,
to: distFolder,
version,
skipFiles,
});
copyFolder({
from: srcFolder,
to: distFolder,
version,
packageName,
skipFiles,
});

const packageRoot = path.resolve(__dirname, '..');
Expand All @@ -238,13 +242,15 @@ export async function create({
from: subFolder,
to: distFolder,
version,
skipFiles,
isMergePackageJson: true,
});
} else {
copyFolder({
from: toolFolder,
to: distFolder,
version,
skipFiles,
isMergePackageJson: true,
});
}
Expand Down Expand Up @@ -301,24 +307,26 @@ function copyFolder({
version,
packageName,
isMergePackageJson,
skipFiles = [],
}: {
from: string;
to: string;
version: string;
packageName?: string;
isMergePackageJson?: boolean;
skipFiles?: string[];
}) {
const renameFiles: Record<string, string> = {
gitignore: '.gitignore',
};

// Skip local files
const skipFiles = ['node_modules', 'dist'];
const allSkipFiles = ['node_modules', 'dist', ...skipFiles];

fs.mkdirSync(to, { recursive: true });

for (const file of fs.readdirSync(from)) {
if (skipFiles.includes(file)) {
if (allSkipFiles.includes(file)) {
continue;
}

Expand All @@ -333,6 +341,7 @@ function copyFolder({
from: srcFile,
to: distFile,
version,
skipFiles,
});
} else if (file === 'package.json') {
const targetPackage = path.resolve(to, 'package.json');
Expand Down

0 comments on commit 2a5302e

Please sign in to comment.