@node-cli/npmrc 0.0.0 → 1.0.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/npmrc.js +0 -1
- package/dist/npmrc.js.map +1 -1
- package/dist/utilities.d.ts +2 -3
- package/dist/utilities.js +39 -38
- package/dist/utilities.js.map +1 -1
- package/package.json +2 -2
package/dist/npmrc.js
CHANGED
|
@@ -8,7 +8,6 @@ const NPMRC_STORE_CONFIG = path.join(HOME, "/.envtools/npmrcs.json");
|
|
|
8
8
|
const { parameters, flags, showHelp } = config;
|
|
9
9
|
if (flags.create && parameters !== undefined) {
|
|
10
10
|
const exitFlag = await createProfile({
|
|
11
|
-
flags,
|
|
12
11
|
storeConfig: NPMRC_STORE_CONFIG,
|
|
13
12
|
storeLocation: NPMRC_STORE,
|
|
14
13
|
profileName: parameters["0"],
|
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\
|
|
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"}
|
package/dist/utilities.d.ts
CHANGED
|
@@ -4,13 +4,12 @@ export declare const listProfiles: ({ flags, storeConfig }: {
|
|
|
4
4
|
flags: any;
|
|
5
5
|
storeConfig: any;
|
|
6
6
|
}) => Promise<0 | 1>;
|
|
7
|
-
export declare const createProfile: ({
|
|
8
|
-
flags: any;
|
|
7
|
+
export declare const createProfile: ({ storeConfig, storeLocation, profileName, homeLocation, }: {
|
|
9
8
|
storeConfig: any;
|
|
10
9
|
storeLocation: any;
|
|
11
10
|
profileName: any;
|
|
12
11
|
homeLocation: any;
|
|
13
|
-
}) => Promise<
|
|
12
|
+
}) => Promise<number>;
|
|
14
13
|
export declare const switchProfile: ({ flags, storeConfig, storeLocation, profileName, homeLocation, }: {
|
|
15
14
|
flags: any;
|
|
16
15
|
storeConfig: any;
|
package/dist/utilities.js
CHANGED
|
@@ -33,51 +33,52 @@ export const listProfiles = async ({ flags, storeConfig })=>{
|
|
|
33
33
|
return 1;
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
export const createProfile = async ({
|
|
36
|
+
export const createProfile = async ({ storeConfig, storeLocation, profileName, homeLocation })=>{
|
|
37
|
+
let profiles = {
|
|
38
|
+
available: [],
|
|
39
|
+
enabled: undefined
|
|
40
|
+
};
|
|
41
|
+
await fs.ensureFile(storeConfig);
|
|
37
42
|
try {
|
|
38
|
-
const profiles = await fs.readJson(storeConfig);
|
|
39
43
|
// if the profile already exists, do nothing
|
|
44
|
+
profiles = await fs.readJson(storeConfig);
|
|
40
45
|
if (profiles.available.includes(profileName)) {
|
|
41
46
|
logger.warn(`Profile '${profileName}' already exists...`);
|
|
42
47
|
return 0;
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
available: [
|
|
60
|
-
...profiles.available,
|
|
61
|
-
profileName
|
|
62
|
-
],
|
|
63
|
-
enabled: profiles.enabled
|
|
64
|
-
};
|
|
65
|
-
await fs.writeJson(storeConfig, newProfiles, {
|
|
66
|
-
spaces: 2
|
|
67
|
-
});
|
|
68
|
-
logger.printBox(`Profile '${profileName}' created`, {
|
|
69
|
-
textAlignment: "left",
|
|
70
|
-
title: "Profiles",
|
|
71
|
-
borderColor: "blue"
|
|
72
|
-
});
|
|
73
|
-
return 0;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (flags.verbose) {
|
|
76
|
-
logger.log(error);
|
|
77
|
-
}
|
|
78
|
-
logger.error("Could not create profile");
|
|
79
|
-
return 1;
|
|
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`);
|
|
80
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;
|
|
81
82
|
};
|
|
82
83
|
export const switchProfile = async ({ flags, storeConfig, storeLocation, profileName, homeLocation })=>{
|
|
83
84
|
try {
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\tflags,\n\tstoreConfig,\n\tstoreLocation,\n\tprofileName,\n\thomeLocation,\n}) => {\n\ttry {\n\t\tconst profiles = await fs.readJson(storeConfig);\n\t\t// if the profile already exists, do nothing\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\t// if the profile does not exist, create\n\t\t// a folder named as the profile under the storeLocation folder,\n\t\t// with the existing npmrc / yarnrc files\n\t\tawait fs.ensureDir(`${storeLocation}/${profileName}`);\n\t\t// copy the existing npmrc / yarnrc files to the new folder\n\t\tconst NPMRC = `${homeLocation}/.npmrc`;\n\t\tconst YARNRC = `${homeLocation}/.yarnrc`;\n\t\tif (await fs.pathExists(YARNRC)) {\n\t\t\tawait fs.copy(YARNRC, `${storeLocation}/${profileName}/yarnrc`);\n\t\t}\n\t\tif (await fs.pathExists(NPMRC)) {\n\t\t\tawait fs.copy(NPMRC, `${storeLocation}/${profileName}/npmrc`);\n\t\t}\n\t\t// then add the profile to the configuration file\n\t\tconst newProfiles = {\n\t\t\tavailable: [...profiles.available, profileName],\n\t\t\tenabled: profiles.enabled,\n\t\t};\n\t\tawait fs.writeJson(storeConfig, newProfiles, { spaces: 2 });\n\t\tlogger.printBox(`Profile '${profileName}' created`, {\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 create profile\");\n\t\treturn 1;\n\t}\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","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;QACf,IAAInB,M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;QAAE;QACzDxC,OAAOmB,QAAQ,CAAC,CAAC,SAAS,EAAEW,YAAY,SAAS,CAAC,EAAE;YACnDT,eAAe;YACfC,OAAO;YACPC,aAAa;QACd;QACA,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,IAAInB,MAAMoB,OAAO,EAAE;YAClB1B,OAAO2B,GAAG,CAACF;QACZ;QACAzB,OAAOyB,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
|
|
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,MAA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A,8DAA8D;QAC9D,MAAMhC,GAAGiD,MAAM,CAAC,CAAC,EAAElB,cAAc,CAAC,EAAEC,YAAY,CAAC;QACjD,sDAAsD;QACtD,MAAMS,cAAc;YACnB7B,WAAWF,SAASE,SAAS,CAACsC,MAAM,CACnC,CAAC/B,UAAiBA,YAAYa;YAE/BjB,SAASL,SAASK,OAAO;QAC1B;QACA,MAAMf,GAAG0C,SAAS,CAACjC,aAAagC,aAAa;YAAEE,QAAQ;QAAE;QACzDzC,OAAOmB,QAAQ,CAAC,CAAC,SAAS,EAAEW,YAAY,SAAS,CAAC,EAAE;YACnDT,eAAe;YACfC,OAAO;YACPC,aAAa;QACd;QACA,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,IAAInB,MAAMoB,OAAO,EAAE;YAClB1B,OAAO2B,GAAG,CAACF;QACZ;QACAzB,OAAOyB,KAAK,CAAC;QACb,OAAO;IACR;AACD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/npmrc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Toggle different npmrc configuration files on the fly",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "89f454404477998ff3c7ee33a70468580705d494"
|
|
37
37
|
}
|