buddy-workbench 0.1.62 → 0.1.64
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
|
@@ -13,11 +13,14 @@ router.get('/dev-configurations', async (_req, res) => {
|
|
|
13
13
|
try { res.json({ ...(await readDevConfigurations()), nvm: await readNvmConfiguration() }); } catch (error) { res.status(500).json({ error: error.message }); }
|
|
14
14
|
});
|
|
15
15
|
router.put('/dev-configurations', async (req, res) => {
|
|
16
|
-
const {
|
|
17
|
-
if (!npm
|
|
18
|
-
return res.status(400).json({ error: '
|
|
16
|
+
const { section } = req.body || {};
|
|
17
|
+
if (!['npm', 'git', 'nvm'].includes(section)) {
|
|
18
|
+
return res.status(400).json({ error: 'A valid configuration section is required.' });
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
if (!req.body?.[section] || typeof req.body[section] !== 'object') {
|
|
21
|
+
return res.status(400).json({ error: `${section.toUpperCase()} configuration is required.` });
|
|
22
|
+
}
|
|
23
|
+
try { res.json({ ...(await saveDevConfigurations({ [section]: req.body[section] }, { section })), nvm: await readNvmConfiguration() }); } catch (error) { res.status(500).json({ error: error.message }); }
|
|
21
24
|
});
|
|
22
25
|
router.post('/dev-configurations/nvm/install', async (req, res) => {
|
|
23
26
|
try { res.json(await installNvmVersion(req.body?.version)); } catch (error) { res.status(400).json({ error: error.message }); }
|
|
@@ -120,7 +120,7 @@ export async function readNvmConfiguration() {
|
|
|
120
120
|
|
|
121
121
|
async function readNpmConfig(key) {
|
|
122
122
|
try {
|
|
123
|
-
const value = await run('npm', ['config', 'get', key]);
|
|
123
|
+
const value = await run('npm', ['config', 'get', key, '--location=user']);
|
|
124
124
|
return value === 'undefined' || value === 'null' ? '' : value;
|
|
125
125
|
} catch {
|
|
126
126
|
return '';
|
|
@@ -218,47 +218,54 @@ export async function readDevConfigurations() {
|
|
|
218
218
|
|
|
219
219
|
async function setNpmConfig(key, value) {
|
|
220
220
|
if (value === '') {
|
|
221
|
-
await run('npm', ['config', 'delete', key]);
|
|
221
|
+
await run('npm', ['config', 'delete', key, '--location=user']);
|
|
222
222
|
} else {
|
|
223
|
-
await run('npm', ['config', 'set', key
|
|
223
|
+
await run('npm', ['config', 'set', `${key}=${value}`, '--location=user']);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
export async function saveDevConfigurations(configurations = {}) {
|
|
227
|
+
export async function saveDevConfigurations(configurations = {}, options = {}) {
|
|
228
|
+
const section = options.section || '';
|
|
228
229
|
const npm = configurations.npm || {};
|
|
229
230
|
const git = configurations.git || {};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
for (const [key, value] of Object.entries(gitValues)) {
|
|
241
|
-
if (value) await run('git', ['config', '--global', `user.${key}`, value]);
|
|
242
|
-
else {
|
|
243
|
-
try { await run('git', ['config', '--global', '--unset', `user.${key}`]); } catch {}
|
|
244
|
-
}
|
|
231
|
+
if (!section || section === 'npm') {
|
|
232
|
+
const npmValues = {
|
|
233
|
+
prefix: String(npm.prefix || '').trim(),
|
|
234
|
+
registry: String(npm.registry || '').trim() || 'https://registry.npmjs.org/',
|
|
235
|
+
'strict-ssl': npm.strictSsl === false ? 'false' : 'true',
|
|
236
|
+
cache: String(npm.cache || '').trim(),
|
|
237
|
+
proxy: String(npm.proxy || '').trim(),
|
|
238
|
+
'https-proxy': String(npm.httpsProxy || '').trim()
|
|
239
|
+
};
|
|
240
|
+
for (const key of NPM_KEYS) await setNpmConfig(key, npmValues[key]);
|
|
245
241
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
242
|
+
if (!section || section === 'git') {
|
|
243
|
+
const gitValues = { name: String(git.name || '').trim(), email: String(git.email || '').trim() };
|
|
244
|
+
for (const [key, value] of Object.entries(gitValues)) {
|
|
245
|
+
if (value) await run('git', ['config', '--global', `user.${key}`, value]);
|
|
246
|
+
else {
|
|
247
|
+
try { await run('git', ['config', '--global', '--unset', `user.${key}`]); } catch {}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const sshKey = String(git.sshKey || '').trim();
|
|
251
|
+
if (sshKey) {
|
|
252
|
+
const resolvedKey = sshKey.startsWith('~/') ? `${homedir()}/${sshKey.slice(2)}` : sshKey;
|
|
253
|
+
const quotedKey = `"${resolvedKey.replaceAll('"', '\\"')}"`;
|
|
254
|
+
await run('git', ['config', '--global', 'core.sshCommand', `ssh -i ${quotedKey} -o IdentitiesOnly=yes`]);
|
|
255
|
+
} else {
|
|
256
|
+
try { await run('git', ['config', '--global', '--unset', 'core.sshCommand']); } catch {}
|
|
257
|
+
}
|
|
253
258
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
if (!section || section === 'nvm') {
|
|
260
|
+
const nvm = configurations.nvm || {};
|
|
261
|
+
const mirror = String(nvm.nodeJsMirror || '').trim().replace(/\/$/, '');
|
|
262
|
+
if (mirror && !/^https?:\/\/[^\s]+$/i.test(mirror)) throw new Error('Invalid NVM Node.js download mirror URL.');
|
|
263
|
+
updateNvmMirror(mirror);
|
|
264
|
+
if (String(nvm.defaultVersion || '').trim()) {
|
|
265
|
+
const version = String(nvm.defaultVersion).trim();
|
|
266
|
+
if (!/^(?:v?\d+(?:\.\d+){0,2}|node|lts\/[\w.-]+)$/.test(version)) throw new Error('Invalid NVM default version.');
|
|
267
|
+
await runNvm(`nvm alias default ${shellQuote(version)}`);
|
|
268
|
+
}
|
|
262
269
|
}
|
|
263
270
|
return readDevConfigurations();
|
|
264
271
|
}
|