@node-cli/npmrc 1.1.0 → 1.1.1

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";
@@ -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,3 +1,4 @@
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";
@@ -14,14 +15,13 @@ export const listProfiles = async ({ flags, storeConfig })=>{
14
15
  ];
15
16
  /**
16
17
  * Since there is an active profile, we can check the
17
- * global registry and list it, alongside the active profile.
18
+ * global registries and list them, alongside the active profile.
18
19
  */ if (activeProfile) {
19
- const { stdout, stderr } = await run('npm config list -l -g | grep "registry ="', {
20
+ const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
20
21
  ignoreError: true
21
22
  });
22
23
  if (!stderr) {
23
- const stdoutArray = stdout.split("\n").map((line)=>kleur.grey(` • ${line}`));
24
- messages.push(...stdoutArray);
24
+ messages.push(...formatRegistries(stdout));
25
25
  }
26
26
  }
27
27
  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 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 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","logger","boring","process","env","NODE_ENV","listProfiles","flags","storeConfig","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,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,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;YAEArB,OAAOsB,QAAQ,CAACR,SAASS,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;QACD,OAAO;YACN1B,OAAO2B,IAAI,CAAC;QACb;QACA,OAAO;IACR,EAAE,OAAOC,OAAO;QACf,IAAItB,MAAMuB,OAAO,EAAE;YAClB7B,OAAO8B,GAAG,CAACF;QACZ;QACA5B,OAAO4B,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
@@ -1,3 +1,4 @@
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";
@@ -20,13 +21,12 @@ export const updateProfile = async ({ storeConfig, storeLocation, homeLocation }
20
21
  ];
21
22
  /**
22
23
  * 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 ="', {
24
+ * global registries and list them, alongside the updated profile.
25
+ */ const { stdout, stderr } = await run(GET_REGISTRY_CMD, {
25
26
  ignoreError: true
26
27
  });
27
28
  if (!stderr) {
28
- const stdoutArray = stdout.split("\n").map((line)=>kleur.grey(` • ${line}`));
29
- messages.push(...stdoutArray);
29
+ messages.push(...formatRegistries(stdout));
30
30
  }
31
31
  // Step 3: update the active profile
32
32
  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,IAAI;QACHA,WAAW,MAAMZ,GAAGa,QAAQ,CAACJ;IAC9B,EAAE,OAAM;IACP,uDAAuD;IACxD;IAEA,IAAIG,UAAUE,WAAWC,SAAS,GAAG;QACpC,MAAMC,cAAcJ,SAASK,OAAO;QACpC,IAAID,aAAa;YAChB,MAAME,WAAW;gBAACjB,MAAMkB,KAAK,CAAC,CAAC,SAAS,EAAEH,YAAY,SAAS,CAAC;aAAE;YAClE;;;IAGC,GAED,MAAM,EAAEI,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMnB,IAChC,6CACA;gBACCoB,aAAa;YACd;YAED,IAAI,CAACD,QAAQ;gBACZ,MAAME,cAAc,AAACH,OACnBI,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASzB,MAAM0B,IAAI,CAAC,CAAC,KAAK,EAAED,KAAK,CAAC;gBACzCR,SAASU,IAAI,IAAIL;YAClB;YAEA,oCAAoC;YACpC,MAAMvB,GAAG6B,SAAS,CAAC,CAAC,EAAEnB,cAAc,CAAC,EAAEM,YAAY,CAAC;YACpD,+DAA+D;YAC/D,MAAMc,QAAQ,CAAC,EAAEnB,aAAa,OAAO,CAAC;YACtC,MAAMoB,SAAS,CAAC,EAAEpB,aAAa,QAAQ,CAAC;YACxC,IAAI,MAAMX,GAAGgC,UAAU,CAACD,SAAS;gBAChC,MAAM/B,GAAGiC,IAAI,CAACF,QAAQ,CAAC,EAAErB,cAAc,CAAC,EAAEM,YAAY,OAAO,CAAC;YAC/D;YACA,IAAI,MAAMhB,GAAGgC,UAAU,CAACF,QAAQ;gBAC/B,MAAM9B,GAAGiC,IAAI,CAACH,OAAO,CAAC,EAAEpB,cAAc,CAAC,EAAEM,YAAY,MAAM,CAAC;YAC7D;YACAb,OAAO+B,QAAQ,CAAChB,SAASiB,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;YACA,OAAO;QACR;IACD;IAEAnC,OAAOoC,IAAI,CACV;IAED,OAAO;AACR,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 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 registries and list them, alongside the updated profile.\n\t\t\t */\n\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","logger","boring","process","env","NODE_ENV","updateProfile","storeConfig","storeLocation","homeLocation","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,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,IAAI;QACHA,WAAW,MAAMZ,GAAGa,QAAQ,CAACJ;IAC9B,EAAE,OAAM;IACP,uDAAuD;IACxD;IAEA,IAAIG,UAAUE,WAAWC,SAAS,GAAG;QACpC,MAAMC,cAAcJ,SAASK,OAAO;QACpC,IAAID,aAAa;YAChB,MAAME,WAAW;gBAACjB,MAAMkB,KAAK,CAAC,CAAC,SAAS,EAAEH,YAAY,SAAS,CAAC;aAAE;YAClE;;;IAGC,GAED,MAAM,EAAEI,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMnB,IAAIL,kBAAkB;gBACtDyB,aAAa;YACd;YACA,IAAI,CAACD,QAAQ;gBACZH,SAASK,IAAI,IAAIzB,iBAAiBsB;YACnC;YAEA,oCAAoC;YACpC,MAAMpB,GAAGwB,SAAS,CAAC,CAAC,EAAEd,cAAc,CAAC,EAAEM,YAAY,CAAC;YACpD,+DAA+D;YAC/D,MAAMS,QAAQ,CAAC,EAAEd,aAAa,OAAO,CAAC;YACtC,MAAMe,SAAS,CAAC,EAAEf,aAAa,QAAQ,CAAC;YACxC,IAAI,MAAMX,GAAG2B,UAAU,CAACD,SAAS;gBAChC,MAAM1B,GAAG4B,IAAI,CAACF,QAAQ,CAAC,EAAEhB,cAAc,CAAC,EAAEM,YAAY,OAAO,CAAC;YAC/D;YACA,IAAI,MAAMhB,GAAG2B,UAAU,CAACF,QAAQ;gBAC/B,MAAMzB,GAAG4B,IAAI,CAACH,OAAO,CAAC,EAAEf,cAAc,CAAC,EAAEM,YAAY,MAAM,CAAC;YAC7D;YACAb,OAAO0B,QAAQ,CAACX,SAASY,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;YACA,OAAO;QACR;IACD;IAEA9B,OAAO+B,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.1.1",
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": "bf18648501bcd42db9e2a44793d53a1ef21d8c2d"
38
38
  }