@@ -29,65 +29,80 @@ import type { Equals } from "tsafe";
2929 return undefined ;
3030 } ) ( ) ;
3131
32- const publicDirPath =
33- viteConfigFilePath !== undefined
34- ? await ( async function getVitePublicDirPath ( ) {
35- const viteConfig = fs . readFileSync ( viteConfigFilePath ) . toString ( "utf8" ) ;
36-
37- if ( ! viteConfig . includes ( "publicDir" ) ) {
38- return pathJoin ( projectDirPath , "public" ) ;
39- }
40-
41- const [ , afterPublicDir ] = viteConfig . split ( / \s [ " ' ] ? p u b l i c D i r [ " ' ] ? \s * : / ) ;
42-
43- for ( let indexEnd = 0 ; indexEnd < afterPublicDir . length ; indexEnd ++ ) {
44- const {
45- default : path ,
46- basename,
47- dirname,
48- delimiter,
49- extname,
50- format,
51- isAbsolute,
52- join,
53- normalize,
54- parse,
55- posix,
56- relative,
57- resolve,
58- sep,
59- toNamespacedPath,
60- win32,
61- ...rest
62- } = await import ( "path" ) ;
63- assert < Equals < keyof typeof rest , never >> ( ) ;
64-
65- const part = afterPublicDir
66- . substring ( 0 , indexEnd )
67- . replace ( / _ _ d i r n a m e / g, `"${ projectDirPath } "` ) ;
68-
69- let candidate : string ;
70-
71- try {
72- candidate = eval ( part ) ;
73- } catch {
74- continue ;
75- }
76-
77- if ( typeof candidate !== "string" ) {
78- continue ;
79- }
80-
81- return candidate ;
82- }
83-
84- console . error (
85- `Can't parse the vite configuration please open an issue about it ${ getRepoIssueUrl ( ) } `
86- ) ;
87-
88- process . exit ( - 1 ) ;
89- } ) ( )
90- : pathJoin ( projectDirPath , "public" ) ;
32+ const publicDirPath = await ( async ( ) => {
33+ command_line_argument: {
34+ const arg = process . argv [ 2 ] ;
35+
36+ if ( arg === undefined ) {
37+ break command_line_argument;
38+ }
39+
40+ return arg ;
41+ }
42+
43+ read_from_vite_config: {
44+ if ( viteConfigFilePath === undefined ) {
45+ break read_from_vite_config;
46+ }
47+
48+ const viteConfig = fs . readFileSync ( viteConfigFilePath ) . toString ( "utf8" ) ;
49+
50+ if ( ! viteConfig . includes ( "publicDir" ) ) {
51+ return pathJoin ( projectDirPath , "public" ) ;
52+ }
53+
54+ const [ , afterPublicDir ] = viteConfig . split ( / \s [ " ' ] ? p u b l i c D i r [ " ' ] ? \s * : / ) ;
55+
56+ for ( let indexEnd = 0 ; indexEnd < afterPublicDir . length ; indexEnd ++ ) {
57+ const {
58+ default : path ,
59+ basename,
60+ dirname,
61+ delimiter,
62+ extname,
63+ format,
64+ isAbsolute,
65+ join,
66+ normalize,
67+ parse,
68+ posix,
69+ relative,
70+ resolve,
71+ sep,
72+ toNamespacedPath,
73+ win32,
74+ ...rest
75+ } = await import ( "path" ) ;
76+ assert < Equals < keyof typeof rest , never >> ( ) ;
77+
78+ const part = afterPublicDir
79+ . substring ( 0 , indexEnd )
80+ . replace ( / _ _ d i r n a m e / g, `"${ projectDirPath } "` ) ;
81+
82+ let candidate : string ;
83+
84+ try {
85+ candidate = eval ( part ) ;
86+ } catch {
87+ continue ;
88+ }
89+
90+ if ( typeof candidate !== "string" ) {
91+ continue ;
92+ }
93+
94+ return candidate ;
95+ }
96+
97+ console . error (
98+ `Can't parse the vite configuration please open an issue about it ${ getRepoIssueUrl ( ) } `
99+ ) ;
100+
101+ process . exit ( - 1 ) ;
102+ }
103+
104+ return pathJoin ( projectDirPath , "public" ) ;
105+ } ) ( ) ;
91106
92107 edit_gitignore: {
93108 const gitignoreFilePath = pathJoin ( projectDirPath , ".gitignore" ) ;
0 commit comments