@opencrvs/create-countryconfig 2.1.0-rc.a2d8806 → 2.1.0-rc.a434ca3
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 +59 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -15,10 +15,11 @@ const { execSync } = require('child_process')
|
|
|
15
15
|
const path = require('path')
|
|
16
16
|
const fs = require('fs')
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
18
|
+
const INFRASTRUCTURE_REPO_URL = 'https://github.com/opencrvs/infrastructure.git'
|
|
19
|
+
const COUNTRYCONFIG_TEMPLATE_PATH = path.resolve(
|
|
20
|
+
__dirname,
|
|
21
|
+
'../../countryconfig-template'
|
|
22
|
+
)
|
|
22
23
|
|
|
23
24
|
const projectName = process.argv[2]
|
|
24
25
|
|
|
@@ -33,34 +34,50 @@ const countryconfigDirName = projectName + '-countryconfig'
|
|
|
33
34
|
const infrastructureDirName = projectName + '-infrastructure'
|
|
34
35
|
|
|
35
36
|
const countryconfigTargetDir = path.resolve(process.cwd(), countryconfigDirName)
|
|
36
|
-
const infrastructureTargetDir = path.resolve(
|
|
37
|
+
const infrastructureTargetDir = path.resolve(
|
|
38
|
+
process.cwd(),
|
|
39
|
+
infrastructureDirName
|
|
40
|
+
)
|
|
37
41
|
|
|
38
42
|
if (fs.existsSync(countryconfigTargetDir)) {
|
|
39
|
-
console.error(
|
|
43
|
+
console.error(
|
|
44
|
+
'Error: Directory "' + countryconfigDirName + '" already exists.'
|
|
45
|
+
)
|
|
40
46
|
process.exit(1)
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
if (fs.existsSync(infrastructureTargetDir)) {
|
|
44
|
-
console.error(
|
|
50
|
+
console.error(
|
|
51
|
+
'Error: Directory "' + infrastructureDirName + '" already exists.'
|
|
52
|
+
)
|
|
45
53
|
process.exit(1)
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
console.log(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
console.error('Failed to clone the country config repository:', err.message)
|
|
54
|
-
process.exit(1)
|
|
55
|
-
}
|
|
56
|
+
console.log(
|
|
57
|
+
'\nCopying OpenCRVS country config template to ./' +
|
|
58
|
+
countryconfigDirName +
|
|
59
|
+
'...\n'
|
|
60
|
+
)
|
|
56
61
|
|
|
62
|
+
console.log(
|
|
63
|
+
'cp -r ' + COUNTRYCONFIG_TEMPLATE_PATH + ' ' + countryconfigTargetDir
|
|
64
|
+
)
|
|
57
65
|
try {
|
|
58
|
-
|
|
66
|
+
execSync(
|
|
67
|
+
'cp -r ' + COUNTRYCONFIG_TEMPLATE_PATH + ' ' + countryconfigTargetDir,
|
|
68
|
+
{
|
|
69
|
+
stdio: 'inherit'
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
console.log('\nCopying template completed successfully.\n')
|
|
59
73
|
} catch (err) {
|
|
60
|
-
console.error('
|
|
74
|
+
console.error('\nFailed to copy country config template:', err.message)
|
|
61
75
|
process.exit(1)
|
|
62
76
|
}
|
|
63
77
|
|
|
78
|
+
console.log(
|
|
79
|
+
'\nUpdating package.json with project name: ' + countryconfigDirName + '\n'
|
|
80
|
+
)
|
|
64
81
|
const pkgPath = path.join(countryconfigTargetDir, 'package.json')
|
|
65
82
|
if (fs.existsSync(pkgPath)) {
|
|
66
83
|
try {
|
|
@@ -68,26 +85,44 @@ if (fs.existsSync(pkgPath)) {
|
|
|
68
85
|
pkg.name = countryconfigDirName
|
|
69
86
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
70
87
|
} catch (err) {
|
|
71
|
-
console.error('
|
|
88
|
+
console.error('\nFailed to update package.json:', err.message)
|
|
72
89
|
process.exit(1)
|
|
73
90
|
}
|
|
74
91
|
} else {
|
|
75
|
-
console.warn(
|
|
92
|
+
console.warn(
|
|
93
|
+
'\nWarning: No package.json found in the cloned country config repository. Project name was not updated.'
|
|
94
|
+
)
|
|
76
95
|
}
|
|
77
96
|
|
|
78
|
-
console.log(
|
|
97
|
+
console.log(
|
|
98
|
+
'\nCloning OpenCRVS infrastructure repository from remote to ./' +
|
|
99
|
+
infrastructureDirName +
|
|
100
|
+
'...\n'
|
|
101
|
+
)
|
|
79
102
|
|
|
80
103
|
try {
|
|
81
|
-
execSync(
|
|
104
|
+
execSync(
|
|
105
|
+
'git clone --depth 1 ' +
|
|
106
|
+
INFRASTRUCTURE_REPO_URL +
|
|
107
|
+
' ' +
|
|
108
|
+
infrastructureDirName,
|
|
109
|
+
{ stdio: 'inherit' }
|
|
110
|
+
)
|
|
82
111
|
} catch (err) {
|
|
83
112
|
console.error('Failed to clone the infrastructure repository:', err.message)
|
|
84
113
|
process.exit(1)
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
try {
|
|
88
|
-
fs.rmSync(path.join(infrastructureTargetDir, '.git'), {
|
|
117
|
+
fs.rmSync(path.join(infrastructureTargetDir, '.git'), {
|
|
118
|
+
recursive: true,
|
|
119
|
+
force: true
|
|
120
|
+
})
|
|
89
121
|
} catch (err) {
|
|
90
|
-
console.error(
|
|
122
|
+
console.error(
|
|
123
|
+
'\nFailed to remove .git directory from infrastructure:',
|
|
124
|
+
err.message
|
|
125
|
+
)
|
|
91
126
|
process.exit(1)
|
|
92
127
|
}
|
|
93
128
|
|
|
@@ -97,7 +132,7 @@ console.log(' ./' + infrastructureDirName + ' -- server infrastructure\n')
|
|
|
97
132
|
console.log('To get started with the country config:\n')
|
|
98
133
|
console.log(' cd ' + countryconfigDirName)
|
|
99
134
|
console.log(' git init')
|
|
100
|
-
console.log('
|
|
135
|
+
console.log(' tilt up\n')
|
|
101
136
|
console.log('To get started with the infrastructure:\n')
|
|
102
137
|
console.log(' cd ' + infrastructureDirName)
|
|
103
138
|
console.log(' git init\n')
|