@node-cli/npmrc 1.2.1 → 1.2.3
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/dist/defaults.js +2 -2
- package/dist/defaults.js.map +1 -1
- package/dist/npmrc.js +2 -2
- package/dist/npmrc.js.map +1 -1
- package/dist/parse.js +3 -3
- package/dist/parse.js.map +1 -1
- package/dist/utilities/common.js +6 -9
- package/dist/utilities/common.js.map +1 -1
- package/dist/utilities/createProfile.js +6 -7
- package/dist/utilities/createProfile.js.map +1 -1
- package/dist/utilities/deleteProfile.js +3 -3
- package/dist/utilities/deleteProfile.js.map +1 -1
- package/dist/utilities/listProfiles.js +3 -3
- package/dist/utilities/listProfiles.js.map +1 -1
- package/dist/utilities/switchProfile.js +6 -5
- package/dist/utilities/switchProfile.js.map +1 -1
- package/dist/utilities/updateProfile.js +7 -7
- package/dist/utilities/updateProfile.js.map +1 -1
- package/package.json +18 -10
package/dist/defaults.js
CHANGED
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/*
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* v8 ignore start */\nexport const defaultFlags = {\n\tboring: false,\n\tverbose: false,\n};\n/* v8 ignore stop */\n"],"names":["defaultFlags","boring","verbose"],"mappings":"AAAA,mBAAmB,GACnB,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,SAAS;AACV,EAAE,CACF,kBAAkB"}
|
package/dist/npmrc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/*
|
|
2
|
+
/* v8 ignore start */ import path from "node:path";
|
|
3
3
|
import { config } from "./parse.js";
|
|
4
4
|
import { createProfile } from "./utilities/createProfile.js";
|
|
5
5
|
import { deleteProfile } from "./utilities/deleteProfile.js";
|
|
@@ -55,6 +55,6 @@ if (flags.list || !flags.version && !flags.help) {
|
|
|
55
55
|
});
|
|
56
56
|
process.exit(exitFlag);
|
|
57
57
|
}
|
|
58
|
-
showHelp();
|
|
58
|
+
showHelp(); /* v8 ignore stop */
|
|
59
59
|
|
|
60
60
|
//# sourceMappingURL=npmrc.js.map
|
package/dist/npmrc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/npmrc.ts"],"sourcesContent":["#!/usr/bin/env node\n/*
|
|
1
|
+
{"version":3,"sources":["../src/npmrc.ts"],"sourcesContent":["#!/usr/bin/env node\n/* v8 ignore start */\n\nimport path from \"node:path\";\nimport { config } from \"./parse.js\";\nimport { createProfile } from \"./utilities/createProfile.js\";\nimport { deleteProfile } from \"./utilities/deleteProfile.js\";\nimport { listProfiles } from \"./utilities/listProfiles.js\";\nimport { switchProfile } from \"./utilities/switchProfile.js\";\nimport { updateProfile } from \"./utilities/updateProfile.js\";\n\nconst HOME = process.env.HOME;\nconst NPMRC_STORE = path.join(HOME, \".envtools/npmrcs\");\nconst NPMRC_STORE_CONFIG = path.join(HOME, \"/.envtools/npmrcs.json\");\n\nconst { parameters, flags, showHelp } = config;\n\nif (flags.create && parameters !== undefined) {\n\tconst exitFlag = await createProfile({\n\t\tflags,\n\t\tstoreConfig: NPMRC_STORE_CONFIG,\n\t\tstoreLocation: NPMRC_STORE,\n\t\tprofileName: parameters[\"0\"],\n\t\thomeLocation: HOME,\n\t});\n\tprocess.exit(exitFlag);\n}\n\nif (flags.update && parameters !== undefined) {\n\tconst exitFlag = await updateProfile({\n\t\tflags,\n\t\tstoreConfig: NPMRC_STORE_CONFIG,\n\t\tstoreLocation: NPMRC_STORE,\n\t\thomeLocation: HOME,\n\t});\n\tprocess.exit(exitFlag);\n}\n\nif (flags.delete && parameters !== undefined) {\n\tconst exitFlag = await deleteProfile({\n\t\tflags,\n\t\tstoreConfig: NPMRC_STORE_CONFIG,\n\t\tstoreLocation: NPMRC_STORE,\n\t\tprofileName: parameters[\"0\"],\n\t});\n\tprocess.exit(exitFlag);\n}\n\nif (parameters !== undefined && parameters[\"0\"] !== undefined) {\n\tconst exitFlag = await switchProfile({\n\t\tflags,\n\t\tstoreConfig: NPMRC_STORE_CONFIG,\n\t\tstoreLocation: NPMRC_STORE,\n\t\tprofileName: parameters[\"0\"],\n\t\thomeLocation: HOME,\n\t});\n\tprocess.exit(exitFlag);\n}\n\nif (flags.list || (!flags.version && !flags.help)) {\n\tconst exitFlag = await listProfiles({\n\t\tflags,\n\t\tstoreConfig: NPMRC_STORE_CONFIG,\n\t});\n\tprocess.exit(exitFlag);\n}\n\nshowHelp();\n/* v8 ignore stop */\n"],"names":["path","config","createProfile","deleteProfile","listProfiles","switchProfile","updateProfile","HOME","process","env","NPMRC_STORE","join","NPMRC_STORE_CONFIG","parameters","flags","showHelp","create","undefined","exitFlag","storeConfig","storeLocation","profileName","homeLocation","exit","update","delete","list","version","help"],"mappings":";AACA,mBAAmB,GAEnB,OAAOA,UAAU,YAAY;AAC7B,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,YAAY,QAAQ,8BAA8B;AAC3D,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,aAAa,QAAQ,+BAA+B;AAE7D,MAAMC,OAAOC,QAAQC,GAAG,CAACF,IAAI;AAC7B,MAAMG,cAAcV,KAAKW,IAAI,CAACJ,MAAM;AACpC,MAAMK,qBAAqBZ,KAAKW,IAAI,CAACJ,MAAM;AAE3C,MAAM,EAAEM,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGd;AAExC,IAAIa,MAAME,MAAM,IAAIH,eAAeI,WAAW;IAC7C,MAAMC,WAAW,MAAMhB,cAAc;QACpCY;QACAK,aAAaP;QACbQ,eAAeV;QACfW,aAAaR,UAAU,CAAC,IAAI;QAC5BS,cAAcf;IACf;IACAC,QAAQe,IAAI,CAACL;AACd;AAEA,IAAIJ,MAAMU,MAAM,IAAIX,eAAeI,WAAW;IAC7C,MAAMC,WAAW,MAAMZ,cAAc;QACpCQ;QACAK,aAAaP;QACbQ,eAAeV;QACfY,cAAcf;IACf;IACAC,QAAQe,IAAI,CAACL;AACd;AAEA,IAAIJ,MAAMW,MAAM,IAAIZ,eAAeI,WAAW;IAC7C,MAAMC,WAAW,MAAMf,cAAc;QACpCW;QACAK,aAAaP;QACbQ,eAAeV;QACfW,aAAaR,UAAU,CAAC,IAAI;IAC7B;IACAL,QAAQe,IAAI,CAACL;AACd;AAEA,IAAIL,eAAeI,aAAaJ,UAAU,CAAC,IAAI,KAAKI,WAAW;IAC9D,MAAMC,WAAW,MAAMb,cAAc;QACpCS;QACAK,aAAaP;QACbQ,eAAeV;QACfW,aAAaR,UAAU,CAAC,IAAI;QAC5BS,cAAcf;IACf;IACAC,QAAQe,IAAI,CAACL;AACd;AAEA,IAAIJ,MAAMY,IAAI,IAAK,CAACZ,MAAMa,OAAO,IAAI,CAACb,MAAMc,IAAI,EAAG;IAClD,MAAMV,WAAW,MAAMd,aAAa;QACnCU;QACAK,aAAaP;IACd;IACAJ,QAAQe,IAAI,CAACL;AACd;AAEAH,YACA,kBAAkB"}
|
package/dist/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { parser } from "@node-cli/parser";
|
|
1
|
+
/* v8 ignore start */ import { parser } from "@node-cli/parser";
|
|
2
2
|
import { defaultFlags } from "./defaults.js";
|
|
3
|
-
/*
|
|
3
|
+
/* v8 ignore next 80 */ export const config = parser({
|
|
4
4
|
meta: import.meta,
|
|
5
5
|
examples: [
|
|
6
6
|
{
|
|
@@ -78,6 +78,6 @@ import { defaultFlags } from "./defaults.js";
|
|
|
78
78
|
}
|
|
79
79
|
],
|
|
80
80
|
usage: "npmrc [options] [profile]"
|
|
81
|
-
});
|
|
81
|
+
}); /* v8 ignore stop */
|
|
82
82
|
|
|
83
83
|
//# sourceMappingURL=parse.js.map
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* v8 ignore start */\nimport { parser } from \"@node-cli/parser\";\nimport { defaultFlags } from \"./defaults.js\";\n\nexport type Parameters = {\n\t[\"0\"]?: string;\n};\nexport type Flags = {\n\tverbose?: boolean;\n\tdelete?: boolean;\n\tcreate?: boolean;\n\tlist?: boolean;\n\tupdate?: boolean;\n\tboring?: boolean;\n\thelp?: boolean;\n\tversion?: boolean;\n};\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n\tshowHelp?: () => void;\n};\n\n/* v8 ignore next 80 */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [\n\t\t{\n\t\t\tcommand: \"npmrc -l\",\n\t\t\tcomment: \"## List existing profiles\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"npmrc -c [name]\",\n\t\t\tcomment: \"## Create a profile\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"npmrc [name]\",\n\t\t\tcomment: \"## Switch to an existing profile\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"npmrc -d [name]\",\n\t\t\tcomment: \"## Delete an existing profile\",\n\t\t},\n\t],\n\tflags: {\n\t\tverbose: {\n\t\t\tshortFlag: \"V\",\n\t\t\tdescription: \"Output debugging information\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tdelete: {\n\t\t\tshortFlag: \"d\",\n\t\t\tdescription: \"Delete a profile\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tcreate: {\n\t\t\tshortFlag: \"c\",\n\t\t\tdescription: \"Create a new profile\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tlist: {\n\t\t\tshortFlag: \"l\",\n\t\t\tdescription: \"List all profiles\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tupdate: {\n\t\t\tshortFlag: \"u\",\n\t\t\tdescription: \"Update the current profile\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tprofile: {\n\t\t\tdescription: \"profile name\",\n\t\t},\n\t},\n\trestrictions: [\n\t\t{\n\t\t\texit: 1,\n\t\t\tmessage: \"To create a profile, you must provide a profile name\",\n\t\t\ttest: (flags?: Flags, parameters?: Parameters) => {\n\t\t\t\treturn flags.create && (!parameters || !parameters[\"0\"]);\n\t\t\t},\n\t\t},\n\t],\n\tusage: \"npmrc [options] [profile]\",\n});\n/* v8 ignore stop */\n"],"names":["parser","defaultFlags","config","meta","examples","command","comment","flags","verbose","shortFlag","description","type","delete","create","list","update","boring","default","help","version","parameters","profile","restrictions","exit","message","test","usage"],"mappings":"AAAA,mBAAmB,GACnB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,YAAY,QAAQ,gBAAgB;AAqB7C,qBAAqB,GACrB,OAAO,MAAMC,SAAwBF,OAAO;IAC3CG,MAAM;IACNC,UAAU;QACT;YACCC,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;KACA;IACDC,OAAO;QACNC,SAAS;YACRC,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAC,QAAQ;YACPH,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAE,QAAQ;YACPJ,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAG,MAAM;YACLL,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAI,QAAQ;YACPN,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAK,QAAQ;YACPP,WAAW;YACXQ,SAAShB,aAAae,MAAM;YAC5BN,aAAa;YACbC,MAAM;QACP;QACAO,MAAM;YACLT,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAQ,SAAS;YACRV,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;IACD;IACAS,YAAY;QACXC,SAAS;YACRX,aAAa;QACd;IACD;IACAY,cAAc;QACb;YACCC,MAAM;YACNC,SAAS;YACTC,MAAM,CAAClB,OAAea;gBACrB,OAAOb,MAAMM,MAAM,IAAK,CAAA,CAACO,cAAc,CAACA,UAAU,CAAC,IAAI,AAAD;YACvD;QACD;KACA;IACDM,OAAO;AACR,GAAG,CACH,kBAAkB"}
|
package/dist/utilities/common.js
CHANGED
|
@@ -2,16 +2,13 @@ import kleur from "kleur";
|
|
|
2
2
|
export const GET_REGISTRY_CMD = 'npm config list -l -g -json | grep registry\\"';
|
|
3
3
|
export const formatRegistries = (registries)=>{
|
|
4
4
|
/**
|
|
5
|
-
* We receive this kind of output:
|
|
6
|
-
* [
|
|
5
|
+
* We receive this kind of output: [
|
|
7
6
|
* ' "@node-cli:registry": "https://other-registry.npmjs.org/"',
|
|
8
7
|
* ' "registry": "https://registry.npmjs.org/"',
|
|
9
|
-
* ]
|
|
10
|
-
* And we need convert that to a JSON object that looks like that:
|
|
11
|
-
* [
|
|
8
|
+
* ] And we need convert that to a JSON object that looks like that: [
|
|
12
9
|
* { "@node-cli:registry": "https://other-registry.npmjs.org/" },
|
|
13
10
|
* { "registry": "https://registry.npmjs.org/" },
|
|
14
|
-
* ]
|
|
11
|
+
* ].
|
|
15
12
|
*/ const messages = [];
|
|
16
13
|
const stdoutLines = registries.split("\n");
|
|
17
14
|
const jsonObjects = stdoutLines.map((line)=>{
|
|
@@ -21,13 +18,13 @@ export const formatRegistries = (registries)=>{
|
|
|
21
18
|
try {
|
|
22
19
|
const jsonObject = JSON.parse(`{${jsonLine}}`);
|
|
23
20
|
return jsonObject;
|
|
24
|
-
} catch {
|
|
25
|
-
// nothing to declare officer
|
|
21
|
+
/* v8 ignore start */ } catch {
|
|
22
|
+
// nothing to declare officer.
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
// eslint-disable-next-line unicorn/no-null
|
|
29
26
|
return null;
|
|
30
|
-
}).filter(Boolean); // remove undefined values
|
|
27
|
+
/* v8 ignore stop */ }).filter(Boolean); // remove undefined values
|
|
31
28
|
for (const jsonObject of jsonObjects){
|
|
32
29
|
messages.push(` • ${Object.keys(jsonObject)}:`, ` ${kleur.underline().grey(`${Object.values(jsonObject)}`)}`);
|
|
33
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/common.ts"],"sourcesContent":["import kleur from \"kleur\";\n\nexport const GET_REGISTRY_CMD =\n\t'npm config list -l -g -json | grep registry\\\\\"';\n\nexport const formatRegistries = (registries: string) => {\n\t/**\n\t * We receive this kind of output
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/common.ts"],"sourcesContent":["import kleur from \"kleur\";\n\nexport const GET_REGISTRY_CMD =\n\t'npm config list -l -g -json | grep registry\\\\\"';\n\nexport const formatRegistries = (registries: string) => {\n\t/**\n\t * We receive this kind of output: [\n\t * ' \"@node-cli:registry\": \"https://other-registry.npmjs.org/\"',\n\t * ' \"registry\": \"https://registry.npmjs.org/\"',\n\t * ] And we need convert that to a JSON object that looks like that: [\n\t * { \"@node-cli:registry\": \"https://other-registry.npmjs.org/\" },\n\t * { \"registry\": \"https://registry.npmjs.org/\" },\n\t * ].\n\t */\n\tconst messages = [];\n\tconst stdoutLines = registries.split(\"\\n\");\n\tconst jsonObjects = stdoutLines\n\t\t.map((line) => {\n\t\t\tconst trimmedLine = line.trim();\n\t\t\tif (trimmedLine.startsWith('\"') && trimmedLine.endsWith(\",\")) {\n\t\t\t\tconst jsonLine = trimmedLine.slice(0, -1); // remove trailing comma\n\t\t\t\ttry {\n\t\t\t\t\tconst jsonObject = JSON.parse(`{${jsonLine}}`);\n\t\t\t\t\treturn jsonObject;\n\t\t\t\t\t/* v8 ignore start */\n\t\t\t\t} catch {\n\t\t\t\t\t// nothing to declare officer.\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\treturn null;\n\t\t\t/* v8 ignore stop */\n\t\t})\n\t\t.filter(Boolean); // remove undefined values\n\n\tfor (const jsonObject of jsonObjects) {\n\t\tmessages.push(\n\t\t\t` • ${Object.keys(jsonObject)}:`,\n\t\t\t` ${kleur.underline().grey(`${Object.values(jsonObject)}`)}`,\n\t\t);\n\t}\n\treturn messages;\n};\n"],"names":["kleur","GET_REGISTRY_CMD","formatRegistries","registries","messages","stdoutLines","split","jsonObjects","map","line","trimmedLine","trim","startsWith","endsWith","jsonLine","slice","jsonObject","JSON","parse","filter","Boolean","push","Object","keys","underline","grey","values"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAE1B,OAAO,MAAMC,mBACZ,iDAAiD;AAElD,OAAO,MAAMC,mBAAmB,CAACC;IAChC;;;;;;;;EAQC,GACD,MAAMC,WAAW,EAAE;IACnB,MAAMC,cAAcF,WAAWG,KAAK,CAAC;IACrC,MAAMC,cAAcF,YAClBG,GAAG,CAAC,CAACC;QACL,MAAMC,cAAcD,KAAKE,IAAI;QAC7B,IAAID,YAAYE,UAAU,CAAC,QAAQF,YAAYG,QAAQ,CAAC,MAAM;YAC7D,MAAMC,WAAWJ,YAAYK,KAAK,CAAC,GAAG,CAAC,IAAI,wBAAwB;YACnE,IAAI;gBACH,MAAMC,aAAaC,KAAKC,KAAK,CAAC,CAAC,CAAC,EAAEJ,SAAS,CAAC,CAAC;gBAC7C,OAAOE;YACP,mBAAmB,GACpB,EAAE,OAAM;YACP,8BAA8B;YAC/B;QACD;QACA,2CAA2C;QAC3C,OAAO;IACP,kBAAkB,GACnB,GACCG,MAAM,CAACC,UAAU,0BAA0B;IAE7C,KAAK,MAAMJ,cAAcT,YAAa;QACrCH,SAASiB,IAAI,CACZ,CAAC,GAAG,EAAEC,OAAOC,IAAI,CAACP,YAAY,CAAC,CAAC,EAChC,CAAC,IAAI,EAAEhB,MAAMwB,SAAS,GAAGC,IAAI,CAAC,GAAGH,OAAOI,MAAM,CAACV,aAAa,GAAG;IAEjE;IACA,OAAOZ;AACR,EAAE"}
|
|
@@ -10,21 +10,20 @@ export const createProfile = async ({ flags, storeConfig, storeLocation, profile
|
|
|
10
10
|
};
|
|
11
11
|
await fs.ensureFile(storeConfig);
|
|
12
12
|
try {
|
|
13
|
-
// if the profile already exists, do nothing
|
|
13
|
+
// if the profile already exists, do nothing.
|
|
14
14
|
profiles = await fs.readJson(storeConfig);
|
|
15
15
|
if (profiles.available.includes(profileName)) {
|
|
16
16
|
logger.warn(`Profile '${profileName}' already exists...`);
|
|
17
17
|
return 0;
|
|
18
18
|
}
|
|
19
19
|
} catch {
|
|
20
|
-
// ignoring error since we are going to create the file
|
|
20
|
+
// ignoring error since we are going to create the file.
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* If the profile does not exist, create a folder named as
|
|
24
|
-
* the
|
|
25
|
-
* existing npmrc / yarnrc files.
|
|
23
|
+
* If the profile does not exist, create a folder named as the profile under
|
|
24
|
+
* the storeLocation folder, with the existing npmrc / yarnrc files.
|
|
26
25
|
*/ await fs.ensureDir(`${storeLocation}/${profileName}`);
|
|
27
|
-
// copy the existing npmrc / yarnrc files to the new folder
|
|
26
|
+
// copy the existing npmrc / yarnrc files to the new folder.
|
|
28
27
|
const NPMRC = `${homeLocation}/.npmrc`;
|
|
29
28
|
const YARNRC = `${homeLocation}/.yarnrc`;
|
|
30
29
|
if (await fs.pathExists(YARNRC)) {
|
|
@@ -33,7 +32,7 @@ export const createProfile = async ({ flags, storeConfig, storeLocation, profile
|
|
|
33
32
|
if (await fs.pathExists(NPMRC)) {
|
|
34
33
|
await fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);
|
|
35
34
|
}
|
|
36
|
-
// then add the profile to the configuration file
|
|
35
|
+
// then add the profile to the configuration file.
|
|
37
36
|
const newProfiles = {
|
|
38
37
|
available: [
|
|
39
38
|
...profiles.available,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/createProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\n\nexport const createProfile = async ({\n\tflags,\n\tstoreConfig,\n\tstoreLocation,\n\tprofileName,\n\thomeLocation,\n}) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\tlet profiles = { available: [], enabled: undefined };\n\tawait fs.ensureFile(storeConfig);\n\ttry {\n\t\t// if the profile already exists, do nothing
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/createProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\n\nexport const createProfile = async ({\n\tflags,\n\tstoreConfig,\n\tstoreLocation,\n\tprofileName,\n\thomeLocation,\n}) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\tlet profiles = { available: [], enabled: undefined };\n\tawait fs.ensureFile(storeConfig);\n\ttry {\n\t\t// if the profile already exists, do nothing.\n\t\tprofiles = await fs.readJson(storeConfig);\n\t\tif (profiles.available.includes(profileName)) {\n\t\t\tlogger.warn(`Profile '${profileName}' already exists...`);\n\t\t\treturn 0;\n\t\t}\n\t} catch {\n\t\t// ignoring error since we are going to create the file.\n\t}\n\n\t/**\n\t * If the profile does not exist, create a folder named as the profile under\n\t * the storeLocation folder, with the existing npmrc / yarnrc files.\n\t */\n\tawait fs.ensureDir(`${storeLocation}/${profileName}`);\n\t// copy the existing npmrc / yarnrc files to the new folder.\n\tconst NPMRC = `${homeLocation}/.npmrc`;\n\tconst YARNRC = `${homeLocation}/.yarnrc`;\n\tif (await fs.pathExists(YARNRC)) {\n\t\tawait fs.copy(YARNRC, `${storeLocation}/${profileName}/yarnrc`);\n\t}\n\tif (await fs.pathExists(NPMRC)) {\n\t\tawait fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);\n\t}\n\t// then add the profile to the configuration file.\n\tconst newProfiles = {\n\t\tavailable: [...profiles.available, profileName],\n\t\tenabled: profiles.enabled ?? profileName,\n\t};\n\tawait fs.writeJson(storeConfig, newProfiles, { spaces: 2 });\n\tlogger.printBox(`Profile '${profileName}' created`, {\n\t\ttextAlignment: \"left\",\n\t\ttitle: \"Profiles\",\n\t\tborderColor: \"blue\",\n\t});\n\treturn 0;\n};\n"],"names":["Logger","fs","createProfile","flags","storeConfig","storeLocation","profileName","homeLocation","logger","boring","process","env","NODE_ENV","profiles","available","enabled","undefined","ensureFile","readJson","includes","warn","ensureDir","NPMRC","YARNRC","pathExists","copy","newProfiles","writeJson","spaces","printBox","textAlignment","title","borderColor"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAE1B,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,KAAK,EACLC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,YAAY,EACZ;IACA,MAAMC,SAAS,IAAIR,OAAO;QACzBS,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUT,MAAMM,MAAM;IACxD;IAEA,IAAII,WAAW;QAAEC,WAAW,EAAE;QAAEC,SAASC;IAAU;IACnD,MAAMf,GAAGgB,UAAU,CAACb;IACpB,IAAI;QACH,6CAA6C;QAC7CS,WAAW,MAAMZ,GAAGiB,QAAQ,CAACd;QAC7B,IAAIS,SAASC,SAAS,CAACK,QAAQ,CAACb,cAAc;YAC7CE,OAAOY,IAAI,CAAC,CAAC,SAAS,EAAEd,YAAY,mBAAmB,CAAC;YACxD,OAAO;QACR;IACD,EAAE,OAAM;IACP,wDAAwD;IACzD;IAEA;;;EAGC,GACD,MAAML,GAAGoB,SAAS,CAAC,GAAGhB,cAAc,CAAC,EAAEC,aAAa;IACpD,4DAA4D;IAC5D,MAAMgB,QAAQ,GAAGf,aAAa,OAAO,CAAC;IACtC,MAAMgB,SAAS,GAAGhB,aAAa,QAAQ,CAAC;IACxC,IAAI,MAAMN,GAAGuB,UAAU,CAACD,SAAS;QAChC,MAAMtB,GAAGwB,IAAI,CAACF,QAAQ,GAAGlB,cAAc,CAAC,EAAEC,YAAY,OAAO,CAAC;IAC/D;IACA,IAAI,MAAML,GAAGuB,UAAU,CAACF,QAAQ;QAC/B,MAAMrB,GAAGwB,IAAI,CAACH,OAAO,GAAGjB,cAAc,CAAC,EAAEC,YAAY,MAAM,CAAC;IAC7D;IACA,kDAAkD;IAClD,MAAMoB,cAAc;QACnBZ,WAAW;eAAID,SAASC,SAAS;YAAER;SAAY;QAC/CS,SAASF,SAASE,OAAO,IAAIT;IAC9B;IACA,MAAML,GAAG0B,SAAS,CAACvB,aAAasB,aAAa;QAAEE,QAAQ;IAAE;IACzDpB,OAAOqB,QAAQ,CAAC,CAAC,SAAS,EAAEvB,YAAY,SAAS,CAAC,EAAE;QACnDwB,eAAe;QACfC,OAAO;QACPC,aAAa;IACd;IACA,OAAO;AACR,EAAE"}
|
|
@@ -10,14 +10,14 @@ export const deleteProfile = async ({ flags, profileName, storeConfig, storeLoca
|
|
|
10
10
|
logger.error(`Profile '${profileName}' does not exist`);
|
|
11
11
|
return 1;
|
|
12
12
|
}
|
|
13
|
-
// if the profile is enabled, do nothing
|
|
13
|
+
// if the profile is enabled, do nothing.
|
|
14
14
|
if (profiles.enabled === profileName) {
|
|
15
15
|
logger.error(`Profile '${profileName}' is currently active`);
|
|
16
16
|
return 1;
|
|
17
17
|
}
|
|
18
|
-
// if profile exists, delete it by removing the profile folder
|
|
18
|
+
// if profile exists, delete it by removing the profile folder.
|
|
19
19
|
await fs.remove(`${storeLocation}/${profileName}`);
|
|
20
|
-
// then remove the profile from the configuration file
|
|
20
|
+
// then remove the profile from the configuration file.
|
|
21
21
|
const newProfiles = {
|
|
22
22
|
available: profiles.available.filter((profile)=>profile !== profileName),
|
|
23
23
|
enabled: profiles.enabled
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/deleteProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\n\nexport const deleteProfile = async ({\n\tflags,\n\tprofileName,\n\tstoreConfig,\n\tstoreLocation,\n}) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\ttry {\n\t\tconst profiles = await fs.readJson(storeConfig);\n\t\tif (!profiles.available.includes(profileName)) {\n\t\t\tlogger.error(`Profile '${profileName}' does not exist`);\n\t\t\treturn 1;\n\t\t}\n\t\t// if the profile is enabled, do nothing
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/deleteProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\n\nexport const deleteProfile = async ({\n\tflags,\n\tprofileName,\n\tstoreConfig,\n\tstoreLocation,\n}) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\ttry {\n\t\tconst profiles = await fs.readJson(storeConfig);\n\t\tif (!profiles.available.includes(profileName)) {\n\t\t\tlogger.error(`Profile '${profileName}' does not exist`);\n\t\t\treturn 1;\n\t\t}\n\t\t// if the profile is enabled, do nothing.\n\t\tif (profiles.enabled === profileName) {\n\t\t\tlogger.error(`Profile '${profileName}' is currently active`);\n\t\t\treturn 1;\n\t\t}\n\t\t// if profile exists, delete it by removing the profile folder.\n\t\tawait fs.remove(`${storeLocation}/${profileName}`);\n\t\t// then remove the profile from the configuration file.\n\t\tconst newProfiles = {\n\t\t\tavailable: profiles.available.filter(\n\t\t\t\t(profile: any) => profile !== profileName,\n\t\t\t),\n\t\t\tenabled: profiles.enabled,\n\t\t};\n\t\tawait fs.writeJson(storeConfig, newProfiles, { spaces: 2 });\n\t\tlogger.printBox(`Profile '${profileName}' deleted`, {\n\t\t\ttextAlignment: \"left\",\n\t\t\ttitle: \"Profiles\",\n\t\t\tborderColor: \"blue\",\n\t\t});\n\t\treturn 0;\n\t} catch (error) {\n\t\tif (flags.verbose) {\n\t\t\tlogger.log(error);\n\t\t}\n\t\tlogger.error(\"Could not delete profile\");\n\t\treturn 1;\n\t}\n};\n"],"names":["Logger","fs","deleteProfile","flags","profileName","storeConfig","storeLocation","logger","boring","process","env","NODE_ENV","profiles","readJson","available","includes","error","enabled","remove","newProfiles","filter","profile","writeJson","spaces","printBox","textAlignment","title","borderColor","verbose","log"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAE1B,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,KAAK,EACLC,WAAW,EACXC,WAAW,EACXC,aAAa,EACb;IACA,MAAMC,SAAS,IAAIP,OAAO;QACzBQ,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUR,MAAMK,MAAM;IACxD;IAEA,IAAI;QACH,MAAMI,WAAW,MAAMX,GAAGY,QAAQ,CAACR;QACnC,IAAI,CAACO,SAASE,SAAS,CAACC,QAAQ,CAACX,cAAc;YAC9CG,OAAOS,KAAK,CAAC,CAAC,SAAS,EAAEZ,YAAY,gBAAgB,CAAC;YACtD,OAAO;QACR;QACA,yCAAyC;QACzC,IAAIQ,SAASK,OAAO,KAAKb,aAAa;YACrCG,OAAOS,KAAK,CAAC,CAAC,SAAS,EAAEZ,YAAY,qBAAqB,CAAC;YAC3D,OAAO;QACR;QACA,+DAA+D;QAC/D,MAAMH,GAAGiB,MAAM,CAAC,GAAGZ,cAAc,CAAC,EAAEF,aAAa;QACjD,uDAAuD;QACvD,MAAMe,cAAc;YACnBL,WAAWF,SAASE,SAAS,CAACM,MAAM,CACnC,CAACC,UAAiBA,YAAYjB;YAE/Ba,SAASL,SAASK,OAAO;QAC1B;QACA,MAAMhB,GAAGqB,SAAS,CAACjB,aAAac,aAAa;YAAEI,QAAQ;QAAE;QACzDhB,OAAOiB,QAAQ,CAAC,CAAC,SAAS,EAAEpB,YAAY,SAAS,CAAC,EAAE;YACnDqB,eAAe;YACfC,OAAO;YACPC,aAAa;QACd;QACA,OAAO;IACR,EAAE,OAAOX,OAAO;QACf,IAAIb,MAAMyB,OAAO,EAAE;YAClBrB,OAAOsB,GAAG,CAACb;QACZ;QACAT,OAAOS,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GET_REGISTRY_CMD, formatRegistries } from "./common.js";
|
|
2
1
|
import { Logger } from "@node-cli/logger";
|
|
3
2
|
import { run } from "@node-cli/run";
|
|
4
3
|
import fs from "fs-extra";
|
|
5
4
|
import kleur from "kleur";
|
|
5
|
+
import { formatRegistries, GET_REGISTRY_CMD } from "./common.js";
|
|
6
6
|
export const listProfiles = async ({ flags, storeConfig })=>{
|
|
7
7
|
const logger = new Logger({
|
|
8
8
|
boring: process.env.NODE_ENV === "test" || flags.boring
|
|
@@ -15,8 +15,8 @@ export const listProfiles = async ({ flags, storeConfig })=>{
|
|
|
15
15
|
kleur.green(`★ ${activeProfile} (active)`)
|
|
16
16
|
];
|
|
17
17
|
/**
|
|
18
|
-
* Since there is an active profile, we can check the
|
|
19
|
-
*
|
|
18
|
+
* Since there is an active profile, we can check the global registries and
|
|
19
|
+
* list them, alongside the active profile.
|
|
20
20
|
*/ if (activeProfile) {
|
|
21
21
|
const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
|
|
22
22
|
ignoreError: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/listProfiles.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/listProfiles.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport { run } from \"@node-cli/run\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { formatRegistries, GET_REGISTRY_CMD } from \"./common.js\";\n\nexport const listProfiles = async ({ flags, storeConfig }) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\ttry {\n\t\tconst profiles = await fs.readJson(storeConfig);\n\n\t\tif (profiles?.available?.length > 0) {\n\t\t\tconst activeProfile = profiles.enabled;\n\t\t\tconst messages =\n\t\t\t\tactiveProfile === undefined\n\t\t\t\t\t? []\n\t\t\t\t\t: [kleur.green(`★ ${activeProfile} (active)`)];\n\n\t\t\t/**\n\t\t\t * Since there is an active profile, we can check the global registries and\n\t\t\t * list them, alongside the active profile.\n\t\t\t */\n\t\t\tif (activeProfile) {\n\t\t\t\tconst { stdout, stderr } = await run(GET_REGISTRY_CMD, {\n\t\t\t\t\tignoreError: true,\n\t\t\t\t});\n\n\t\t\t\tif (!stderr) {\n\t\t\t\t\tmessages.push(...formatRegistries(stdout as string));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const profile of profiles.available) {\n\t\t\t\tif (profile !== activeProfile) {\n\t\t\t\t\tmessages.push(`${profile}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlogger.printBox(messages.join(\"\\n\"), {\n\t\t\t\ttextAlignment: \"left\",\n\t\t\t\ttitle: \"Profiles\",\n\t\t\t\tborderColor: \"blue\",\n\t\t\t});\n\t\t} else {\n\t\t\tlogger.warn(\"No profiles found\");\n\t\t}\n\t\treturn 0;\n\t} catch (error) {\n\t\tif (flags.verbose) {\n\t\t\tlogger.log(error);\n\t\t}\n\t\tlogger.error(\"Unable to read the profile configuration file\");\n\t\treturn 1;\n\t}\n};\n"],"names":["Logger","run","fs","kleur","formatRegistries","GET_REGISTRY_CMD","listProfiles","flags","storeConfig","logger","boring","process","env","NODE_ENV","profiles","readJson","available","length","activeProfile","enabled","messages","undefined","green","stdout","stderr","ignoreError","push","profile","printBox","join","textAlignment","title","borderColor","warn","error","verbose","log"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAc;AAEjE,OAAO,MAAMC,eAAe,OAAO,EAAEC,KAAK,EAAEC,WAAW,EAAE;IACxD,MAAMC,SAAS,IAAIT,OAAO;QACzBU,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUN,MAAMG,MAAM;IACxD;IAEA,IAAI;QACH,MAAMI,WAAW,MAAMZ,GAAGa,QAAQ,CAACP;QAEnC,IAAIM,UAAUE,WAAWC,SAAS,GAAG;YACpC,MAAMC,gBAAgBJ,SAASK,OAAO;YACtC,MAAMC,WACLF,kBAAkBG,YACf,EAAE,GACF;gBAAClB,MAAMmB,KAAK,CAAC,CAAC,EAAE,EAAEJ,cAAc,SAAS,CAAC;aAAE;YAEhD;;;IAGC,GACD,IAAIA,eAAe;gBAClB,MAAM,EAAEK,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMvB,IAAII,kBAAkB;oBACtDoB,aAAa;gBACd;gBAEA,IAAI,CAACD,QAAQ;oBACZJ,SAASM,IAAI,IAAItB,iBAAiBmB;gBACnC;YACD;YAEA,KAAK,MAAMI,WAAWb,SAASE,SAAS,CAAE;gBACzC,IAAIW,YAAYT,eAAe;oBAC9BE,SAASM,IAAI,CAAC,GAAGC,SAAS;gBAC3B;YACD;YAEAlB,OAAOmB,QAAQ,CAACR,SAASS,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;QACD,OAAO;YACNvB,OAAOwB,IAAI,CAAC;QACb;QACA,OAAO;IACR,EAAE,OAAOC,OAAO;QACf,IAAI3B,MAAM4B,OAAO,EAAE;YAClB1B,OAAO2B,GAAG,CAACF;QACZ;QACAzB,OAAOyB,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GET_REGISTRY_CMD, formatRegistries } from "./common.js";
|
|
2
1
|
import { Logger } from "@node-cli/logger";
|
|
3
2
|
import { run } from "@node-cli/run";
|
|
4
3
|
import fs from "fs-extra";
|
|
5
4
|
import kleur from "kleur";
|
|
5
|
+
import { formatRegistries, GET_REGISTRY_CMD } from "./common.js";
|
|
6
6
|
export const switchProfile = async ({ flags, storeConfig, storeLocation, profileName, homeLocation })=>{
|
|
7
7
|
const logger = new Logger({
|
|
8
8
|
boring: process.env.NODE_ENV === "test" || flags.boring
|
|
@@ -13,14 +13,15 @@ export const switchProfile = async ({ flags, storeConfig, storeLocation, profile
|
|
|
13
13
|
logger.error(`Profile '${profileName}' does not exist`);
|
|
14
14
|
return 1;
|
|
15
15
|
}
|
|
16
|
-
// if profile is already enabled, do nothing
|
|
16
|
+
// if profile is already enabled, do nothing.
|
|
17
17
|
if (profiles.enabled === profileName) {
|
|
18
18
|
logger.warn(`Profile '${profileName}' is already active`);
|
|
19
19
|
return 0;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* if profile exists and is not enabled, switch to it by copying the npmrc and
|
|
23
|
+
* yarnrc files from the profile folder to the home folder.
|
|
24
|
+
*/ const NPMRC = `${homeLocation}/.npmrc`;
|
|
24
25
|
const PROFILE_NPMRC = `${storeLocation}/${profileName}/npmrc`;
|
|
25
26
|
const YARNRC = `${homeLocation}/.yarnrc`;
|
|
26
27
|
const PROFILE_YARNRC = `${storeLocation}/${profileName}/yarnrc`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/switchProfile.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/switchProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport { run } from \"@node-cli/run\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { formatRegistries, GET_REGISTRY_CMD } from \"./common.js\";\n\nexport const switchProfile = async ({\n\tflags,\n\tstoreConfig,\n\tstoreLocation,\n\tprofileName,\n\thomeLocation,\n}) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\ttry {\n\t\tconst profiles = await fs.readJson(storeConfig);\n\t\tif (!profiles.available.includes(profileName)) {\n\t\t\tlogger.error(`Profile '${profileName}' does not exist`);\n\t\t\treturn 1;\n\t\t}\n\t\t// if profile is already enabled, do nothing.\n\t\tif (profiles.enabled === profileName) {\n\t\t\tlogger.warn(`Profile '${profileName}' is already active`);\n\t\t\treturn 0;\n\t\t}\n\t\t/**\n\t\t * if profile exists and is not enabled, switch to it by copying the npmrc and\n\t\t * yarnrc files from the profile folder to the home folder.\n\t\t */\n\t\tconst NPMRC = `${homeLocation}/.npmrc`;\n\t\tconst PROFILE_NPMRC = `${storeLocation}/${profileName}/npmrc`;\n\t\tconst YARNRC = `${homeLocation}/.yarnrc`;\n\t\tconst PROFILE_YARNRC = `${storeLocation}/${profileName}/yarnrc`;\n\n\t\tif (await fs.pathExists(PROFILE_NPMRC)) {\n\t\t\tawait fs.copy(PROFILE_NPMRC, NPMRC, {\n\t\t\t\toverwrite: true,\n\t\t\t});\n\t\t} else {\n\t\t\tlogger.warn(`No npmrc file found for profile '${profileName}'`);\n\t\t}\n\t\tif (await fs.pathExists(PROFILE_YARNRC)) {\n\t\t\tawait fs.copy(PROFILE_YARNRC, YARNRC, {\n\t\t\t\toverwrite: true,\n\t\t\t});\n\t\t} else {\n\t\t\tlogger.warn(`No yarnrc file found for profile '${profileName}'`);\n\t\t}\n\n\t\tconst newProfiles = {\n\t\t\tavailable: profiles.available,\n\t\t\tenabled: profileName,\n\t\t};\n\t\tawait fs.writeJson(storeConfig, newProfiles, { spaces: 2 });\n\t\tconst messages = [kleur.green(`Profile switched to '${profileName}'`)];\n\t\tconst { stdout, stderr } = await run(GET_REGISTRY_CMD, {\n\t\t\tignoreError: true,\n\t\t});\n\t\tif (!stderr) {\n\t\t\tmessages.push(...formatRegistries(stdout as string));\n\t\t}\n\t\tlogger.printBox(messages.join(\"\\n\"), {\n\t\t\ttextAlignment: \"left\",\n\t\t\ttitle: \"Profiles\",\n\t\t\tborderColor: \"blue\",\n\t\t});\n\t\treturn 0;\n\t} catch (error) {\n\t\tif (flags.verbose) {\n\t\t\tlogger.log(error);\n\t\t}\n\t\tlogger.error(\"Could not switch profile\");\n\t\treturn 1;\n\t}\n};\n"],"names":["Logger","run","fs","kleur","formatRegistries","GET_REGISTRY_CMD","switchProfile","flags","storeConfig","storeLocation","profileName","homeLocation","logger","boring","process","env","NODE_ENV","profiles","readJson","available","includes","error","enabled","warn","NPMRC","PROFILE_NPMRC","YARNRC","PROFILE_YARNRC","pathExists","copy","overwrite","newProfiles","writeJson","spaces","messages","green","stdout","stderr","ignoreError","push","printBox","join","textAlignment","title","borderColor","verbose","log"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAc;AAEjE,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,KAAK,EACLC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,YAAY,EACZ;IACA,MAAMC,SAAS,IAAIZ,OAAO;QACzBa,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUT,MAAMM,MAAM;IACxD;IAEA,IAAI;QACH,MAAMI,WAAW,MAAMf,GAAGgB,QAAQ,CAACV;QACnC,IAAI,CAACS,SAASE,SAAS,CAACC,QAAQ,CAACV,cAAc;YAC9CE,OAAOS,KAAK,CAAC,CAAC,SAAS,EAAEX,YAAY,gBAAgB,CAAC;YACtD,OAAO;QACR;QACA,6CAA6C;QAC7C,IAAIO,SAASK,OAAO,KAAKZ,aAAa;YACrCE,OAAOW,IAAI,CAAC,CAAC,SAAS,EAAEb,YAAY,mBAAmB,CAAC;YACxD,OAAO;QACR;QACA;;;GAGC,GACD,MAAMc,QAAQ,GAAGb,aAAa,OAAO,CAAC;QACtC,MAAMc,gBAAgB,GAAGhB,cAAc,CAAC,EAAEC,YAAY,MAAM,CAAC;QAC7D,MAAMgB,SAAS,GAAGf,aAAa,QAAQ,CAAC;QACxC,MAAMgB,iBAAiB,GAAGlB,cAAc,CAAC,EAAEC,YAAY,OAAO,CAAC;QAE/D,IAAI,MAAMR,GAAG0B,UAAU,CAACH,gBAAgB;YACvC,MAAMvB,GAAG2B,IAAI,CAACJ,eAAeD,OAAO;gBACnCM,WAAW;YACZ;QACD,OAAO;YACNlB,OAAOW,IAAI,CAAC,CAAC,iCAAiC,EAAEb,YAAY,CAAC,CAAC;QAC/D;QACA,IAAI,MAAMR,GAAG0B,UAAU,CAACD,iBAAiB;YACxC,MAAMzB,GAAG2B,IAAI,CAACF,gBAAgBD,QAAQ;gBACrCI,WAAW;YACZ;QACD,OAAO;YACNlB,OAAOW,IAAI,CAAC,CAAC,kCAAkC,EAAEb,YAAY,CAAC,CAAC;QAChE;QAEA,MAAMqB,cAAc;YACnBZ,WAAWF,SAASE,SAAS;YAC7BG,SAASZ;QACV;QACA,MAAMR,GAAG8B,SAAS,CAACxB,aAAauB,aAAa;YAAEE,QAAQ;QAAE;QACzD,MAAMC,WAAW;YAAC/B,MAAMgC,KAAK,CAAC,CAAC,qBAAqB,EAAEzB,YAAY,CAAC,CAAC;SAAE;QACtE,MAAM,EAAE0B,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMpC,IAAII,kBAAkB;YACtDiC,aAAa;QACd;QACA,IAAI,CAACD,QAAQ;YACZH,SAASK,IAAI,IAAInC,iBAAiBgC;QACnC;QACAxB,OAAO4B,QAAQ,CAACN,SAASO,IAAI,CAAC,OAAO;YACpCC,eAAe;YACfC,OAAO;YACPC,aAAa;QACd;QACA,OAAO;IACR,EAAE,OAAOvB,OAAO;QACf,IAAId,MAAMsC,OAAO,EAAE;YAClBjC,OAAOkC,GAAG,CAACzB;QACZ;QACAT,OAAOS,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { GET_REGISTRY_CMD, formatRegistries } from "./common.js";
|
|
2
1
|
import { Logger } from "@node-cli/logger";
|
|
3
2
|
import { run } from "@node-cli/run";
|
|
4
3
|
import fs from "fs-extra";
|
|
5
4
|
import kleur from "kleur";
|
|
5
|
+
import { formatRegistries, GET_REGISTRY_CMD } from "./common.js";
|
|
6
6
|
export const updateProfile = async ({ flags, storeConfig, storeLocation, homeLocation })=>{
|
|
7
7
|
const logger = new Logger({
|
|
8
8
|
boring: process.env.NODE_ENV === "test" || flags.boring
|
|
9
9
|
});
|
|
10
10
|
let profiles;
|
|
11
|
-
// Step 1: check if there is an active profile
|
|
11
|
+
// Step 1: check if there is an active profile.
|
|
12
12
|
try {
|
|
13
13
|
profiles = await fs.readJson(storeConfig);
|
|
14
14
|
} catch {
|
|
15
|
-
// ignoring error since we are going to create the file
|
|
15
|
+
// ignoring error since we are going to create the file.
|
|
16
16
|
}
|
|
17
17
|
if (profiles?.available?.length > 0) {
|
|
18
18
|
const profileName = profiles.enabled;
|
|
@@ -21,17 +21,17 @@ export const updateProfile = async ({ flags, storeConfig, storeLocation, homeLoc
|
|
|
21
21
|
kleur.green(`Profile '${profileName}' updated`)
|
|
22
22
|
];
|
|
23
23
|
/**
|
|
24
|
-
* Step2: since there is an active profile, we can check the
|
|
25
|
-
*
|
|
24
|
+
* Step2: since there is an active profile, we can check the global
|
|
25
|
+
* registries and list them, alongside the updated profile.
|
|
26
26
|
*/ const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
|
|
27
27
|
ignoreError: true
|
|
28
28
|
});
|
|
29
29
|
if (!stderr) {
|
|
30
30
|
messages.push(...formatRegistries(stdout));
|
|
31
31
|
}
|
|
32
|
-
// Step 3: update the active profile
|
|
32
|
+
// Step 3: update the active profile.
|
|
33
33
|
await fs.ensureDir(`${storeLocation}/${profileName}`);
|
|
34
|
-
// copy the existing npmrc / yarnrc files to the storage folder
|
|
34
|
+
// copy the existing npmrc / yarnrc files to the storage folder.
|
|
35
35
|
const NPMRC = `${homeLocation}/.npmrc`;
|
|
36
36
|
const YARNRC = `${homeLocation}/.yarnrc`;
|
|
37
37
|
if (await fs.pathExists(YARNRC)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/updateProfile.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/updateProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport { run } from \"@node-cli/run\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { formatRegistries, GET_REGISTRY_CMD } from \"./common.js\";\n\nexport const updateProfile = async ({\n\tflags,\n\tstoreConfig,\n\tstoreLocation,\n\thomeLocation,\n}) => {\n\tconst logger = new Logger({\n\t\tboring: process.env.NODE_ENV === \"test\" || flags.boring,\n\t});\n\n\tlet profiles: { available: string | any[]; enabled: any };\n\n\t// Step 1: check if there is an active profile.\n\ttry {\n\t\tprofiles = await fs.readJson(storeConfig);\n\t} catch {\n\t\t// ignoring error since we are going to create the file.\n\t}\n\n\tif (profiles?.available?.length > 0) {\n\t\tconst profileName = profiles.enabled;\n\t\tif (profileName) {\n\t\t\tconst messages = [kleur.green(`Profile '${profileName}' updated`)];\n\t\t\t/**\n\t\t\t * Step2: since there is an active profile, we can check the global\n\t\t\t * registries and list them, alongside the updated profile.\n\t\t\t */\n\t\t\tconst { stdout, stderr } = await run(GET_REGISTRY_CMD, {\n\t\t\t\tignoreError: true,\n\t\t\t});\n\t\t\tif (!stderr) {\n\t\t\t\tmessages.push(...formatRegistries(stdout as string));\n\t\t\t}\n\n\t\t\t// Step 3: update the active profile.\n\t\t\tawait fs.ensureDir(`${storeLocation}/${profileName}`);\n\t\t\t// copy the existing npmrc / yarnrc files to the storage folder.\n\t\t\tconst NPMRC = `${homeLocation}/.npmrc`;\n\t\t\tconst YARNRC = `${homeLocation}/.yarnrc`;\n\t\t\tif (await fs.pathExists(YARNRC)) {\n\t\t\t\tawait fs.copy(YARNRC, `${storeLocation}/${profileName}/yarnrc`);\n\t\t\t}\n\t\t\tif (await fs.pathExists(NPMRC)) {\n\t\t\t\tawait fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);\n\t\t\t}\n\t\t\tlogger.printBox(messages.join(\"\\n\"), {\n\t\t\t\ttextAlignment: \"left\",\n\t\t\t\ttitle: \"Profiles\",\n\t\t\t\tborderColor: \"blue\",\n\t\t\t});\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tlogger.warn(\n\t\t\"Only active profiles can be updated. Please switch to the profile you want to update.\",\n\t);\n\treturn 0;\n};\n"],"names":["Logger","run","fs","kleur","formatRegistries","GET_REGISTRY_CMD","updateProfile","flags","storeConfig","storeLocation","homeLocation","logger","boring","process","env","NODE_ENV","profiles","readJson","available","length","profileName","enabled","messages","green","stdout","stderr","ignoreError","push","ensureDir","NPMRC","YARNRC","pathExists","copy","printBox","join","textAlignment","title","borderColor","warn"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAc;AAEjE,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,KAAK,EACLC,WAAW,EACXC,aAAa,EACbC,YAAY,EACZ;IACA,MAAMC,SAAS,IAAIX,OAAO;QACzBY,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUR,MAAMK,MAAM;IACxD;IAEA,IAAII;IAEJ,+CAA+C;IAC/C,IAAI;QACHA,WAAW,MAAMd,GAAGe,QAAQ,CAACT;IAC9B,EAAE,OAAM;IACP,wDAAwD;IACzD;IAEA,IAAIQ,UAAUE,WAAWC,SAAS,GAAG;QACpC,MAAMC,cAAcJ,SAASK,OAAO;QACpC,IAAID,aAAa;YAChB,MAAME,WAAW;gBAACnB,MAAMoB,KAAK,CAAC,CAAC,SAAS,EAAEH,YAAY,SAAS,CAAC;aAAE;YAClE;;;IAGC,GACD,MAAM,EAAEI,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMxB,IAAII,kBAAkB;gBACtDqB,aAAa;YACd;YACA,IAAI,CAACD,QAAQ;gBACZH,SAASK,IAAI,IAAIvB,iBAAiBoB;YACnC;YAEA,qCAAqC;YACrC,MAAMtB,GAAG0B,SAAS,CAAC,GAAGnB,cAAc,CAAC,EAAEW,aAAa;YACpD,gEAAgE;YAChE,MAAMS,QAAQ,GAAGnB,aAAa,OAAO,CAAC;YACtC,MAAMoB,SAAS,GAAGpB,aAAa,QAAQ,CAAC;YACxC,IAAI,MAAMR,GAAG6B,UAAU,CAACD,SAAS;gBAChC,MAAM5B,GAAG8B,IAAI,CAACF,QAAQ,GAAGrB,cAAc,CAAC,EAAEW,YAAY,OAAO,CAAC;YAC/D;YACA,IAAI,MAAMlB,GAAG6B,UAAU,CAACF,QAAQ;gBAC/B,MAAM3B,GAAG8B,IAAI,CAACH,OAAO,GAAGpB,cAAc,CAAC,EAAEW,YAAY,MAAM,CAAC;YAC7D;YACAT,OAAOsB,QAAQ,CAACX,SAASY,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;YACA,OAAO;QACR;IACD;IAEA1B,OAAO2B,IAAI,CACV;IAED,OAAO;AACR,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/npmrc",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Toggle different npmrc configuration files on the fly",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"exports": "./dist/npmrc.js",
|
|
10
10
|
"bin": "dist/npmrc.js",
|
|
11
11
|
"files": [
|
|
12
|
-
"dist"
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"node": ">=18",
|
|
15
16
|
"scripts": {
|
|
@@ -18,21 +19,28 @@
|
|
|
18
19
|
"build:js": "swc --strip-leading-paths --source-maps --out-dir dist src",
|
|
19
20
|
"build:types": "tsc",
|
|
20
21
|
"clean": "rimraf dist types coverage",
|
|
22
|
+
"comments:fix": "comments --merge-line-comments 'src/**/*.ts'",
|
|
21
23
|
"lint": "biome lint src",
|
|
22
|
-
"
|
|
23
|
-
"test
|
|
24
|
-
"test:
|
|
24
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
25
|
+
"test": "vitest run --globals",
|
|
26
|
+
"test:coverage": "vitest run --coverage --globals",
|
|
27
|
+
"test:watch": "vitest --globals",
|
|
25
28
|
"watch": "swc --strip-leading-paths --watch --out-dir dist src"
|
|
26
29
|
},
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"@node-cli/logger": "
|
|
29
|
-
"@node-cli/parser": "
|
|
30
|
-
"@node-cli/run": "
|
|
31
|
-
"fs-extra": "11.
|
|
31
|
+
"@node-cli/logger": "../logger",
|
|
32
|
+
"@node-cli/parser": "../parser",
|
|
33
|
+
"@node-cli/run": "../run",
|
|
34
|
+
"fs-extra": "11.3.1",
|
|
32
35
|
"kleur": "4.1.5"
|
|
33
36
|
},
|
|
34
37
|
"publishConfig": {
|
|
35
38
|
"access": "public"
|
|
36
39
|
},
|
|
37
|
-
"
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@node-cli/comments": "0.2.0",
|
|
42
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
43
|
+
"vitest": "3.2.4"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "d90392dcb766dd605bc3eeabc7c7a7ab0c8e6da6"
|
|
38
46
|
}
|