@azure-net/cli 1.3.1 → 1.3.2
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/src/commands/initAliases.js +38 -12
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
4
5
|
|
|
5
6
|
/** Файл конфигурации */
|
|
6
7
|
const svelteConfigPath = path.resolve('svelte.config.js');
|
|
@@ -41,32 +42,57 @@ function serializeObjectLiteral(obj) {
|
|
|
41
42
|
.join(',\n');
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
function insertAliasBlock(content, aliasBlock) {
|
|
46
|
+
const kitRegex = /kit:\s*{([\s\S]*?)}/m;
|
|
47
|
+
const match = content.match(kitRegex);
|
|
48
|
+
|
|
49
|
+
if (!match) {
|
|
50
|
+
throw new Error('❌ Cannot find `kit: {}` block in svelte.config.js');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const existingKit = match[0];
|
|
54
|
+
const newKit = existingKit.includes('alias:')
|
|
55
|
+
? existingKit.replace(/alias:\s*{([\s\S]*?)}/m, aliasBlock)
|
|
56
|
+
: existingKit.replace(/{/, `{\n\t\t${aliasBlock},`);
|
|
57
|
+
|
|
58
|
+
return content.replace(kitRegex, newKit);
|
|
59
|
+
}
|
|
60
|
+
|
|
44
61
|
async function updateAliases() {
|
|
45
62
|
const config = await loadUserConfig();
|
|
46
63
|
const newAliases = generateAliases(config);
|
|
47
64
|
|
|
48
65
|
let content = await fs.readFile(svelteConfigPath, 'utf-8');
|
|
49
66
|
|
|
67
|
+
// если alias уже есть
|
|
50
68
|
const aliasRegex = /alias:\s*{([\s\S]*?)}/m;
|
|
51
|
-
const
|
|
69
|
+
const aliasMatch = content.match(aliasRegex);
|
|
52
70
|
|
|
53
|
-
|
|
54
|
-
console.error('❌ No `alias` field found in svelte.config.js');
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
71
|
+
let updatedAliases = {};
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
if (aliasMatch) {
|
|
74
|
+
const existingAliases = parseObjectLiteral(aliasMatch[1]);
|
|
75
|
+
updatedAliases = { ...existingAliases, ...newAliases };
|
|
76
|
+
} else {
|
|
77
|
+
updatedAliases = { ...newAliases };
|
|
78
|
+
}
|
|
63
79
|
|
|
64
|
-
// замена в контенте
|
|
65
80
|
const newAliasBlock = `alias: {\n${serializeObjectLiteral(updatedAliases)}\n\t\t}`;
|
|
66
|
-
|
|
81
|
+
|
|
82
|
+
content = aliasMatch
|
|
83
|
+
? content.replace(aliasRegex, newAliasBlock)
|
|
84
|
+
: insertAliasBlock(content, newAliasBlock);
|
|
67
85
|
|
|
68
86
|
await fs.writeFile(svelteConfigPath, content, 'utf-8');
|
|
69
87
|
console.log('✅ Aliases updated in svelte.config.js');
|
|
88
|
+
|
|
89
|
+
// Run formatter
|
|
90
|
+
try {
|
|
91
|
+
execSync('npm run format', { stdio: 'inherit' });
|
|
92
|
+
console.log('✅ Ran npm run format');
|
|
93
|
+
} catch {
|
|
94
|
+
console.warn('⚠️ Failed to run format. Make sure you have a format script in package.json');
|
|
95
|
+
}
|
|
70
96
|
}
|
|
71
97
|
|
|
72
98
|
export default updateAliases;
|