core-maugli 1.1.6 → 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 +1 -1
- package/scripts/upgrade-config.js +70 -62
- package/src/config/maugli.config.ts +1 -1
package/package.json
CHANGED
@@ -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
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
46
|
+
const pkg = await loadTsModule(defaultConfigPath);
|
47
|
+
const defCfg = pkg.maugliConfig;
|
48
|
+
const newVersion = pkg.MAUGLI_CONFIG_VERSION || defCfg.configVersion;
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
63
|
-
|
70
|
+
mergeMissing(userCfg, defCfg);
|
71
|
+
userCfg.configVersion = newVersion;
|
64
72
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
88
|
-
|
95
|
+
main().catch((err) => {
|
96
|
+
console.error('Upgrade failed:', err);
|
97
|
+
process.exit(1);
|
89
98
|
});
|
90
|
-
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// MAUGLI_CONFIG_VERSION — config version for CLI/automation compatibility
|
2
|
-
export const MAUGLI_CONFIG_VERSION = '0.
|
2
|
+
export const MAUGLI_CONFIG_VERSION = '0.2';
|
3
3
|
// Main configuration interface for the Maugli project
|
4
4
|
export interface MaugliConfig {
|
5
5
|
// Show example/demo content (for CLI/empty blog setup)
|