From 06e1c8f28cc1a321d230f97e5229379456ee2a23 Mon Sep 17 00:00:00 2001 From: WQ Date: Tue, 12 Nov 2024 18:42:47 +0800 Subject: [PATCH 1/8] feat:import path for global styles --- src/sync.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sync.ts b/src/sync.ts index 2aefd68..caaaef7 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -48,6 +48,12 @@ export async function sync(opts: SyncOptions) { }, } as Config); + // Check for existing global styles (.css or .less) and set the import path + const globalStylesPath = path.join(cwd, 'src/global'); + const styleExtensions = ['.css', '.less']; + const ext = styleExtensions.find(ext => fs.existsSync(`${globalStylesPath}${ext}`)); + const globalStyleImportPath = ext ? `import '../global${ext}';` : ''; + // tailwindcss let tailwindcssPath: string | undefined; if (config?.tailwindcss && !opts.runAgain) { @@ -71,6 +77,7 @@ import { } from '@umijs/tnf/router'; import { routeTree } from './routeTree.gen'; ${tailwindcssPath ? `import '${tailwindcssPath}'` : ''} +${globalStyleImportPath} const router = createRouter({ routeTree, defaultPreload: ${config?.router?.defaultPreload ? `'${config.router.defaultPreload}'` : 'false'}, From 71b129b64cdf87f46feaf1785f4efda6ce67c46a Mon Sep 17 00:00:00 2001 From: WQ Date: Wed, 13 Nov 2024 08:59:52 +0800 Subject: [PATCH 2/8] fix:sync format --- src/sync.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sync.ts b/src/sync.ts index caaaef7..3ae9bc6 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -51,7 +51,9 @@ export async function sync(opts: SyncOptions) { // Check for existing global styles (.css or .less) and set the import path const globalStylesPath = path.join(cwd, 'src/global'); const styleExtensions = ['.css', '.less']; - const ext = styleExtensions.find(ext => fs.existsSync(`${globalStylesPath}${ext}`)); + const ext = styleExtensions.find((ext) => + fs.existsSync(`${globalStylesPath}${ext}`), + ); const globalStyleImportPath = ext ? `import '../global${ext}';` : ''; // tailwindcss From f0dbb867ea08898cba02c4566e82b8299d237cc7 Mon Sep 17 00:00:00 2001 From: WQ Date: Wed, 13 Nov 2024 09:55:56 +0800 Subject: [PATCH 3/8] feat:add overrides file to write --- .changeset/stupid-tomatoes-work.md | 5 +++++ src/sync.ts | 29 +++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 .changeset/stupid-tomatoes-work.md diff --git a/.changeset/stupid-tomatoes-work.md b/.changeset/stupid-tomatoes-work.md new file mode 100644 index 0000000..99ecbd9 --- /dev/null +++ b/.changeset/stupid-tomatoes-work.md @@ -0,0 +1,5 @@ +--- +'@umijs/tnf': patch +--- + +Added the ability to write global and overrides style files diff --git a/src/sync.ts b/src/sync.ts index 3ae9bc6..cab6f3b 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -48,13 +48,18 @@ export async function sync(opts: SyncOptions) { }, } as Config); - // Check for existing global styles (.css or .less) and set the import path - const globalStylesPath = path.join(cwd, 'src/global'); - const styleExtensions = ['.css', '.less']; - const ext = styleExtensions.find((ext) => - fs.existsSync(`${globalStylesPath}${ext}`), - ); - const globalStyleImportPath = ext ? `import '../global${ext}';` : ''; + // Check for existing style files (.css or .less) and set import paths + const supportedExtensions = ['.css', '.less']; + function getStyleImportPath(basePath) { + const ext = supportedExtensions.find((ext) => + fs.existsSync(path.join(basePath + ext)), + ); + return ext ? `import '${basePath}${ext}';` : ''; + } + const globalStylePath = path.join(cwd, 'src/global'); + const overridesStylePath = path.join(cwd, 'src/overrides'); + const globalStyleImportPath = getStyleImportPath(globalStylePath); + const overridesStyleImportPath = getStyleImportPath(overridesStylePath); // tailwindcss let tailwindcssPath: string | undefined; @@ -78,8 +83,9 @@ import { createRouter, } from '@umijs/tnf/router'; import { routeTree } from './routeTree.gen'; -${tailwindcssPath ? `import '${tailwindcssPath}'` : ''} ${globalStyleImportPath} +${tailwindcssPath ? `import '${tailwindcssPath}'` : ''} +${overridesStyleImportPath} const router = createRouter({ routeTree, defaultPreload: ${config?.router?.defaultPreload ? `'${config.router.defaultPreload}'` : 'false'}, @@ -113,3 +119,10 @@ ReactDOM.createRoot(document.getElementById('root')!).render( console.log('Prepared'); } + +function getStyleImportPath(basePath: string) { + const ext = supportedExtensions.find((ext) => + fs.existsSync(`${basePath}${ext}`), + ); + return ext ? `import '${basePath}${ext}';` : ''; +} From f489c12e7398114bca03edfc72ca4ecb48ac90cb Mon Sep 17 00:00:00 2001 From: WQ Date: Wed, 13 Nov 2024 09:58:58 +0800 Subject: [PATCH 4/8] feat:add overrides file to write --- src/sync.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/sync.ts b/src/sync.ts index cab6f3b..1021668 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -118,11 +118,4 @@ ReactDOM.createRoot(document.getElementById('root')!).render( ); console.log('Prepared'); -} - -function getStyleImportPath(basePath: string) { - const ext = supportedExtensions.find((ext) => - fs.existsSync(`${basePath}${ext}`), - ); - return ext ? `import '${basePath}${ext}';` : ''; -} +} \ No newline at end of file From 0e5f90da2ed7a523fe8bab8dd6c4f5107ba603ff Mon Sep 17 00:00:00 2001 From: WQ Date: Wed, 13 Nov 2024 09:55:56 +0800 Subject: [PATCH 5/8] feat:add overrides file to write feat:add overrides file to write --- .changeset/stupid-tomatoes-work.md | 5 +++++ src/sync.ts | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 .changeset/stupid-tomatoes-work.md diff --git a/.changeset/stupid-tomatoes-work.md b/.changeset/stupid-tomatoes-work.md new file mode 100644 index 0000000..99ecbd9 --- /dev/null +++ b/.changeset/stupid-tomatoes-work.md @@ -0,0 +1,5 @@ +--- +'@umijs/tnf': patch +--- + +Added the ability to write global and overrides style files diff --git a/src/sync.ts b/src/sync.ts index 3ae9bc6..1021668 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -48,13 +48,18 @@ export async function sync(opts: SyncOptions) { }, } as Config); - // Check for existing global styles (.css or .less) and set the import path - const globalStylesPath = path.join(cwd, 'src/global'); - const styleExtensions = ['.css', '.less']; - const ext = styleExtensions.find((ext) => - fs.existsSync(`${globalStylesPath}${ext}`), - ); - const globalStyleImportPath = ext ? `import '../global${ext}';` : ''; + // Check for existing style files (.css or .less) and set import paths + const supportedExtensions = ['.css', '.less']; + function getStyleImportPath(basePath) { + const ext = supportedExtensions.find((ext) => + fs.existsSync(path.join(basePath + ext)), + ); + return ext ? `import '${basePath}${ext}';` : ''; + } + const globalStylePath = path.join(cwd, 'src/global'); + const overridesStylePath = path.join(cwd, 'src/overrides'); + const globalStyleImportPath = getStyleImportPath(globalStylePath); + const overridesStyleImportPath = getStyleImportPath(overridesStylePath); // tailwindcss let tailwindcssPath: string | undefined; @@ -78,8 +83,9 @@ import { createRouter, } from '@umijs/tnf/router'; import { routeTree } from './routeTree.gen'; -${tailwindcssPath ? `import '${tailwindcssPath}'` : ''} ${globalStyleImportPath} +${tailwindcssPath ? `import '${tailwindcssPath}'` : ''} +${overridesStyleImportPath} const router = createRouter({ routeTree, defaultPreload: ${config?.router?.defaultPreload ? `'${config.router.defaultPreload}'` : 'false'}, @@ -112,4 +118,4 @@ ReactDOM.createRoot(document.getElementById('root')!).render( ); console.log('Prepared'); -} +} \ No newline at end of file From 959f53c6bff896481d95a24a64e509cdd0174700 Mon Sep 17 00:00:00 2001 From: WQ Date: Wed, 13 Nov 2024 10:06:14 +0800 Subject: [PATCH 6/8] fix:remove overrides import temporarily, pending further discussion --- src/sync.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sync.ts b/src/sync.ts index 1021668..59c30ac 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -57,9 +57,7 @@ export async function sync(opts: SyncOptions) { return ext ? `import '${basePath}${ext}';` : ''; } const globalStylePath = path.join(cwd, 'src/global'); - const overridesStylePath = path.join(cwd, 'src/overrides'); const globalStyleImportPath = getStyleImportPath(globalStylePath); - const overridesStyleImportPath = getStyleImportPath(overridesStylePath); // tailwindcss let tailwindcssPath: string | undefined; @@ -85,7 +83,6 @@ import { import { routeTree } from './routeTree.gen'; ${globalStyleImportPath} ${tailwindcssPath ? `import '${tailwindcssPath}'` : ''} -${overridesStyleImportPath} const router = createRouter({ routeTree, defaultPreload: ${config?.router?.defaultPreload ? `'${config.router.defaultPreload}'` : 'false'}, From 38e5949f78f45fb2a60ce1815dd1eb7a265a4008 Mon Sep 17 00:00:00 2001 From: WQ Date: Wed, 13 Nov 2024 10:09:29 +0800 Subject: [PATCH 7/8] fix:sync format --- src/sync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sync.ts b/src/sync.ts index 59c30ac..0d5716d 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -115,4 +115,4 @@ ReactDOM.createRoot(document.getElementById('root')!).render( ); console.log('Prepared'); -} \ No newline at end of file +} From 292a8964749723e939d3b8f48293eac1c9423388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?chencheng=20=28=E4=BA=91=E8=B0=A6=29?= Date: Wed, 13 Nov 2024 10:09:56 +0800 Subject: [PATCH 8/8] Update .changeset/stupid-tomatoes-work.md --- .changeset/stupid-tomatoes-work.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/stupid-tomatoes-work.md b/.changeset/stupid-tomatoes-work.md index 99ecbd9..ea596d8 100644 --- a/.changeset/stupid-tomatoes-work.md +++ b/.changeset/stupid-tomatoes-work.md @@ -2,4 +2,4 @@ '@umijs/tnf': patch --- -Added the ability to write global and overrides style files +Support conventional src/global.{less,css} as global style