@opencrvs/create-countryconfig 2.0.1-rc.007f18d → 2.0.1-rc.02c1a89

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