core-maugli 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "core-maugli",
3
3
  "description": "Astro & Tailwind CSS blog theme for Maugli.",
4
4
  "type": "module",
5
- "version": "1.1.7",
5
+ "version": "1.1.8",
6
6
  "license": "GPL-3.0-or-later OR Commercial",
7
7
  "repository": {
8
8
  "type": "git",
@@ -10,81 +10,89 @@ const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
11
11
 
12
12
  const defaultConfigPath = path.join(__dirname, '../src/config/maugli.config.ts');
13
- const userConfigPath = path.join(process.cwd(), 'src/config/maugli.config.ts');
13
+ const userRoot = process.env.INIT_CWD || process.cwd();
14
+ const userConfigPath = path.join(userRoot, 'src/config/maugli.config.ts');
14
15
 
15
16
  async function loadTsModule(filePath) {
16
- const code = await fs.readFile(filePath, 'utf8');
17
- const js = ts.transpileModule(code, {
18
- compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2020 }
19
- }).outputText;
20
- const tmp = path.join(os.tmpdir(), `maugli-${Date.now()}.mjs`);
21
- await fs.writeFile(tmp, js, 'utf8');
22
- const mod = await import(pathToFileURL(tmp).href);
23
- await fs.unlink(tmp);
24
- return mod;
17
+ const code = await fs.readFile(filePath, 'utf8');
18
+ const js = ts.transpileModule(code, {
19
+ compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2020 }
20
+ }).outputText;
21
+ const tmp = path.join(os.tmpdir(), `maugli-${Date.now()}.mjs`);
22
+ await fs.writeFile(tmp, js, 'utf8');
23
+ const mod = await import(pathToFileURL(tmp).href);
24
+ await fs.unlink(tmp);
25
+ return mod;
25
26
  }
26
27
 
27
28
  function mergeMissing(target, source) {
28
- for (const key of Object.keys(source)) {
29
- if (key === 'configVersion') continue;
30
- const sv = source[key];
31
- const tv = target[key];
32
- if (sv && typeof sv === 'object' && !Array.isArray(sv)) {
33
- if (!tv || typeof tv !== 'object' || Array.isArray(tv)) {
34
- if (!(key in target)) target[key] = sv;
35
- } else {
36
- mergeMissing(tv, sv);
37
- }
38
- } else {
39
- if (!(key in target)) target[key] = sv;
29
+ for (const key of Object.keys(source)) {
30
+ if (key === 'configVersion') continue;
31
+ const sv = source[key];
32
+ const tv = target[key];
33
+ if (sv && typeof sv === 'object' && !Array.isArray(sv)) {
34
+ if (!tv || typeof tv !== 'object' || Array.isArray(tv)) {
35
+ if (!(key in target)) target[key] = sv;
36
+ } else {
37
+ mergeMissing(tv, sv);
38
+ }
39
+ } else {
40
+ if (!(key in target)) target[key] = sv;
41
+ }
40
42
  }
41
- }
42
43
  }
43
44
 
44
45
  async function main() {
45
- const pkg = await loadTsModule(defaultConfigPath);
46
- const defCfg = pkg.maugliConfig;
47
- const newVersion = pkg.MAUGLI_CONFIG_VERSION || defCfg.configVersion;
46
+ const pkg = await loadTsModule(defaultConfigPath);
47
+ const defCfg = pkg.maugliConfig;
48
+ const newVersion = pkg.MAUGLI_CONFIG_VERSION || defCfg.configVersion;
48
49
 
49
- let user;
50
- try {
51
- user = await loadTsModule(userConfigPath);
52
- } catch (err) {
53
- console.error(`Cannot find user config at ${userConfigPath}`);
54
- process.exit(1);
55
- }
56
- const userCfg = user.maugliConfig;
57
- if (userCfg.configVersion === newVersion) {
58
- console.log('maugli.config.ts is already up to date');
59
- return;
60
- }
50
+ try {
51
+ await fs.access(userConfigPath);
52
+ } catch {
53
+ console.warn(`User config not found at ${userConfigPath}, skipping upgrade`);
54
+ return;
55
+ }
56
+
57
+ let user;
58
+ try {
59
+ user = await loadTsModule(userConfigPath);
60
+ } catch (err) {
61
+ console.warn(`Cannot load user config at ${userConfigPath}:`, err.message);
62
+ return;
63
+ }
64
+ const userCfg = user.maugliConfig;
65
+ if (userCfg.configVersion === newVersion) {
66
+ console.log('maugli.config.ts is already up to date');
67
+ return;
68
+ }
61
69
 
62
- mergeMissing(userCfg, defCfg);
63
- userCfg.configVersion = newVersion;
70
+ mergeMissing(userCfg, defCfg);
71
+ userCfg.configVersion = newVersion;
64
72
 
65
- const defText = await fs.readFile(defaultConfigPath, 'utf8');
66
- const headerEnd = defText.indexOf('export const maugliConfig');
67
- let header = defText.slice(0, headerEnd);
68
- header = header.replace(/MAUGLI_CONFIG_VERSION\s*=\s*['\"][^'\"]*['\"]/, `MAUGLI_CONFIG_VERSION = '${newVersion}'`);
69
- let bracePos = defText.indexOf('{', headerEnd);
70
- let count = 0, i = bracePos;
71
- for (; i < defText.length; i++) {
72
- if (defText[i] === '{') count++;
73
- else if (defText[i] === '}') count--;
74
- if (count === 0) break;
75
- }
76
- let j = i;
77
- while (j < defText.length && defText[j] !== ';') j++;
78
- const tail = defText.slice(j + 1);
73
+ const defText = await fs.readFile(defaultConfigPath, 'utf8');
74
+ const headerEnd = defText.indexOf('export const maugliConfig');
75
+ let header = defText.slice(0, headerEnd);
76
+ header = header.replace(/MAUGLI_CONFIG_VERSION\s*=\s*['\"][^'\"]*['\"]/, `MAUGLI_CONFIG_VERSION = '${newVersion}'`);
77
+ let bracePos = defText.indexOf('{', headerEnd);
78
+ let count = 0,
79
+ i = bracePos;
80
+ for (; i < defText.length; i++) {
81
+ if (defText[i] === '{') count++;
82
+ else if (defText[i] === '}') count--;
83
+ if (count === 0) break;
84
+ }
85
+ let j = i;
86
+ while (j < defText.length && defText[j] !== ';') j++;
87
+ const tail = defText.slice(j + 1);
79
88
 
80
- const newObject = JSON.stringify(userCfg, null, 2);
81
- const result = `${header}export const maugliConfig: MaugliConfig = ${newObject};${tail}`;
82
- await fs.writeFile(userConfigPath, result, 'utf8');
83
- console.log(`Upgraded maugli.config.ts to version ${newVersion}`);
89
+ const newObject = JSON.stringify(userCfg, null, 2);
90
+ const result = `${header}export const maugliConfig: MaugliConfig = ${newObject};${tail}`;
91
+ await fs.writeFile(userConfigPath, result, 'utf8');
92
+ console.log(`Upgraded maugli.config.ts to version ${newVersion}`);
84
93
  }
85
94
 
86
- main().catch(err => {
87
- console.error('Upgrade failed:', err);
88
- process.exit(1);
95
+ main().catch((err) => {
96
+ console.error('Upgrade failed:', err);
97
+ process.exit(1);
89
98
  });
90
-