@opencrvs/create-countryconfig 2.0.1-rc.0a4db5f → 2.0.1-rc.0afe065
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/index.js +90 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,8 +17,55 @@ const fs = require('fs')
|
|
|
17
17
|
|
|
18
18
|
const COUNTRYCONFIG_REPO_URL =
|
|
19
19
|
'https://github.com/opencrvs/opencrvs-countryconfig.git'
|
|
20
|
-
const INFRASTRUCTURE_REPO_URL =
|
|
21
|
-
|
|
20
|
+
const INFRASTRUCTURE_REPO_URL = 'https://github.com/opencrvs/infrastructure.git'
|
|
21
|
+
|
|
22
|
+
const { version } = JSON.parse(
|
|
23
|
+
fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8')
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
function tagExists(repoUrl, tag) {
|
|
27
|
+
try {
|
|
28
|
+
execSync(
|
|
29
|
+
'git ls-remote --exit-code --tags ' + repoUrl + ' refs/tags/' + tag,
|
|
30
|
+
{
|
|
31
|
+
stdio: 'pipe'
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
return true
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function resolveRef() {
|
|
41
|
+
console.log('version: ' + version)
|
|
42
|
+
/* if (version.includes('-')) {
|
|
43
|
+
return 'develop'
|
|
44
|
+
} */
|
|
45
|
+
|
|
46
|
+
const tag = 'v' + version
|
|
47
|
+
if (
|
|
48
|
+
tagExists(COUNTRYCONFIG_REPO_URL, tag) &&
|
|
49
|
+
tagExists(INFRASTRUCTURE_REPO_URL, tag)
|
|
50
|
+
) {
|
|
51
|
+
return tag
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.warn(
|
|
55
|
+
'\nWarning: tag "' +
|
|
56
|
+
tag +
|
|
57
|
+
'" was not found in both the country config and infrastructure ' +
|
|
58
|
+
'repositories; falling back to develop for both.'
|
|
59
|
+
)
|
|
60
|
+
return 'develop'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function cloneRepository(repoUrl, ref, targetDir) {
|
|
64
|
+
execSync(
|
|
65
|
+
'git clone --depth 1 --branch ' + ref + ' ' + repoUrl + ' ' + targetDir,
|
|
66
|
+
{ stdio: 'inherit' }
|
|
67
|
+
)
|
|
68
|
+
}
|
|
22
69
|
|
|
23
70
|
const projectName = process.argv[2]
|
|
24
71
|
|
|
@@ -33,31 +80,48 @@ const countryconfigDirName = projectName + '-countryconfig'
|
|
|
33
80
|
const infrastructureDirName = projectName + '-infrastructure'
|
|
34
81
|
|
|
35
82
|
const countryconfigTargetDir = path.resolve(process.cwd(), countryconfigDirName)
|
|
36
|
-
const infrastructureTargetDir = path.resolve(
|
|
83
|
+
const infrastructureTargetDir = path.resolve(
|
|
84
|
+
process.cwd(),
|
|
85
|
+
infrastructureDirName
|
|
86
|
+
)
|
|
37
87
|
|
|
38
88
|
if (fs.existsSync(countryconfigTargetDir)) {
|
|
39
|
-
console.error(
|
|
89
|
+
console.error(
|
|
90
|
+
'Error: Directory "' + countryconfigDirName + '" already exists.'
|
|
91
|
+
)
|
|
40
92
|
process.exit(1)
|
|
41
93
|
}
|
|
42
94
|
|
|
43
95
|
if (fs.existsSync(infrastructureTargetDir)) {
|
|
44
|
-
console.error(
|
|
96
|
+
console.error(
|
|
97
|
+
'Error: Directory "' + infrastructureDirName + '" already exists.'
|
|
98
|
+
)
|
|
45
99
|
process.exit(1)
|
|
46
100
|
}
|
|
47
101
|
|
|
48
|
-
|
|
102
|
+
const ref = resolveRef()
|
|
103
|
+
|
|
104
|
+
console.log(
|
|
105
|
+
'\nScaffolding OpenCRVS country config in ./' + countryconfigDirName + '...\n'
|
|
106
|
+
)
|
|
49
107
|
|
|
50
108
|
try {
|
|
51
|
-
|
|
109
|
+
cloneRepository(COUNTRYCONFIG_REPO_URL, ref, countryconfigDirName)
|
|
52
110
|
} catch (err) {
|
|
53
111
|
console.error('Failed to clone the country config repository:', err.message)
|
|
54
112
|
process.exit(1)
|
|
55
113
|
}
|
|
56
114
|
|
|
57
115
|
try {
|
|
58
|
-
fs.rmSync(path.join(countryconfigTargetDir, '.git'), {
|
|
116
|
+
fs.rmSync(path.join(countryconfigTargetDir, '.git'), {
|
|
117
|
+
recursive: true,
|
|
118
|
+
force: true
|
|
119
|
+
})
|
|
59
120
|
} catch (err) {
|
|
60
|
-
console.error(
|
|
121
|
+
console.error(
|
|
122
|
+
'Failed to remove .git directory from country config:',
|
|
123
|
+
err.message
|
|
124
|
+
)
|
|
61
125
|
process.exit(1)
|
|
62
126
|
}
|
|
63
127
|
|
|
@@ -72,22 +136,34 @@ if (fs.existsSync(pkgPath)) {
|
|
|
72
136
|
process.exit(1)
|
|
73
137
|
}
|
|
74
138
|
} else {
|
|
75
|
-
console.warn(
|
|
139
|
+
console.warn(
|
|
140
|
+
'Warning: No package.json found in the cloned country config repository. Project name was not updated.'
|
|
141
|
+
)
|
|
76
142
|
}
|
|
77
143
|
|
|
78
|
-
console.log(
|
|
144
|
+
console.log(
|
|
145
|
+
'\nScaffolding OpenCRVS infrastructure in ./' +
|
|
146
|
+
infrastructureDirName +
|
|
147
|
+
'...\n'
|
|
148
|
+
)
|
|
79
149
|
|
|
80
150
|
try {
|
|
81
|
-
|
|
151
|
+
cloneRepository(INFRASTRUCTURE_REPO_URL, ref, infrastructureDirName)
|
|
82
152
|
} catch (err) {
|
|
83
153
|
console.error('Failed to clone the infrastructure repository:', err.message)
|
|
84
154
|
process.exit(1)
|
|
85
155
|
}
|
|
86
156
|
|
|
87
157
|
try {
|
|
88
|
-
fs.rmSync(path.join(infrastructureTargetDir, '.git'), {
|
|
158
|
+
fs.rmSync(path.join(infrastructureTargetDir, '.git'), {
|
|
159
|
+
recursive: true,
|
|
160
|
+
force: true
|
|
161
|
+
})
|
|
89
162
|
} catch (err) {
|
|
90
|
-
console.error(
|
|
163
|
+
console.error(
|
|
164
|
+
'Failed to remove .git directory from infrastructure:',
|
|
165
|
+
err.message
|
|
166
|
+
)
|
|
91
167
|
process.exit(1)
|
|
92
168
|
}
|
|
93
169
|
|