@@ -44,13 +44,14 @@ async function downloadFile(url, outputPath) {
4444 fileStream . on ( 'finish' , resolve ) ;
4545 } ) ;
4646}
47+ // ... [other imports and functions]
4748
4849async function setup_theme ( themeName ) {
4950 try {
5051 // Check if theme name is in kebab-case
5152 if ( ! isKebabCase ( themeName ) ) {
5253 console . log (
53- chalk . red ( '\nTheme name must be in kebab-case (example-theme-name' )
54+ chalk . red ( '\nTheme name must be in kebab-case (example-theme-name) ' )
5455 ) ;
5556 return false ;
5657 }
@@ -59,15 +60,17 @@ async function setup_theme(themeName) {
5960 const cwd = process . cwd ( ) ;
6061 if ( ! cwd . endsWith ( 'wp-content/themes' ) ) {
6162 console . log (
62- chalk . red ( '\nThis command needs to be run inside a wp-themes folder.' )
63+ chalk . red (
64+ '\nThis command needs to be run inside a wp-content/themes folder.'
65+ )
6366 ) ;
6467 return false ;
6568 }
6669
6770 // Check if theme directory already exists
6871 const newThemePath = path . join ( '.' , themeName ) ;
6972 if ( fs . existsSync ( newThemePath ) ) {
70- console . log ( chalk . red ( '\nTA theme with this name already exists.' ) ) ;
73+ console . log ( chalk . red ( '\nA theme with this name already exists.' ) ) ;
7174 return false ;
7275 }
7376
@@ -100,29 +103,27 @@ async function setup_theme(themeName) {
100103 fs . renameSync ( topLevelDir , newThemePath ) ;
101104
102105 // Clean up temporary directory
103- fs . rmdirSync ( tempExtractPath , { recursive : true } ) ;
106+ fs . rmSync ( tempExtractPath , { recursive : true , force : true } ) ;
104107
105108 // Delete the .git directory from the new theme folder
106109 const gitDirPath = path . join ( newThemePath , '.git' ) ;
107110 if ( fs . existsSync ( gitDirPath ) ) {
108111 fs . rmSync ( gitDirPath , { recursive : true , force : true } ) ;
109112 }
110113
111- // Rename the extracted folder
112- // Note: You need to adjust the logic here to determine the correct extracted folder name
113- spinner . start ( 'Renaming the folder...' ) ;
114- const extractedFolderName = 'theme-redone' ; // Placeholder, replace with actual logic
115- fs . renameSync ( extractedFolderName , newThemePath ) ;
116- spinner . succeed ( 'Renaming completed' ) ;
117-
118114 // Modify style.css in the theme folder
119115 const styleCssPath = path . join ( newThemePath , 'style.css' ) ;
120- let styleCss = fs . readFileSync ( styleCssPath , 'utf8' ) ;
121- styleCss = styleCss . replace (
122- / T h e m e N a m e : t h e m e - r e d o n e / g,
123- `Theme Name: ${ themeName } `
124- ) ;
125- fs . writeFileSync ( styleCssPath , styleCss ) ;
116+ if ( fs . existsSync ( styleCssPath ) ) {
117+ let styleCss = fs . readFileSync ( styleCssPath , 'utf8' ) ;
118+ styleCss = styleCss . replace (
119+ / T h e m e N a m e : t h e m e - r e d o n e / g,
120+ `Theme Name: ${ themeName } `
121+ ) ;
122+ fs . writeFileSync ( styleCssPath , styleCss ) ;
123+ } else {
124+ console . error ( chalk . red ( `style.css not found in ${ newThemePath } ` ) ) ;
125+ return false ;
126+ }
126127
127128 // Delete the zip file
128129 fs . unlinkSync ( 'theme-redone.zip' ) ;
@@ -135,15 +136,20 @@ async function setup_theme(themeName) {
135136
136137 // Read package.json and extract Node version
137138 const packageJsonPath = path . join ( newThemePath , 'package.json' ) ;
138- const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
139- const nodeVersion = packageJson . engines . node ;
140-
141- console . log (
142- `Please ensure you have Node version ${ nodeVersion } installed.`
143- ) ;
144- console . log (
145- 'Then, run "npm i" and "composer i" from the theme root directory.'
146- ) ;
139+ if ( fs . existsSync ( packageJsonPath ) ) {
140+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
141+ const nodeVersion = packageJson . engines . node ;
142+ console . log (
143+ `Please ensure you have Node version ${ nodeVersion } installed.`
144+ ) ;
145+ console . log (
146+ 'Then, run "npm i" and "composer i" from the theme root directory.'
147+ ) ;
148+ } else {
149+ console . log (
150+ chalk . yellow ( 'Note: package.json not found in the theme directory.' )
151+ ) ;
152+ }
147153 } catch ( error ) {
148154 console . error ( chalk . red ( `Error setting up theme: ${ error . message } ` ) ) ;
149155 return false ;
0 commit comments