-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-fflib.mjs
101 lines (92 loc) · 2.48 KB
/
setup-fflib.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import fs from "fs";
import childProcess from "child_process";
// run via `node --harmony setup-fflib.mjs e- ORG_ALIAS`
const REPOS = [
{
git: "https://github.com/apex-enterprise-patterns/fflib-apex-common",
source: "fflib-apex-common",
deployPath: "sfdx-source"
},
{
git: "https://github.com/apex-enterprise-patterns/fflib-apex-mocks",
source: "fflib-apex-mocks",
deployPath: "sfdx-source"
},
{
git: "https://github.com/apex-enterprise-patterns/force-di",
source: "force-di",
deployPath: "force-di"
},
{
git: "https://github.com/apex-enterprise-patterns/at4dx",
source: "at4dx",
deployPath: "sfdx-source"
}
];
const execute = async (command) => {
return new Promise(async (resolve, reject) => {
try {
resolve(childProcess.execSync(command, { stdio: "inherit" }));
} catch (error) {
reject(error);
}
});
};
const cloneAndDeployToOrg = async (orgAlias) => {
const foldersToDeploy = [];
await Promise.all(
REPOS.map(async (item) => {
const { source, git } = item;
if (fs.existsSync(`./${source}`)) {
console.warn("\x1b[33m%s\x1b[0m ", `${source} already exists.`);
} else {
console.warn("\x1b[32m%s\x1b[0m ", `Cloning ${source} from ${git}`);
foldersToDeploy.push(item);
return execute(`git clone ${git} ${source}`);
}
})
);
if (foldersToDeploy.length > 0) {
console.log(
"Deploying ",
foldersToDeploy.map((item) => item.source)
);
await Promise.all(
foldersToDeploy.map(async ({ source, deployPath }) => {
console.warn(
"\x1b[32m%s\x1b[0m ",
`\nDeploying metadata ${source} to org.`
);
return execute(
`sfdx force:source:deploy -p "./${source}/${deployPath}" -u ${orgAlias}`
);
})
);
console.log(`\nSuccessfully installed fflib into org ${orgAlias}\n`);
} else {
console.log(
"\x1b[32m%s\x1b[0m ",
"\nNo new folders cloned, no metadata updated"
);
}
};
const getArgs = () =>
process.argv.slice(2, process.argv.length).reduce((acc, arg, key) => {
// flags
if (arg[0] === "-") {
const flags = arg.slice(1, arg.length).split("");
flags.forEach((flag) => {
acc[flag] = process.argv[key + 3];
});
}
return acc;
}, {});
const args = getArgs();
if (!args.e) {
console.error(
"\x1b[31m%s\x1b[0m ",
"Please provide org alias via the `-e` flag."
);
} else {
cloneAndDeployToOrg(args.e);
}