@node-cli/npmrc 1.0.1 → 1.1.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/README.md CHANGED
@@ -12,25 +12,31 @@
12
12
 
13
13
  ## Examples
14
14
 
15
- List existing profiles
15
+ Create a profile from the current .npmrc file
16
+
17
+ ```sh
18
+ > npmrc -c my-profile
19
+ ```
20
+
21
+ List profiles handled by npmrc
16
22
 
17
23
  ```sh
18
24
  > npmrc -l
19
25
  ```
20
26
 
21
- Create a profile
27
+ Update an existing profile with the current .npmrc file
22
28
 
23
29
  ```sh
24
- > npmrc -c my-profile
30
+ > npmrc -u
25
31
  ```
26
32
 
27
- Switch to an existing profile
33
+ Switch to an existing profile handled by npmrc
28
34
 
29
35
  ```sh
30
36
  > npmrc my-profile
31
37
  ```
32
38
 
33
- Delete a profile
39
+ Delete a profile handled by npmrc
34
40
 
35
41
  ```sh
36
42
  > npmrc -d my-profile
package/dist/index.d.ts CHANGED
@@ -5,4 +5,8 @@
5
5
  export * from "./defaults";
6
6
  export * from "./npmrc";
7
7
  export * from "./parse";
8
- export * from "./utilities";
8
+ export * from "./utilities/createProfile";
9
+ export * from "./utilities/deleteProfile";
10
+ export * from "./utilities/listProfiles";
11
+ export * from "./utilities/switchProfile";
12
+ export * from "./utilities/updateProfile";
package/dist/npmrc.js CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env node
2
- /* istanbul ignore file */ import { createProfile, deleteProfile, listProfiles, switchProfile } from "./utilities.js";
3
- import { config } from "./parse.js";
2
+ /* istanbul ignore file */ import { config } from "./parse.js";
3
+ import { createProfile } from "./utilities/createProfile.js";
4
+ import { deleteProfile } from "./utilities/deleteProfile.js";
5
+ import { listProfiles } from "./utilities/listProfiles.js";
4
6
  import path from "node:path";
7
+ import { switchProfile } from "./utilities/switchProfile.js";
8
+ import { updateProfile } from "./utilities/updateProfile.js";
5
9
  const HOME = process.env.HOME;
6
10
  const NPMRC_STORE = path.join(HOME, ".envtools/npmrcs");
7
11
  const NPMRC_STORE_CONFIG = path.join(HOME, "/.envtools/npmrcs.json");
@@ -15,6 +19,14 @@ if (flags.create && parameters !== undefined) {
15
19
  });
16
20
  process.exit(exitFlag);
17
21
  }
22
+ if (flags.update && parameters !== undefined) {
23
+ const exitFlag = await updateProfile({
24
+ storeConfig: NPMRC_STORE_CONFIG,
25
+ storeLocation: NPMRC_STORE,
26
+ homeLocation: HOME
27
+ });
28
+ process.exit(exitFlag);
29
+ }
18
30
  if (flags.delete && parameters !== undefined) {
19
31
  const exitFlag = await deleteProfile({
20
32
  flags,
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 {\n\tcreateProfile,\n\tdeleteProfile,\n\tlistProfiles,\n\tswitchProfile,\n} from \"./utilities.js\";\n\nimport { config } from \"./parse.js\";\nimport path from \"node:path\";\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.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":["createProfile","deleteProfile","listProfiles","switchProfile","config","path","HOME","process","env","NPMRC_STORE","join","NPMRC_STORE_CONFIG","parameters","flags","showHelp","create","undefined","exitFlag","storeConfig","storeLocation","profileName","homeLocation","exit","delete","list","version","help"],"mappings":";AACA,wBAAwB,GAExB,SACCA,aAAa,EACbC,aAAa,EACbC,YAAY,EACZC,aAAa,QACP,iBAAiB;AAExB,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,UAAU,YAAY;AAE7B,MAAMC,OAAOC,QAAQC,GAAG,CAACF,IAAI;AAC7B,MAAMG,cAAcJ,KAAKK,IAAI,CAACJ,MAAM;AACpC,MAAMK,qBAAqBN,KAAKK,IAAI,CAACJ,MAAM;AAE3C,MAAM,EAAEM,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGV;AAExC,IAAIS,MAAME,MAAM,IAAIH,eAAeI,WAAW;IAC7C,MAAMC,WAAW,MAAMjB,cAAc;QACpCkB,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,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,MAAMd,cAAc;QACpCU;QACAK,aAAaP;QACbQ,eAAeV;QACfW,aAAaR,UAAU,CAAC,IAAI;QAC5BS,cAAcf;IACf;IACAC,QAAQe,IAAI,CAACL;AACd;AAEA,IAAIJ,MAAMW,IAAI,IAAK,CAACX,MAAMY,OAAO,IAAI,CAACZ,MAAMa,IAAI,EAAG;IAClD,MAAMT,WAAW,MAAMf,aAAa;QACnCW;QACAK,aAAaP;IACd;IACAJ,QAAQe,IAAI,CAACL;AACd;AAEAH"}
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+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;QACpCkB,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;QACpCa,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"}
package/dist/parse.d.ts CHANGED
@@ -6,6 +6,7 @@ export type Flags = {
6
6
  delete?: boolean;
7
7
  create?: boolean;
8
8
  list?: boolean;
9
+ update?: boolean;
9
10
  boring?: boolean;
10
11
  help?: boolean;
11
12
  version?: boolean;
package/dist/parse.js CHANGED
@@ -41,6 +41,11 @@ import { parser } from "@node-cli/parser";
41
41
  description: "List all profiles",
42
42
  type: "boolean"
43
43
  },
44
+ update: {
45
+ shortFlag: "u",
46
+ description: "Update the current profile",
47
+ type: "boolean"
48
+ },
44
49
  boring: {
45
50
  shortFlag: "b",
46
51
  default: defaultFlags.boring,
package/dist/parse.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { defaultFlags } from \"./defaults.js\";\nimport { parser } from \"@node-cli/parser\";\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\tboring?: boolean;\n\thelp?: boolean;\n\tversion?: boolean;\n};\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n\tshowHelp?: () => void;\n};\n\n/* istanbul ignore next */\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\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"],"names":["defaultFlags","parser","config","meta","examples","command","comment","flags","verbose","shortFlag","description","type","delete","create","list","boring","default","help","version","parameters","profile","restrictions","exit","message","test","usage"],"mappings":"AAAA,SAASA,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,MAAM,QAAQ,mBAAmB;AAoB1C,wBAAwB,GACxB,OAAO,MAAMC,SAAwBD,OAAO;IAC3CE,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;YACXO,SAAShB,aAAae,MAAM;YAC5BL,aAAa;YACbC,MAAM;QACP;QACAM,MAAM;YACLR,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAO,SAAS;YACRT,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;IACD;IACAQ,YAAY;QACXC,SAAS;YACRV,aAAa;QACd;IACD;IACAW,cAAc;QACb;YACCC,MAAM;YACNC,SAAS;YACTC,MAAM,CAACjB,OAAeY;gBACrB,OAAOZ,MAAMM,MAAM,IAAK,CAAA,CAACM,cAAc,CAACA,UAAU,CAAC,IAAI,AAAD;YACvD;QACD;KACA;IACDM,OAAO;AACR,GAAG"}
1
+ {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { defaultFlags } from \"./defaults.js\";\nimport { parser } from \"@node-cli/parser\";\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/* istanbul ignore next */\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"],"names":["defaultFlags","parser","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,SAASA,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,MAAM,QAAQ,mBAAmB;AAqB1C,wBAAwB,GACxB,OAAO,MAAMC,SAAwBD,OAAO;IAC3CE,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,SAASjB,aAAagB,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"}
@@ -0,0 +1,8 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ export declare const logger: Logger;
3
+ export declare const createProfile: ({ storeConfig, storeLocation, profileName, homeLocation, }: {
4
+ storeConfig: any;
5
+ storeLocation: any;
6
+ profileName: any;
7
+ homeLocation: any;
8
+ }) => Promise<number>;
@@ -0,0 +1,54 @@
1
+ import { Logger } from "@node-cli/logger";
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 })=>{
6
+ let profiles = {
7
+ available: [],
8
+ enabled: undefined
9
+ };
10
+ await fs.ensureFile(storeConfig);
11
+ try {
12
+ // if the profile already exists, do nothing
13
+ profiles = await fs.readJson(storeConfig);
14
+ if (profiles.available.includes(profileName)) {
15
+ logger.warn(`Profile '${profileName}' already exists...`);
16
+ return 0;
17
+ }
18
+ } catch {
19
+ // ignoring error since we are going to create the file
20
+ }
21
+ /**
22
+ * If the profile does not exist, create a folder named as
23
+ * the profile under the storeLocation folder, with the
24
+ * existing npmrc / yarnrc files.
25
+ */ await fs.ensureDir(`${storeLocation}/${profileName}`);
26
+ // copy the existing npmrc / yarnrc files to the new folder
27
+ const NPMRC = `${homeLocation}/.npmrc`;
28
+ const YARNRC = `${homeLocation}/.yarnrc`;
29
+ if (await fs.pathExists(YARNRC)) {
30
+ await fs.copy(YARNRC, `${storeLocation}/${profileName}/yarnrc`);
31
+ }
32
+ if (await fs.pathExists(NPMRC)) {
33
+ await fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);
34
+ }
35
+ // then add the profile to the configuration file
36
+ const newProfiles = {
37
+ available: [
38
+ ...profiles.available,
39
+ profileName
40
+ ],
41
+ enabled: profiles.enabled ?? profileName
42
+ };
43
+ await fs.writeJson(storeConfig, newProfiles, {
44
+ spaces: 2
45
+ });
46
+ logger.printBox(`Profile '${profileName}' created`, {
47
+ textAlignment: "left",
48
+ title: "Profiles",
49
+ borderColor: "blue"
50
+ });
51
+ return 0;
52
+ };
53
+
54
+ //# sourceMappingURL=createProfile.js.map
@@ -0,0 +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"}
@@ -0,0 +1,8 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ export declare const logger: Logger;
3
+ export declare const deleteProfile: ({ flags, profileName, storeConfig, storeLocation, }: {
4
+ flags: any;
5
+ profileName: any;
6
+ storeConfig: any;
7
+ storeLocation: any;
8
+ }) => Promise<1 | 0>;
@@ -0,0 +1,42 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ import fs from "fs-extra";
3
+ export const logger = new Logger();
4
+ logger.boring = process.env.NODE_ENV === "test";
5
+ export const deleteProfile = async ({ flags, profileName, storeConfig, storeLocation })=>{
6
+ try {
7
+ const profiles = await fs.readJson(storeConfig);
8
+ if (!profiles.available.includes(profileName)) {
9
+ logger.error(`Profile '${profileName}' does not exist`);
10
+ return 1;
11
+ }
12
+ // if the profile is enabled, do nothing
13
+ if (profiles.enabled === profileName) {
14
+ logger.error(`Profile '${profileName}' is currently active`);
15
+ return 1;
16
+ }
17
+ // if profile exists, delete it by removing the profile folder
18
+ await fs.remove(`${storeLocation}/${profileName}`);
19
+ // then remove the profile from the configuration file
20
+ const newProfiles = {
21
+ available: profiles.available.filter((profile)=>profile !== profileName),
22
+ enabled: profiles.enabled
23
+ };
24
+ await fs.writeJson(storeConfig, newProfiles, {
25
+ spaces: 2
26
+ });
27
+ logger.printBox(`Profile '${profileName}' deleted`, {
28
+ textAlignment: "left",
29
+ title: "Profiles",
30
+ borderColor: "blue"
31
+ });
32
+ return 0;
33
+ } catch (error) {
34
+ if (flags.verbose) {
35
+ logger.log(error);
36
+ }
37
+ logger.error("Could not delete profile");
38
+ return 1;
39
+ }
40
+ };
41
+
42
+ //# sourceMappingURL=deleteProfile.js.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ export declare const logger: Logger;
3
+ export declare const listProfiles: ({ flags, storeConfig }: {
4
+ flags: any;
5
+ storeConfig: any;
6
+ }) => Promise<1 | 0>;
@@ -0,0 +1,50 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ import fs from "fs-extra";
3
+ import kleur from "kleur";
4
+ import { run } from "@node-cli/run";
5
+ export const logger = new Logger();
6
+ logger.boring = process.env.NODE_ENV === "test";
7
+ export const listProfiles = async ({ flags, storeConfig })=>{
8
+ try {
9
+ const profiles = await fs.readJson(storeConfig);
10
+ if (profiles?.available?.length > 0) {
11
+ const activeProfile = profiles.enabled;
12
+ const messages = activeProfile === undefined ? [] : [
13
+ kleur.green(`★ ${activeProfile} (active)`)
14
+ ];
15
+ /**
16
+ * Since there is an active profile, we can check the
17
+ * global registry and list it, alongside the active profile.
18
+ */ if (activeProfile) {
19
+ const { stdout, stderr } = await run('npm config list -l -g | grep "registry ="', {
20
+ ignoreError: true
21
+ });
22
+ if (!stderr) {
23
+ const stdoutArray = stdout.split("\n").map((line)=>kleur.grey(` • ${line}`));
24
+ messages.push(...stdoutArray);
25
+ }
26
+ }
27
+ for (const profile of profiles.available){
28
+ if (profile !== activeProfile) {
29
+ messages.push(`${profile}`);
30
+ }
31
+ }
32
+ logger.printBox(messages.join("\n"), {
33
+ textAlignment: "left",
34
+ title: "Profiles",
35
+ borderColor: "blue"
36
+ });
37
+ } else {
38
+ logger.warn("No profiles found");
39
+ }
40
+ return 0;
41
+ } catch (error) {
42
+ if (flags.verbose) {
43
+ logger.log(error);
44
+ }
45
+ logger.error("Unable to read the profile configuration file");
46
+ return 1;
47
+ }
48
+ };
49
+
50
+ //# sourceMappingURL=listProfiles.js.map
@@ -0,0 +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"}
@@ -0,0 +1,9 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ export declare const logger: Logger;
3
+ export declare const switchProfile: ({ flags, storeConfig, storeLocation, profileName, homeLocation, }: {
4
+ flags: any;
5
+ storeConfig: any;
6
+ storeLocation: any;
7
+ profileName: any;
8
+ homeLocation: any;
9
+ }) => Promise<1 | 0>;
@@ -0,0 +1,59 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ import fs from "fs-extra";
3
+ export const logger = new Logger();
4
+ logger.boring = process.env.NODE_ENV === "test";
5
+ export const switchProfile = async ({ flags, storeConfig, storeLocation, profileName, homeLocation })=>{
6
+ try {
7
+ const profiles = await fs.readJson(storeConfig);
8
+ if (!profiles.available.includes(profileName)) {
9
+ logger.error(`Profile '${profileName}' does not exist`);
10
+ return 1;
11
+ }
12
+ // if profile is already enabled, do nothing
13
+ if (profiles.enabled === profileName) {
14
+ logger.warn(`Profile '${profileName}' is already active`);
15
+ return 0;
16
+ }
17
+ // if profile exists and is not enabled, switch to it by copying
18
+ // the npmrc and yarnrc files from the profile folder to the home folder
19
+ const NPMRC = `${homeLocation}/.npmrc`;
20
+ const PROFILE_NPMRC = `${storeLocation}/${profileName}/npmrc`;
21
+ const YARNRC = `${homeLocation}/.yarnrc`;
22
+ const PROFILE_YARNRC = `${storeLocation}/${profileName}/yarnrc`;
23
+ if (await fs.pathExists(PROFILE_NPMRC)) {
24
+ await fs.copy(PROFILE_NPMRC, NPMRC, {
25
+ overwrite: true
26
+ });
27
+ } else {
28
+ logger.warn(`No npmrc file found for profile '${profileName}'`);
29
+ }
30
+ if (await fs.pathExists(PROFILE_YARNRC)) {
31
+ await fs.copy(PROFILE_YARNRC, YARNRC, {
32
+ overwrite: true
33
+ });
34
+ } else {
35
+ logger.warn(`No yarnrc file found for profile '${profileName}'`);
36
+ }
37
+ const newProfiles = {
38
+ available: profiles.available,
39
+ enabled: profileName
40
+ };
41
+ await fs.writeJson(storeConfig, newProfiles, {
42
+ spaces: 2
43
+ });
44
+ logger.printBox(`Profile switched to '${profileName}'`, {
45
+ textAlignment: "left",
46
+ title: "Profiles",
47
+ borderColor: "blue"
48
+ });
49
+ return 0;
50
+ } catch (error) {
51
+ if (flags.verbose) {
52
+ logger.log(error);
53
+ }
54
+ logger.error("Could not switch profile");
55
+ return 1;
56
+ }
57
+ };
58
+
59
+ //# sourceMappingURL=switchProfile.js.map
@@ -0,0 +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,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kC,EAAER,YAAY,CAAC,CAAC;QAChE;QAEA,MAAMgB,cAAc;YACnBZ,WAAWF,SAASE,SAAS;YAC7BG,SAASP;QACV;QACA,MAAMV,GAAG2B,SAAS,CAACnB,aAAakB,aAAa;YAAEE,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"}
@@ -0,0 +1,7 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ export declare const logger: Logger;
3
+ export declare const updateProfile: ({ storeConfig, storeLocation, homeLocation, }: {
4
+ storeConfig: any;
5
+ storeLocation: any;
6
+ homeLocation: any;
7
+ }) => Promise<number>;
@@ -0,0 +1,54 @@
1
+ import { Logger } from "@node-cli/logger";
2
+ import fs from "fs-extra";
3
+ import kleur from "kleur";
4
+ 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 })=>{
8
+ let profiles;
9
+ // Step 1: check if there is an active profile
10
+ try {
11
+ profiles = await fs.readJson(storeConfig);
12
+ } catch {
13
+ // ignoring error since we are going to create the file
14
+ }
15
+ if (profiles?.available?.length > 0) {
16
+ const profileName = profiles.enabled;
17
+ if (profileName) {
18
+ const messages = [
19
+ kleur.green(`Profile '${profileName}' updated`)
20
+ ];
21
+ /**
22
+ * 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
+ ignoreError: true
26
+ });
27
+ if (!stderr) {
28
+ const stdoutArray = stdout.split("\n").map((line)=>kleur.grey(` • ${line}`));
29
+ messages.push(...stdoutArray);
30
+ }
31
+ // Step 3: update the active profile
32
+ await fs.ensureDir(`${storeLocation}/${profileName}`);
33
+ // copy the existing npmrc / yarnrc files to the storage folder
34
+ const NPMRC = `${homeLocation}/.npmrc`;
35
+ const YARNRC = `${homeLocation}/.yarnrc`;
36
+ if (await fs.pathExists(YARNRC)) {
37
+ await fs.copy(YARNRC, `${storeLocation}/${profileName}/yarnrc`);
38
+ }
39
+ if (await fs.pathExists(NPMRC)) {
40
+ await fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);
41
+ }
42
+ logger.printBox(messages.join("\n"), {
43
+ textAlignment: "left",
44
+ title: "Profiles",
45
+ borderColor: "blue"
46
+ });
47
+ return 0;
48
+ }
49
+ }
50
+ logger.warn("Only active profiles can be updated. Please switch to the profile you want to update.");
51
+ return 0;
52
+ };
53
+
54
+ //# sourceMappingURL=updateProfile.js.map
@@ -0,0 +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,QAAQ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CAAChB,SAASiB,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;YACA,OAAO;QACR;IACD;IAEAnC,OAAOoC,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.0.1",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "Toggle different npmrc configuration files on the fly",
@@ -15,23 +15,24 @@
15
15
  "scripts": {
16
16
  "build": "npm-run-all --serial clean build:types build:js build:barrel",
17
17
  "build:barrel": "barrelsby --delete --directory dist --pattern \"**/*.d.ts\" --name \"index.d\"",
18
- "build:js": "swc --source-maps --out-dir dist src",
18
+ "build:js": "swc --strip-leading-paths --source-maps --out-dir dist src",
19
19
  "build:types": "tsc",
20
20
  "clean": "rimraf dist types coverage",
21
21
  "lint": "prettier --write \"src/*.ts\" && eslint --fix \"src/*.ts\"",
22
22
  "test": "cross-env-shell NODE_OPTIONS=--experimental-vm-modules TZ=UTC jest",
23
23
  "test:coverage": "npm run test -- --coverage",
24
24
  "test:watch": "npm run test -- --watch",
25
- "watch": "swc --watch --out-dir dist src"
25
+ "watch": "swc --strip-leading-paths --watch --out-dir dist src"
26
26
  },
27
27
  "dependencies": {
28
- "@node-cli/logger": ">=1.2.2",
29
- "@node-cli/parser": ">=2.2.3",
28
+ "@node-cli/logger": "1.2.3",
29
+ "@node-cli/parser": "2.3.2",
30
+ "@node-cli/run": "1.0.3",
30
31
  "fs-extra": "11.2.0",
31
32
  "kleur": "4.1.5"
32
33
  },
33
34
  "publishConfig": {
34
35
  "access": "public"
35
36
  },
36
- "gitHead": "89f454404477998ff3c7ee33a70468580705d494"
37
+ "gitHead": "b9504f158921ee87ce690cbd42ab2806913d6e8f"
37
38
  }
@@ -1,25 +0,0 @@
1
- import { Logger } from "@node-cli/logger";
2
- export declare const logger: Logger;
3
- export declare const listProfiles: ({ flags, storeConfig }: {
4
- flags: any;
5
- storeConfig: any;
6
- }) => Promise<0 | 1>;
7
- export declare const createProfile: ({ storeConfig, storeLocation, profileName, homeLocation, }: {
8
- storeConfig: any;
9
- storeLocation: any;
10
- profileName: any;
11
- homeLocation: any;
12
- }) => Promise<number>;
13
- export declare const switchProfile: ({ flags, storeConfig, storeLocation, profileName, homeLocation, }: {
14
- flags: any;
15
- storeConfig: any;
16
- storeLocation: any;
17
- profileName: any;
18
- homeLocation: any;
19
- }) => Promise<0 | 1>;
20
- export declare const deleteProfile: ({ flags, profileName, storeConfig, storeLocation, }: {
21
- flags: any;
22
- profileName: any;
23
- storeConfig: any;
24
- storeLocation: any;
25
- }) => Promise<0 | 1>;
package/dist/utilities.js DELETED
@@ -1,173 +0,0 @@
1
- import { Logger } from "@node-cli/logger";
2
- import fs from "fs-extra";
3
- import kleur from "kleur";
4
- export const logger = new Logger();
5
- logger.boring = process.env.NODE_ENV === "test";
6
- export const listProfiles = async ({ flags, storeConfig })=>{
7
- try {
8
- const profiles = await fs.readJson(storeConfig);
9
- if (profiles?.available?.length > 0) {
10
- const activeProfile = profiles.enabled;
11
- const messages = activeProfile === undefined ? [] : [
12
- kleur.green(`★ ${activeProfile} (active)`)
13
- ];
14
- for (const profile of profiles.available){
15
- if (profile !== activeProfile) {
16
- messages.push(`${profile}`);
17
- }
18
- }
19
- logger.printBox(messages.join("\n"), {
20
- textAlignment: "left",
21
- title: "Profiles",
22
- borderColor: "blue"
23
- });
24
- } else {
25
- logger.warn("No profiles found");
26
- }
27
- return 0;
28
- } catch (error) {
29
- if (flags.verbose) {
30
- logger.log(error);
31
- }
32
- logger.error("Unable to read the profile configuration file");
33
- return 1;
34
- }
35
- };
36
- export const createProfile = async ({ storeConfig, storeLocation, profileName, homeLocation })=>{
37
- let profiles = {
38
- available: [],
39
- enabled: undefined
40
- };
41
- await fs.ensureFile(storeConfig);
42
- try {
43
- // if the profile already exists, do nothing
44
- profiles = await fs.readJson(storeConfig);
45
- if (profiles.available.includes(profileName)) {
46
- logger.warn(`Profile '${profileName}' already exists...`);
47
- return 0;
48
- }
49
- } catch {
50
- // ignoring error since we are creating the file
51
- }
52
- // if the profile does not exist, create
53
- // a folder named as the profile under the storeLocation folder,
54
- // with the existing npmrc / yarnrc files
55
- await fs.ensureDir(`${storeLocation}/${profileName}`);
56
- // copy the existing npmrc / yarnrc files to the new folder
57
- const NPMRC = `${homeLocation}/.npmrc`;
58
- const YARNRC = `${homeLocation}/.yarnrc`;
59
- if (await fs.pathExists(YARNRC)) {
60
- await fs.copy(YARNRC, `${storeLocation}/${profileName}/yarnrc`);
61
- }
62
- if (await fs.pathExists(NPMRC)) {
63
- await fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);
64
- }
65
- // then add the profile to the configuration file
66
- const newProfiles = {
67
- available: [
68
- ...profiles.available,
69
- profileName
70
- ],
71
- enabled: profiles.enabled ?? profileName
72
- };
73
- await fs.writeJson(storeConfig, newProfiles, {
74
- spaces: 2
75
- });
76
- logger.printBox(`Profile '${profileName}' created`, {
77
- textAlignment: "left",
78
- title: "Profiles",
79
- borderColor: "blue"
80
- });
81
- return 0;
82
- };
83
- export const switchProfile = async ({ flags, storeConfig, storeLocation, profileName, homeLocation })=>{
84
- try {
85
- const profiles = await fs.readJson(storeConfig);
86
- if (!profiles.available.includes(profileName)) {
87
- logger.error(`Profile '${profileName}' does not exist`);
88
- return 1;
89
- }
90
- // if profile is already enabled, do nothing
91
- if (profiles.enabled === profileName) {
92
- logger.warn(`Profile '${profileName}' is already active`);
93
- return 0;
94
- }
95
- // if profile exists and is not enabled, switch to it by copying
96
- // the npmrc and yarnrc files from the profile folder to the home folder
97
- const NPMRC = `${homeLocation}/.npmrc`;
98
- const PROFILE_NPMRC = `${storeLocation}/${profileName}/npmrc`;
99
- const YARNRC = `${homeLocation}/.yarnrc`;
100
- const PROFILE_YARNRC = `${storeLocation}/${profileName}/yarnrc`;
101
- if (await fs.pathExists(PROFILE_NPMRC)) {
102
- await fs.copy(PROFILE_NPMRC, NPMRC, {
103
- overwrite: true
104
- });
105
- } else {
106
- logger.warn(`No npmrc file found for profile '${profileName}'`);
107
- }
108
- if (await fs.pathExists(PROFILE_YARNRC)) {
109
- await fs.copy(PROFILE_YARNRC, YARNRC, {
110
- overwrite: true
111
- });
112
- } else {
113
- logger.warn(`No yarnrc file found for profile '${profileName}'`);
114
- }
115
- const newProfiles = {
116
- available: profiles.available,
117
- enabled: profileName
118
- };
119
- await fs.writeJson(storeConfig, newProfiles, {
120
- spaces: 2
121
- });
122
- logger.printBox(`Profile switched to '${profileName}'`, {
123
- textAlignment: "left",
124
- title: "Profiles",
125
- borderColor: "blue"
126
- });
127
- return 0;
128
- } catch (error) {
129
- if (flags.verbose) {
130
- logger.log(error);
131
- }
132
- logger.error("Could not switch profile");
133
- return 1;
134
- }
135
- };
136
- export const deleteProfile = async ({ flags, profileName, storeConfig, storeLocation })=>{
137
- try {
138
- const profiles = await fs.readJson(storeConfig);
139
- if (!profiles.available.includes(profileName)) {
140
- logger.error(`Profile '${profileName}' does not exist`);
141
- return 1;
142
- }
143
- // if the profile is enabled, do nothing
144
- if (profiles.enabled === profileName) {
145
- logger.error(`Profile '${profileName}' is currently active`);
146
- return 1;
147
- }
148
- // if profile exists, delete it by removing the profile folder
149
- await fs.remove(`${storeLocation}/${profileName}`);
150
- // then remove the profile from the configuration file
151
- const newProfiles = {
152
- available: profiles.available.filter((profile)=>profile !== profileName),
153
- enabled: profiles.enabled
154
- };
155
- await fs.writeJson(storeConfig, newProfiles, {
156
- spaces: 2
157
- });
158
- logger.printBox(`Profile '${profileName}' deleted`, {
159
- textAlignment: "left",
160
- title: "Profiles",
161
- borderColor: "blue"
162
- });
163
- return 0;
164
- } catch (error) {
165
- if (flags.verbose) {
166
- logger.log(error);
167
- }
168
- logger.error("Could not delete profile");
169
- return 1;
170
- }
171
- };
172
-
173
- //# sourceMappingURL=utilities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport kleur from \"kleur\";\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\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\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 creating the file\n\t}\n\n\t// if the profile does not exist, create\n\t// a folder named as the profile under the storeLocation folder,\n\t// with the existing npmrc / yarnrc files\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\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\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","kleur","logger","boring","process","env","NODE_ENV","listProfiles","flags","storeConfig","profiles","readJson","available","length","activeProfile","enabled","messages","undefined","green","profile","push","printBox","join","textAlignment","title","borderColor","warn","error","verbose","log","createProfile","storeLocation","profileName","homeLocation","ensureFile","includes","ensureDir","NPMRC","YARNRC","pathExists","copy","newProfiles","writeJson","spaces","switchProfile","PROFILE_NPMRC","PROFILE_YARNRC","overwrite","deleteProfile","remove","filter"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,WAAW,QAAQ;AAE1B,OAAO,MAAMC,SAAS,IAAIH,SAAS;AACnCG,OAAOC,MAAM,GAAGC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAEzC,OAAO,MAAMC,eAAe,OAAO,EAAEC,KAAK,EAAEC,WAAW,EAAE;IACxD,IAAI;QACH,MAAMC,WAAW,MAAMV,GAAGW,QAAQ,CAACF;QAEnC,IAAIC,UAAUE,WAAWC,SAAS,GAAG;YACpC,MAAMC,gBAAgBJ,SAASK,OAAO;YACtC,MAAMC,WACLF,kBAAkBG,YACf,EAAE,GACF;gBAAChB,MAAMiB,KAAK,CAAC,CAAC,EAAE,EAAEJ,cAAc,SAAS,CAAC;aAAE;YAEhD,KAAK,MAAMK,WAAWT,SAASE,SAAS,CAAE;gBACzC,IAAIO,YAAYL,eAAe;oBAC9BE,SAASI,IAAI,CAAC,CAAC,EAAED,QAAQ,CAAC;gBAC3B;YACD;YAEAjB,OAAOmB,QAAQ,CAACL,SAASM,IAAI,CAAC,OAAO;gBACpCC,eAAe;gBACfC,OAAO;gBACPC,aAAa;YACd;QACD,OAAO;YACNvB,OAAOwB,IAAI,CAAC;QACb;QACA,OAAO;IACR,EAAE,OAAOC,OAAO;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