@node-cli/npmrc 1.1.0 → 1.2.0

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/index.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  export * from "./defaults";
6
6
  export * from "./npmrc";
7
7
  export * from "./parse";
8
+ export * from "./utilities/common";
8
9
  export * from "./utilities/createProfile";
9
10
  export * from "./utilities/deleteProfile";
10
11
  export * from "./utilities/listProfiles";
package/dist/npmrc.js CHANGED
@@ -12,6 +12,7 @@ const NPMRC_STORE_CONFIG = path.join(HOME, "/.envtools/npmrcs.json");
12
12
  const { parameters, flags, showHelp } = config;
13
13
  if (flags.create && parameters !== undefined) {
14
14
  const exitFlag = await createProfile({
15
+ flags,
15
16
  storeConfig: NPMRC_STORE_CONFIG,
16
17
  storeLocation: NPMRC_STORE,
17
18
  profileName: parameters["0"],
@@ -21,6 +22,7 @@ if (flags.create && parameters !== undefined) {
21
22
  }
22
23
  if (flags.update && parameters !== undefined) {
23
24
  const exitFlag = await updateProfile({
25
+ flags,
24
26
  storeConfig: NPMRC_STORE_CONFIG,
25
27
  storeLocation: NPMRC_STORE,
26
28
  homeLocation: HOME
package/dist/npmrc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/npmrc.ts"],"sourcesContent":["#!/usr/bin/env node\n/* istanbul ignore file */\n\nimport { config } from \"./parse.js\";\nimport { createProfile } from \"./utilities/createProfile.js\";\nimport { deleteProfile } from \"./utilities/deleteProfile.js\";\nimport { listProfiles } from \"./utilities/listProfiles.js\";\nimport path from \"node:path\";\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\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\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"],"names":["config","createProfile","deleteProfile","listProfiles","path","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,wBAAwB,GAExB,SAASA,MAAM,QAAQ,aAAa;AACpC,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,YAAY,QAAQ,8BAA8B;AAC3D,OAAOC,UAAU,YAAY;AAC7B,SAASC,aAAa,QAAQ,+BAA+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r/bin/env node\n/* istanbul ignore file */\n\nimport { config } from \"./parse.js\";\nimport { createProfile } from \"./utilities/createProfile.js\";\nimport { deleteProfile } from \"./utilities/deleteProfile.js\";\nimport { listProfiles } from \"./utilities/listProfiles.js\";\nimport path from \"node:path\";\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"],"names":["config","createProfile","deleteProfile","listProfiles","path","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,wBAAwB,GAExB,SAASA,MAAM,QAAQ,aAAa;AACpC,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,YAAY,QAAQ,8BAA8B;AAC3D,OAAOC,UAAU,YAAY;AAC7B,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,aAAa,QAAQ,+BAA+B;AAE7D,MAAMC,OAAOC,QAAQC,GAAG,CAACF,IAAI;AAC7B,MAAMG,cAAcN,KAAKO,IAAI,CAACJ,MAAM;AACpC,MAAMK,qBAAqBR,KAAKO,IAAI,CAACJ,MAAM;AAE3C,MAAM,EAAEM,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGf;AAExC,IAAIc,MAAME,MAAM,IAAIH,eAAeI,WAAW;IAC7C,MAAMC,WAAW,MAAMjB,cAAc;QACpCa;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,MAAMhB,cAAc;QACpCY;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,MAAMf,aAAa;QACnCW;QACAK,aAAaP;IACd;IACAJ,QAAQe,IAAI,CAACL;AACd;AAEAH"}
@@ -0,0 +1,2 @@
1
+ export declare const GET_REGISTRY_CMD = "npm config list -l -g -json | grep registry\\\"";
2
+ export declare const formatRegistries: (registries: string) => any[];
@@ -0,0 +1,37 @@
1
+ import kleur from "kleur";
2
+ export const GET_REGISTRY_CMD = 'npm config list -l -g -json | grep registry\\"';
3
+ export const formatRegistries = (registries)=>{
4
+ /**
5
+ * We receive this kind of output:
6
+ * [
7
+ * ' "@node-cli:registry": "https://other-registry.npmjs.org/"',
8
+ * ' "registry": "https://registry.npmjs.org/"',
9
+ * ]
10
+ * And we need convert that to a JSON object that looks like that:
11
+ * [
12
+ * { "@node-cli:registry": "https://other-registry.npmjs.org/" },
13
+ * { "registry": "https://registry.npmjs.org/" },
14
+ * ]
15
+ */ const messages = [];
16
+ const stdoutLines = registries.split("\n");
17
+ const jsonObjects = stdoutLines.map((line)=>{
18
+ const trimmedLine = line.trim();
19
+ if (trimmedLine.startsWith('"') && trimmedLine.endsWith(",")) {
20
+ const jsonLine = trimmedLine.slice(0, -1); // remove trailing comma
21
+ try {
22
+ const jsonObject = JSON.parse(`{${jsonLine}}`);
23
+ return jsonObject;
24
+ } catch {
25
+ // nothing to declare officer
26
+ }
27
+ }
28
+ // eslint-disable-next-line unicorn/no-null
29
+ return null;
30
+ }).filter(Boolean); // remove undefined values
31
+ for (const jsonObject of jsonObjects){
32
+ messages.push(` • ${Object.keys(jsonObject)}:`, ` ${kleur.underline().grey(`${Object.values(jsonObject)}`)}`);
33
+ }
34
+ return messages;
35
+ };
36
+
37
+ //# sourceMappingURL=common.js.map
@@ -0,0 +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:\n\t * [\n\t * ' \"@node-cli:registry\": \"https://other-registry.npmjs.org/\"',\n\t * ' \"registry\": \"https://registry.npmjs.org/\"',\n\t * ]\n\t * And we need convert that to a JSON object that looks like that:\n\t * [\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} 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})\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;;;;;;;;;;;EAWC,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;YACR,EAAE,OAAM;YACP,6BAA6B;YAC9B;QACD;QACA,2CAA2C;QAC3C,OAAO;IACR,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,CAAC,EAAEH,OAAOI,MAAM,CAACV,YAAY,CAAC,EAAE,CAAC;IAEjE;IACA,OAAOZ;AACR,EAAE"}
@@ -1,6 +1,5 @@
1
- import { Logger } from "@node-cli/logger";
2
- export declare const logger: Logger;
3
- export declare const createProfile: ({ storeConfig, storeLocation, profileName, homeLocation, }: {
1
+ export declare const createProfile: ({ flags, storeConfig, storeLocation, profileName, homeLocation, }: {
2
+ flags: any;
4
3
  storeConfig: any;
5
4
  storeLocation: any;
6
5
  profileName: any;
@@ -1,8 +1,9 @@
1
1
  import { Logger } from "@node-cli/logger";
2
2
  import fs from "fs-extra";
3
- export const logger = new Logger();
4
- logger.boring = process.env.NODE_ENV === "test";
5
- export const createProfile = async ({ storeConfig, storeLocation, profileName, homeLocation })=>{
3
+ export const createProfile = async ({ flags, storeConfig, storeLocation, profileName, homeLocation })=>{
4
+ const logger = new Logger({
5
+ boring: process.env.NODE_ENV === "test" || flags.boring
6
+ });
6
7
  let profiles = {
7
8
  available: [],
8
9
  enabled: undefined
@@ -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 logger = new Logger();\nlogger.boring = process.env.NODE_ENV === \"test\";\n\nexport const createProfile = async ({\n\tstoreConfig,\n\tstoreLocation,\n\tprofileName,\n\thomeLocation,\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\n\t * the profile under the storeLocation folder, with the\n\t * 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","logger","boring","process","env","NODE_ENV","createProfile","storeConfig","storeLocation","profileName","homeLocation","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,SAAS,IAAIF,SAAS;AACnCE,OAAOC,MAAM,GAAGC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAEzC,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,YAAY,EACZ;IACA,IAAIC,WAAW;QAAEC,WAAW,EAAE;QAAEC,SAASC;IAAU;IACnD,MAAMd,GAAGe,UAAU,CAACR;IACpB,IAAI;QACH,4CAA4C;QAC5CI,WAAW,MAAMX,GAAGgB,QAAQ,CAACT;QAC7B,IAAII,SAASC,SAAS,CAACK,QAAQ,CAACR,cAAc;YAC7CR,OAAOiB,IAAI,CAAC,CAAC,SAAS,EAAET,YAAY,mBAAmB,CAAC;YACxD,OAAO;QACR;IACD,EAAE,OAAM;IACP,uDAAuD;IACxD;IAEA;;;;EAIC,GACD,MAAMT,GAAGmB,SAAS,CAAC,CAAC,EAAEX,cAAc,CAAC,EAAEC,YAAY,CAAC;IACpD,2DAA2D;IAC3D,MAAMW,QAAQ,CAAC,EAAEV,aAAa,OAAO,CAAC;IACtC,MAAMW,SAAS,CAAC,EAAEX,aAAa,QAAQ,CAAC;IACxC,IAAI,MAAMV,GAAGsB,UAAU,CAACD,SAAS;QAChC,MAAMrB,GAAGuB,IAAI,CAACF,QAAQ,CAAC,EAAEb,cAAc,CAAC,EAAEC,YAAY,OAAO,CAAC;IAC/D;IACA,IAAI,MAAMT,GAAGsB,UAAU,CAACF,QAAQ;QAC/B,MAAMpB,GAAGuB,IAAI,CAACH,OAAO,CAAC,EAAEZ,cAAc,CAAC,EAAEC,YAAY,MAAM,CAAC;IAC7D;IACA,iDAAiD;IACjD,MAAMe,cAAc;QACnBZ,WAAW;eAAID,SAASC,SAAS;YAAEH;SAAY;QAC/CI,SAASF,SAASE,OAAO,IAAIJ;IAC9B;IACA,MAAMT,GAAGyB,SAAS,CAAClB,aAAaiB,aAAa;QAAEE,QAAQ;IAAE;IACzDzB,OAAO0B,QAAQ,CAAC,CAAC,SAAS,EAAElB,YAAY,SAAS,CAAC,EAAE;QACnDmB,eAAe;QACfC,OAAO;QACPC,aAAa;IACd;IACA,OAAO;AACR,EAAE"}
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\n\t * the profile under the storeLocation folder, with the\n\t * 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,4CAA4C;QAC5CS,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,uDAAuD;IACxD;IAEA;;;;EAIC,GACD,MAAML,GAAGoB,SAAS,CAAC,CAAC,EAAEhB,cAAc,CAAC,EAAEC,YAAY,CAAC;IACpD,2DAA2D;IAC3D,MAAMgB,QAAQ,CAAC,EAAEf,aAAa,OAAO,CAAC;IACtC,MAAMgB,SAAS,CAAC,EAAEhB,aAAa,QAAQ,CAAC;IACxC,IAAI,MAAMN,GAAGuB,UAAU,CAACD,SAAS;QAChC,MAAMtB,GAAGwB,IAAI,CAACF,QAAQ,CAAC,EAAElB,cAAc,CAAC,EAAEC,YAAY,OAAO,CAAC;IAC/D;IACA,IAAI,MAAML,GAAGuB,UAAU,CAACF,QAAQ;QAC/B,MAAMrB,GAAGwB,IAAI,CAACH,OAAO,CAAC,EAAEjB,cAAc,CAAC,EAAEC,YAAY,MAAM,CAAC;IAC7D;IACA,iDAAiD;IACjD,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"}
@@ -1,5 +1,3 @@
1
- import { Logger } from "@node-cli/logger";
2
- export declare const logger: Logger;
3
1
  export declare const deleteProfile: ({ flags, profileName, storeConfig, storeLocation, }: {
4
2
  flags: any;
5
3
  profileName: any;
@@ -1,8 +1,9 @@
1
1
  import { Logger } from "@node-cli/logger";
2
2
  import fs from "fs-extra";
3
- export const logger = new Logger();
4
- logger.boring = process.env.NODE_ENV === "test";
5
3
  export const deleteProfile = async ({ flags, profileName, storeConfig, storeLocation })=>{
4
+ const logger = new Logger({
5
+ boring: process.env.NODE_ENV === "test" || flags.boring
6
+ });
6
7
  try {
7
8
  const profiles = await fs.readJson(storeConfig);
8
9
  if (!profiles.available.includes(profileName)) {
@@ -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 logger = new Logger();\nlogger.boring = process.env.NODE_ENV === \"test\";\n\nexport const deleteProfile = async ({\n\tflags,\n\tprofileName,\n\tstoreConfig,\n\tstoreLocation,\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","logger","boring","process","env","NODE_ENV","deleteProfile","flags","profileName","storeConfig","storeLocation","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,SAAS,IAAIF,SAAS;AACnCE,OAAOC,MAAM,GAAGC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAEzC,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,KAAK,EACLC,WAAW,EACXC,WAAW,EACXC,aAAa,EACb;IACA,IAAI;QACH,MAAMC,WAAW,MAAMX,GAAGY,QAAQ,CAACH;QACnC,IAAI,CAACE,SAASE,SAAS,CAACC,QAAQ,CAACN,cAAc;YAC9CP,OAAOc,KAAK,CAAC,CAAC,SAAS,EAAEP,YAAY,gBAAgB,CAAC;YACtD,OAAO;QACR;QACA,wCAAwC;QACxC,IAAIG,SAASK,OAAO,KAAKR,aAAa;YACrCP,OAAOc,KAAK,CAAC,CAAC,SAAS,EAAEP,YAAY,qBAAqB,CAAC;YAC3D,OAAO;QACR;QACA,8DAA8D;QAC9D,MAAMR,GAAGiB,MAAM,CAAC,CAAC,EAAEP,cAAc,CAAC,EAAEF,YAAY,CAAC;QACjD,sDAAsD;QACtD,MAAMU,cAAc;YACnBL,WAAWF,SAASE,SAAS,CAACM,MAAM,CACnC,CAACC,UAAiBA,YAAYZ;YAE/BQ,SAASL,SAASK,OAAO;QAC1B;QACA,MAAMhB,GAAGqB,SAAS,CAACZ,aAAaS,aAAa;YAAEI,QAAQ;QAAE;QACzDrB,OAAOsB,QAAQ,CAAC,CAAC,SAAS,EAAEf,YAAY,SAAS,CAAC,EAAE;YACnDgB,eAAe;YACfC,OAAO;YACPC,aAAa;QACd;QACA,OAAO;IACR,EAAE,OAAOX,OAAO;QACf,IAAIR,MAAMoB,OAAO,EAAE;YAClB1B,OAAO2B,GAAG,CAACb;QACZ;QACAd,OAAOc,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
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,wCAAwC;QACxC,IAAIQ,SAASK,OAAO,KAAKb,aAAa;YACrCG,OAAOS,KAAK,CAAC,CAAC,SAAS,EAAEZ,YAAY,qBAAqB,CAAC;YAC3D,OAAO;QACR;QACA,8DAA8D;QAC9D,MAAMH,GAAGiB,MAAM,CAAC,CAAC,EAAEZ,cAAc,CAAC,EAAEF,YAAY,CAAC;QACjD,sDAAsD;QACtD,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,5 +1,3 @@
1
- import { Logger } from "@node-cli/logger";
2
- export declare const logger: Logger;
3
1
  export declare const listProfiles: ({ flags, storeConfig }: {
4
2
  flags: any;
5
3
  storeConfig: any;
@@ -1,10 +1,12 @@
1
+ import { GET_REGISTRY_CMD, formatRegistries } from "./common.js";
1
2
  import { Logger } from "@node-cli/logger";
2
3
  import fs from "fs-extra";
3
4
  import kleur from "kleur";
4
5
  import { run } from "@node-cli/run";
5
- export const logger = new Logger();
6
- logger.boring = process.env.NODE_ENV === "test";
7
6
  export const listProfiles = async ({ flags, storeConfig })=>{
7
+ const logger = new Logger({
8
+ boring: process.env.NODE_ENV === "test" || flags.boring
9
+ });
8
10
  try {
9
11
  const profiles = await fs.readJson(storeConfig);
10
12
  if (profiles?.available?.length > 0) {
@@ -14,14 +16,13 @@ export const listProfiles = async ({ flags, storeConfig })=>{
14
16
  ];
15
17
  /**
16
18
  * Since there is an active profile, we can check the
17
- * global registry and list it, alongside the active profile.
19
+ * global registries and list them, alongside the active profile.
18
20
  */ if (activeProfile) {
19
- const { stdout, stderr } = await run('npm config list -l -g | grep "registry ="', {
21
+ const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
20
22
  ignoreError: true
21
23
  });
22
24
  if (!stderr) {
23
- const stdoutArray = stdout.split("\n").map((line)=>kleur.grey(` • ${line}`));
24
- messages.push(...stdoutArray);
25
+ messages.push(...formatRegistries(stdout));
25
26
  }
26
27
  }
27
28
  for (const profile of profiles.available){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/listProfiles.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { run } from \"@node-cli/run\";\n\nexport const logger = new Logger();\nlogger.boring = process.env.NODE_ENV === \"test\";\n\nexport const listProfiles = async ({ flags, storeConfig }) => {\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\n\t\t\t * global registry and list it, alongside the active profile.\n\t\t\t */\n\t\t\tif (activeProfile) {\n\t\t\t\tconst { stdout, stderr } = await run(\n\t\t\t\t\t'npm config list -l -g | grep \"registry =\"',\n\t\t\t\t\t{\n\t\t\t\t\t\tignoreError: true,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tif (!stderr) {\n\t\t\t\t\tconst stdoutArray = (stdout as string)\n\t\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t\t.map((line) => kleur.grey(` • ${line}`));\n\t\t\t\t\tmessages.push(...stdoutArray);\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","fs","kleur","run","logger","boring","process","env","NODE_ENV","listProfiles","flags","storeConfig","profiles","readJson","available","length","activeProfile","enabled","messages","undefined","green","stdout","stderr","ignoreError","stdoutArray","split","map","line","grey","push","profile","printBox","join","textAlignment","title","borderColor","warn","error","verbose","log"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,OAAO,MAAMC,SAAS,IAAIJ,SAAS;AACnCI,OAAOC,MAAM,GAAGC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAEzC,OAAO,MAAMC,eAAe,OAAO,EAAEC,KAAK,EAAEC,WAAW,EAAE;IACxD,IAAI;QACH,MAAMC,WAAW,MAAMX,GAAGY,QAAQ,CAACF;QAEnC,IAAIC,UAAUE,WAAWC,SAAS,GAAG;YACpC,MAAMC,gBAAgBJ,SAASK,OAAO;YACtC,MAAMC,WACLF,kBAAkBG,YACf,EAAE,GACF;gBAACjB,MAAMkB,KAAK,CAAC,CAAC,EAAE,EAAEJ,cAAc,SAAS,CAAC;aAAE;YAEhD;;;IAGC,GACD,IAAIA,eAAe;gBAClB,MAAM,EAAEK,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMnB,IAChC,6CACA;oBACCoB,aAAa;gBACd;gBAED,IAAI,CAACD,QAAQ;oBACZ,MAAME,cAAc,AAACH,OACnBI,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASzB,MAAM0B,IAAI,CAAC,CAAC,KAAK,EAAED,KAAK,CAAC;oBACzCT,SAASW,IAAI,IAAIL;gBAClB;YACD;YAEA,KAAK,MAAMM,WAAWlB,SAASE,SAAS,CAAE;gBACzC,IAAIgB,YAAYd,eAAe;oBAC9BE,SAASW,IAAI,CAAC,CAAC,EAAEC,QAAQ,CAAC;gBAC3B;YACD;YAEA1B,OAAO2B,QAAQ,CAACb,SAASc,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;QACD,OAAO;YACN/B,OAAOgC,IAAI,CAAC;QACb;QACA,OAAO;IACR,EAAE,OAAOC,OAAO;QACf,IAAI3B,MAAM4B,OAAO,EAAE;YAClBlC,OAAOmC,GAAG,CAACF;QACZ;QACAjC,OAAOiC,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
1
+ {"version":3,"sources":["../../src/utilities/listProfiles.ts"],"sourcesContent":["import { GET_REGISTRY_CMD, formatRegistries } from \"./common.js\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { run } from \"@node-cli/run\";\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\n\t\t\t * global registries and 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":["GET_REGISTRY_CMD","formatRegistries","Logger","fs","kleur","run","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,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAc;AAEjE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,OAAO,MAAMC,eAAe,OAAO,EAAEC,KAAK,EAAEC,WAAW,EAAE;IACxD,MAAMC,SAAS,IAAIP,OAAO;QACzBQ,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUN,MAAMG,MAAM;IACxD;IAEA,IAAI;QACH,MAAMI,WAAW,MAAMX,GAAGY,QAAQ,CAACP;QAEnC,IAAIM,UAAUE,WAAWC,SAAS,GAAG;YACpC,MAAMC,gBAAgBJ,SAASK,OAAO;YACtC,MAAMC,WACLF,kBAAkBG,YACf,EAAE,GACF;gBAACjB,MAAMkB,KAAK,CAAC,CAAC,EAAE,EAAEJ,cAAc,SAAS,CAAC;aAAE;YAEhD;;;IAGC,GACD,IAAIA,eAAe;gBAClB,MAAM,EAAEK,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMnB,IAAIL,kBAAkB;oBACtDyB,aAAa;gBACd;gBAEA,IAAI,CAACD,QAAQ;oBACZJ,SAASM,IAAI,IAAIzB,iBAAiBsB;gBACnC;YACD;YAEA,KAAK,MAAMI,WAAWb,SAASE,SAAS,CAAE;gBACzC,IAAIW,YAAYT,eAAe;oBAC9BE,SAASM,IAAI,CAAC,CAAC,EAAEC,QAAQ,CAAC;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,5 +1,3 @@
1
- import { Logger } from "@node-cli/logger";
2
- export declare const logger: Logger;
3
1
  export declare const switchProfile: ({ flags, storeConfig, storeLocation, profileName, homeLocation, }: {
4
2
  flags: any;
5
3
  storeConfig: any;
@@ -1,8 +1,12 @@
1
+ import { GET_REGISTRY_CMD, formatRegistries } from "./common.js";
1
2
  import { Logger } from "@node-cli/logger";
2
3
  import fs from "fs-extra";
3
- export const logger = new Logger();
4
- logger.boring = process.env.NODE_ENV === "test";
4
+ import kleur from "kleur";
5
+ import { run } from "@node-cli/run";
5
6
  export const switchProfile = async ({ flags, storeConfig, storeLocation, profileName, homeLocation })=>{
7
+ const logger = new Logger({
8
+ boring: process.env.NODE_ENV === "test" || flags.boring
9
+ });
6
10
  try {
7
11
  const profiles = await fs.readJson(storeConfig);
8
12
  if (!profiles.available.includes(profileName)) {
@@ -41,7 +45,16 @@ export const switchProfile = async ({ flags, storeConfig, storeLocation, profile
41
45
  await fs.writeJson(storeConfig, newProfiles, {
42
46
  spaces: 2
43
47
  });
44
- logger.printBox(`Profile switched to '${profileName}'`, {
48
+ const messages = [
49
+ kleur.green(`Profile switched to '${profileName}'`)
50
+ ];
51
+ const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
52
+ ignoreError: true
53
+ });
54
+ if (!stderr) {
55
+ messages.push(...formatRegistries(stdout));
56
+ }
57
+ logger.printBox(messages.join("\n"), {
45
58
  textAlignment: "left",
46
59
  title: "Profiles",
47
60
  borderColor: "blue"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/switchProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\n\nexport const logger = new Logger();\nlogger.boring = process.env.NODE_ENV === \"test\";\n\nexport const switchProfile = async ({\n\tflags,\n\tstoreConfig,\n\tstoreLocation,\n\tprofileName,\n\thomeLocation,\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// if profile exists and is not enabled, switch to it by copying\n\t\t// the npmrc and yarnrc files from the profile folder to the home folder\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\tlogger.printBox(`Profile switched to '${profileName}'`, {\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","fs","logger","boring","process","env","NODE_ENV","switchProfile","flags","storeConfig","storeLocation","profileName","homeLocation","profiles","readJson","available","includes","error","enabled","warn","NPMRC","PROFILE_NPMRC","YARNRC","PROFILE_YARNRC","pathExists","copy","overwrite","newProfiles","writeJson","spaces","printBox","textAlignment","title","borderColor","verbose","log"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAE1B,OAAO,MAAMC,SAAS,IAAIF,SAAS;AACnCE,OAAOC,MAAM,GAAGC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAEz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,QAAQ;QAAE;QACzD3B,OAAO4B,QAAQ,CAAC,CAAC,qBAAqB,EAAEnB,YAAY,CAAC,CAAC,EAAE;YACvDoB,eAAe;YACfC,OAAO;YACPC,aAAa;QACd;QACA,OAAO;IACR,EAAE,OAAOhB,OAAO;QACf,IAAIT,MAAM0B,OAAO,EAAE;YAClBhC,OAAOiC,GAAG,CAAClB;QACZ;QACAf,OAAOe,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
1
+ {"version":3,"sources":["../../src/utilities/switchProfile.ts"],"sourcesContent":["import { GET_REGISTRY_CMD, formatRegistries } from \"./common.js\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { run } from \"@node-cli/run\";\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// if profile exists and is not enabled, switch to it by copying\n\t\t// the npmrc and yarnrc files from the profile folder to the home folder\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":["GET_REGISTRY_CMD","formatRegistries","Logger","fs","kleur","run","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,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAc;AAEjE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,OAAO,MAAMC,gBAAgB,OAAO,EACnCC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S;YAC7BG,SAASZ;QACV;QACA,MAAMP,GAAG6B,SAAS,CAACxB,aAAauB,aAAa;YAAEE,QAAQ;QAAE;QACzD,MAAMC,WAAW;YAAC9B,MAAM+B,KAAK,CAAC,CAAC,qBAAqB,EAAEzB,YAAY,CAAC,CAAC;SAAE;QACtE,MAAM,EAAE0B,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMhC,IAAIL,kBAAkB;YACtDsC,aAAa;QACd;QACA,IAAI,CAACD,QAAQ;YACZH,SAASK,IAAI,IAAItC,iBAAiBmC;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,6 +1,5 @@
1
- import { Logger } from "@node-cli/logger";
2
- export declare const logger: Logger;
3
- export declare const updateProfile: ({ storeConfig, storeLocation, homeLocation, }: {
1
+ export declare const updateProfile: ({ flags, storeConfig, storeLocation, homeLocation, }: {
2
+ flags: any;
4
3
  storeConfig: any;
5
4
  storeLocation: any;
6
5
  homeLocation: any;
@@ -1,10 +1,12 @@
1
+ import { GET_REGISTRY_CMD, formatRegistries } from "./common.js";
1
2
  import { Logger } from "@node-cli/logger";
2
3
  import fs from "fs-extra";
3
4
  import kleur from "kleur";
4
5
  import { run } from "@node-cli/run";
5
- export const logger = new Logger();
6
- logger.boring = process.env.NODE_ENV === "test";
7
- export const updateProfile = async ({ storeConfig, storeLocation, homeLocation })=>{
6
+ export const updateProfile = async ({ flags, storeConfig, storeLocation, homeLocation })=>{
7
+ const logger = new Logger({
8
+ boring: process.env.NODE_ENV === "test" || flags.boring
9
+ });
8
10
  let profiles;
9
11
  // Step 1: check if there is an active profile
10
12
  try {
@@ -20,13 +22,12 @@ export const updateProfile = async ({ storeConfig, storeLocation, homeLocation }
20
22
  ];
21
23
  /**
22
24
  * Step2: since there is an active profile, we can check the
23
- * global registry and list it, alongside the active profile.
24
- */ const { stdout, stderr } = await run('npm config list -l -g | grep "registry ="', {
25
+ * global registries and list them, alongside the updated profile.
26
+ */ const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
25
27
  ignoreError: true
26
28
  });
27
29
  if (!stderr) {
28
- const stdoutArray = stdout.split("\n").map((line)=>kleur.grey(` • ${line}`));
29
- messages.push(...stdoutArray);
30
+ messages.push(...formatRegistries(stdout));
30
31
  }
31
32
  // Step 3: update the active profile
32
33
  await fs.ensureDir(`${storeLocation}/${profileName}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/updateProfile.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { run } from \"@node-cli/run\";\n\nexport const logger = new Logger();\nlogger.boring = process.env.NODE_ENV === \"test\";\n\nexport const updateProfile = async ({\n\tstoreConfig,\n\tstoreLocation,\n\thomeLocation,\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\n\t\t\t * global registry and list it, alongside the active profile.\n\t\t\t */\n\n\t\t\tconst { stdout, stderr } = await run(\n\t\t\t\t'npm config list -l -g | grep \"registry =\"',\n\t\t\t\t{\n\t\t\t\t\tignoreError: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (!stderr) {\n\t\t\t\tconst stdoutArray = (stdout as string)\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.map((line) => kleur.grey(` • ${line}`));\n\t\t\t\tmessages.push(...stdoutArray);\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","fs","kleur","run","logger","boring","process","env","NODE_ENV","updateProfile","storeConfig","storeLocation","homeLocation","profiles","readJson","available","length","profileName","enabled","messages","green","stdout","stderr","ignoreError","stdoutArray","split","map","line","grey","push","ensureDir","NPMRC","YARNRC","pathExists","copy","printBox","join","textAlignment","title","borderColor","warn"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,OAAO,MAAMC,SAAS,IAAIJ,SAAS;AACnCI,OAAOC,MAAM,GAAGC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAEzC,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,WAAW,EACXC,aAAa,EACbC,YAAY,EACZ;IACA,IAAIC;IAEJ,8CAA8C;IAC9C,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,EAAE"}
1
+ {"version":3,"sources":["../../src/utilities/updateProfile.ts"],"sourcesContent":["import { GET_REGISTRY_CMD, formatRegistries } from \"./common.js\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport { run } from \"@node-cli/run\";\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\n\t\t\t * global 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":["GET_REGISTRY_CMD","formatRegistries","Logger","fs","kleur","run","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,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAc;AAEjE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,OAAO,MAAMC,gBAAgB,OAAO,EACnCC,KAAK,EACLC,WAAW,EACXC,aAAa,EACbC,YAAY,EACZ;IACA,MAAMC,SAAS,IAAIT,OAAO;QACzBU,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAUR,MAAMK,MAAM;IACxD;IAEA,IAAII;IAEJ,8CAA8C;IAC9C,IAAI;QACHA,WAAW,MAAMb,GAAGc,QAAQ,CAACT;IAC9B,EAAE,OAAM;IACP,uDAAuD;IACxD;IAEA,IAAIQ,UAAUE,WAAWC,SAAS,GAAG;QACpC,MAAMC,cAAcJ,SAASK,OAAO;QACpC,IAAID,aAAa;YAChB,MAAME,WAAW;gBAAClB,MAAMmB,KAAK,CAAC,CAAC,SAAS,EAAEH,YAAY,SAAS,CAAC;aAAE;YAClE;;;IAGC,GACD,MAAM,EAAEI,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMpB,IAAIL,kBAAkB;gBACtD0B,aAAa;YACd;YACA,IAAI,CAACD,QAAQ;gBACZH,SAASK,IAAI,IAAI1B,iBAAiBuB;YACnC;YAEA,oCAAoC;YACpC,MAAMrB,GAAGyB,SAAS,CAAC,CAAC,EAAEnB,cAAc,CAAC,EAAEW,YAAY,CAAC;YACpD,+DAA+D;YAC/D,MAAMS,QAAQ,CAAC,EAAEnB,aAAa,OAAO,CAAC;YACtC,MAAMoB,SAAS,CAAC,EAAEpB,aAAa,QAAQ,CAAC;YACxC,IAAI,MAAMP,GAAG4B,UAAU,CAACD,SAAS;gBAChC,MAAM3B,GAAG6B,IAAI,CAACF,QAAQ,CAAC,EAAErB,cAAc,CAAC,EAAEW,YAAY,OAAO,CAAC;YAC/D;YACA,IAAI,MAAMjB,GAAG4B,UAAU,CAACF,QAAQ;gBAC/B,MAAM1B,GAAG6B,IAAI,CAACH,OAAO,CAAC,EAAEpB,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.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "Toggle different npmrc configuration files on the fly",
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "b9504f158921ee87ce690cbd42ab2806913d6e8f"
37
+ "gitHead": "fc524a6f6f4de9e52ab5a86cf696ccb961164176"
38
38
  }