Skip to content

Commit 472dff3

Browse files
committed
Fix: Fix error when create theme with no configuration file
1 parent a65ee3e commit 472dff3

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

packages/evershop/src/bin/theme/active.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,40 @@ async function selectTheme() {
3636
}
3737

3838
async function updateConfig(theme: string) {
39-
const configPath = path.join(process.cwd(), 'config', 'default.json');
39+
const configDir = path.join(process.cwd(), 'config');
40+
const configPath = path.join(configDir, 'default.json');
4041
try {
41-
const configData = await fs.readFile(configPath, 'utf8');
42-
const config = JSON.parse(configData);
42+
// Ensure config directory exists
43+
try {
44+
await fs.access(configDir);
45+
} catch {
46+
await fs.mkdir(configDir, { recursive: true });
47+
}
48+
49+
// Read existing config or create new one
50+
let config: any = {};
51+
try {
52+
const configData = await fs.readFile(configPath, 'utf8');
53+
config = JSON.parse(configData);
54+
} catch (err: any) {
55+
// If file doesn't exist, start with empty config
56+
if (err.code !== 'ENOENT') {
57+
throw err;
58+
}
59+
}
60+
61+
// Update theme
4362
config.system = config.system || {};
4463
config.system.theme = theme;
4564
await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
46-
65+
4766
console.log(
4867
boxen(kleur.green(`Theme updated to "${theme}" in config/default.json`), {
4968
padding: 1,
5069
borderColor: 'green'
5170
})
5271
);
5372
} catch (err) {
54-
5573
console.error(kleur.red('Error updating config:'), err);
5674
process.exit(1);
5775
}

0 commit comments

Comments
 (0)