-
Notifications
You must be signed in to change notification settings - Fork 2
/
archetypes.js
97 lines (75 loc) · 2.75 KB
/
archetypes.js
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
const sh = require('shelljs');
const replace = require("replace");
const REPO_TEMP_DIR = 'target';
const lg = console.log;
const pushArchetype = (repoUser, repoName, archetypeName, jenkinsfileCfg, projectName) => {
const PUSH_URL = `[email protected]:${repoUser}/${repoName}`
lg(`** Génération archetype ${archetypeName} pour le dépôt ${repoUser}/${repoName}` );
sh.rm('-rf', REPO_TEMP_DIR);
const repoDir = `${REPO_TEMP_DIR}/${repoName}`;
sh.mkdir('-p', repoDir);
lg(`** Copie des sources de l'archetype vers ${repoDir}`);
sh.cp('-R', `archetypes/${archetypeName}/*`, repoDir);
lg('** mise à jour du Jenkinsfile');
if(archetypeName === 'back') {
replace({
regex: "____PROD_GIT____",
replacement: `${jenkinsfileCfg.back.jenkinsfileUrlCleverCloud[projectName]}`,
paths: [`${repoDir}/Jenkinsfile`],
recursive: true,
silent: true,
});
replace({
regex: "____GIT_CREDENTIAL_ID____",
replacement: `${jenkinsfileCfg.back.jenkinsfileGitCredentialId}`,
paths: [`${repoDir}/Jenkinsfile`],
recursive: true,
silent: true,
});
replace({
regex: "____ARTIFACT_ID____",
replacement: `${repoName}`,
paths: [`${repoDir}/pom.xml`],
recursive: true,
silent: true,
});
}
if(archetypeName === 'front') {
replace({
regex: "____GH_ORG____",
replacement: `${repoUser}`,
paths: [`${repoDir}/Jenkinsfile`],
recursive: true,
silent: true,
});
replace({
regex: "____APP_REPO____",
replacement: `${repoName}`,
paths: [`${repoDir}/Jenkinsfile`],
recursive: true,
silent: true,
});
replace({
regex: "____BACKEND_PROD____",
replacement: `${jenkinsfileCfg.front.backendProdUrlMapping[projectName]}`,
paths: [`${repoDir}/Jenkinsfile`],
recursive: true,
silent: true,
});
}
lg(`** Commit & Push Github`);
const gitCmds = [
`cd ${repoDir} && git init`,
`cd ${repoDir} && git add .`,
`cd ${repoDir} && git commit -m "init archetype"`,
`cd ${repoDir} && git push --force ${PUSH_URL} master`];
gitCmds.forEach(sh.exec);
};
const push = (repoUser, config, jenkinsfileCfg) => {
Object.keys(config).forEach(repoName => {
pushArchetype(repoUser, `${repoName}-front`, 'front', jenkinsfileCfg, config[repoName]);
pushArchetype(repoUser, `${repoName}-back`, 'back', jenkinsfileCfg, config[repoName]);
})
};
exports.push = push;
exports.pushArchetype = pushArchetype;