@@ -4,6 +4,8 @@ import * as path from 'node:path'
44import { assetTargets } from '../assets-data.mjs'
55import { templateChoices } from '../template-data.mjs'
66import { assetsDir , packageDir , skeletonDir , templatesDir } from './paths'
7+ import { toPublishGitignorePath } from './utils/gitignore'
8+ import { shouldSkipTemplatePath } from './utils/template-filter'
79
810export interface PrepareAssetsOptions {
911 overwriteExisting ?: boolean
@@ -27,77 +29,6 @@ const skeletonFiles = [
2729 'LICENSE' ,
2830]
2931
30- const publishBasename = 'gitignore'
31- const workspaceBasename = '.gitignore'
32- const templateSkipDirs = new Set ( [
33- 'node_modules' ,
34- 'dist' ,
35- '.turbo' ,
36- '.cache' ,
37- '.vite' ,
38- '.tmp' ,
39- '.vue-global-types' ,
40- '.wrangler' ,
41- ] )
42-
43- function detectSeparator ( input : string ) {
44- if ( input . includes ( '\\' ) && ! input . includes ( '/' ) ) {
45- return '\\'
46- }
47- return '/'
48- }
49-
50- function replaceBasename ( input : string , from : string , to : string ) {
51- if ( ! input ) {
52- return input
53- }
54- const separator = detectSeparator ( input )
55- const normalized = input . replace ( / [ \\ / ] / g, separator )
56- const hasTrailingSeparator = normalized . endsWith ( separator )
57- const segments = normalized . split ( separator )
58- if ( hasTrailingSeparator && segments [ segments . length - 1 ] === '' ) {
59- segments . pop ( )
60- }
61- const lastIndex = segments . length - 1
62- if ( lastIndex >= 0 && segments [ lastIndex ] === from ) {
63- segments [ lastIndex ] = to
64- const rebuilt = segments . join ( separator )
65- return hasTrailingSeparator ? `${ rebuilt } ${ separator } ` : rebuilt
66- }
67- return input
68- }
69-
70- function toPublishGitignorePath ( input : string ) {
71- return replaceBasename ( input , workspaceBasename , publishBasename )
72- }
73-
74- function shouldSkipTemplatePath ( rootDir : string , targetPath : string ) {
75- const relative = path . relative ( rootDir , targetPath )
76- if ( ! relative || relative . startsWith ( '..' ) ) {
77- return false
78- }
79- const segments = relative . split ( path . sep )
80- if ( segments . some ( segment => templateSkipDirs . has ( segment ) ) ) {
81- return true
82- }
83- for ( let i = 0 ; i < segments . length - 1 ; i += 1 ) {
84- if ( segments [ i ] === '.vitepress' && segments [ i + 1 ] === 'cache' ) {
85- return true
86- }
87- }
88- const basename = path . basename ( targetPath )
89- if ( basename . endsWith ( '.tsbuildinfo' ) ) {
90- return true
91- }
92- if ( basename === 'typed-router.d.ts' && segments . includes ( 'types' ) ) {
93- return true
94- }
95- if ( basename === 'worker-configuration.d.ts' ) {
96- return true
97- }
98- return false
99- }
100-
10132async function pathExists ( targetPath : string ) {
10233 try {
10334 await fs . access ( targetPath )
@@ -125,8 +56,9 @@ async function renameGitignoreFiles(targetDir: string) {
12556 await renameGitignoreFiles ( current )
12657 return
12758 }
128- if ( entry . name === workspaceBasename ) {
129- await fs . rename ( current , path . join ( targetDir , publishBasename ) )
59+ const renamed = toPublishGitignorePath ( entry . name )
60+ if ( renamed !== entry . name ) {
61+ await fs . rename ( current , path . join ( targetDir , renamed ) )
13062 }
13163 } ) )
13264}
0 commit comments