Skip to content

Commit 37e4bfc

Browse files
committed
feat( Creator): 去除了对点文件开头的文件的特殊处理,由外部拦截器控制
1 parent 227287d commit 37e4bfc

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

src/Creator.ts

+6-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { tryFlatten } from 'try-flatten';
99
import { ExitError } from './ExitError';
1010
import { MiddleWare, type MiddleWareInterceptor } from './MiddleWare';
1111
import { TypedEvents } from './TypedEvents';
12-
import { BUILTIN_DATA_KEY, DOT_FILE_PREFIX, EJS_FILE_REGEX, EJS_FILE_SUFFIX, UNDERSCORE_FILE_PREFIX } from './const';
12+
import { BUILTIN_DATA_KEY, EJS_FILE_REGEX, EJS_FILE_SUFFIX } from './const';
1313
import { colors, prompts, selectTemplate, selectWriteMode } from './prompts';
1414
import type { CreatorContext, CreatorData, CreatorOptions, FileMeta, OverrideWrite } from './types';
1515
import { isDirectory } from './utils';
@@ -109,7 +109,7 @@ export class Creator<T extends Record<string, unknown>> extends TypedEvents<{
109109
const paths = await glob('**/*', {
110110
nodir: true,
111111
cwd: context.templateRoot,
112-
dot: false,
112+
dot: true,
113113
});
114114

115115
// Verify selected template contains files
@@ -149,32 +149,14 @@ export class Creator<T extends Record<string, unknown>> extends TypedEvents<{
149149
const sourceFile = path.join(context.templateRoot, sourcePath);
150150

151151
const isEjsFile = EJS_FILE_REGEX.test(sourceFileName);
152-
const isUnderscoreFile = sourceFileName.startsWith(UNDERSCORE_FILE_PREFIX);
153-
const isDotFile = !isUnderscoreFile && sourceFileName.startsWith(DOT_FILE_PREFIX);
154-
155-
let start = 0;
156-
let end = undefined;
157-
let prefix = '';
158-
159-
if (isEjsFile) {
160-
end = -EJS_FILE_SUFFIX.length;
161-
}
162-
163-
if (isUnderscoreFile) {
164-
start = UNDERSCORE_FILE_PREFIX.length;
165-
prefix = '_';
166-
} else if (isDotFile) {
167-
start = DOT_FILE_PREFIX.length;
168-
prefix = '.';
169-
}
170-
171-
const targetPath = path.join(sourceFolder, prefix + sourceFileName.slice(start, end));
152+
const targetPath = path.join(
153+
sourceFolder,
154+
sourceFileName.slice(0, isEjsFile ? -EJS_FILE_SUFFIX.length : undefined),
155+
);
172156
const targetFile = path.join(context.projectRoot, targetPath);
173157

174158
const fileMeta: FileMeta = {
175-
isDotFile,
176159
isEjsFile: isEjsFile,
177-
isUnderscoreFile,
178160
sourcePath,
179161
sourceFile,
180162
sourceRoot: context.templateRoot,

src/const.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ export const pkgName = PKG_NAME;
22
export const pkgVersion = PKG_VERSION;
33
export const pkgDescription = PKG_DESCRIPTION;
44

5-
export const UNDERSCORE_FILE_PREFIX = '__';
6-
export const DOT_FILE_PREFIX = '_';
75
export const EJS_FILE_SUFFIX = '.ejs';
86
export const EJS_FILE_REGEX = /\.ejs$/i;
97
export const BUILTIN_DATA_KEY = 'ctx';

src/types.ts

-8
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,6 @@ export type FileMeta = {
122122
* Whether file uses EJS templating
123123
*/
124124
isEjsFile: boolean;
125-
/**
126-
* Whether file uses underscore prefix
127-
*/
128-
isUnderscoreFile: boolean;
129-
/**
130-
* Whether file uses dot prefix
131-
*/
132-
isDotFile: boolean;
133125

134126
/**
135127
* Root directory of source files

0 commit comments

Comments
 (0)