@opencrvs/create-countryconfig 2.0.0-rc.1ddd150 → 2.0.0-rc.1f0a972
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 +20 -50
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -15,10 +15,7 @@ const { execSync } = require('child_process')
|
|
|
15
15
|
const path = require('path')
|
|
16
16
|
const fs = require('fs')
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
'https://github.com/opencrvs/opencrvs-countryconfig.git'
|
|
20
|
-
const INFRASTRUCTURE_REPO_URL =
|
|
21
|
-
'https://github.com/opencrvs/infrastructure.git'
|
|
18
|
+
const REPO_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git'
|
|
22
19
|
|
|
23
20
|
const projectName = process.argv[2]
|
|
24
21
|
|
|
@@ -29,75 +26,48 @@ if (!projectName) {
|
|
|
29
26
|
process.exit(1)
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
const
|
|
33
|
-
const infrastructureDirName = projectName + '-infrastructure'
|
|
29
|
+
const targetDir = path.resolve(process.cwd(), projectName)
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (fs.existsSync(countryconfigTargetDir)) {
|
|
39
|
-
console.error('Error: Directory "' + countryconfigDirName + '" already exists.')
|
|
40
|
-
process.exit(1)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (fs.existsSync(infrastructureTargetDir)) {
|
|
44
|
-
console.error('Error: Directory "' + infrastructureDirName + '" already exists.')
|
|
31
|
+
if (fs.existsSync(targetDir)) {
|
|
32
|
+
console.error(`Error: Directory "${projectName}" already exists.`)
|
|
45
33
|
process.exit(1)
|
|
46
34
|
}
|
|
47
35
|
|
|
48
|
-
console.log(
|
|
36
|
+
console.log(`\nScaffolding OpenCRVS country config in ./${projectName}...\n`)
|
|
49
37
|
|
|
50
38
|
try {
|
|
51
|
-
execSync(
|
|
39
|
+
execSync(`git clone --depth 1 ${REPO_URL} ${projectName}`, {
|
|
40
|
+
stdio: 'inherit'
|
|
41
|
+
})
|
|
52
42
|
} catch (err) {
|
|
53
|
-
console.error('Failed to clone the
|
|
43
|
+
console.error('Failed to clone the repository:', err.message)
|
|
54
44
|
process.exit(1)
|
|
55
45
|
}
|
|
56
46
|
|
|
57
47
|
try {
|
|
58
|
-
fs.rmSync(path.join(
|
|
48
|
+
fs.rmSync(path.join(targetDir, '.git'), { recursive: true, force: true })
|
|
59
49
|
} catch (err) {
|
|
60
|
-
console.error('Failed to remove .git directory
|
|
50
|
+
console.error('Failed to remove .git directory:', err.message)
|
|
61
51
|
process.exit(1)
|
|
62
52
|
}
|
|
63
53
|
|
|
64
|
-
const pkgPath = path.join(
|
|
54
|
+
const pkgPath = path.join(targetDir, 'package.json')
|
|
65
55
|
if (fs.existsSync(pkgPath)) {
|
|
66
56
|
try {
|
|
67
57
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
68
|
-
pkg.name =
|
|
58
|
+
pkg.name = projectName
|
|
69
59
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
70
60
|
} catch (err) {
|
|
71
61
|
console.error('Failed to update package.json:', err.message)
|
|
72
62
|
process.exit(1)
|
|
73
63
|
}
|
|
74
64
|
} else {
|
|
75
|
-
console.warn(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.log('\nScaffolding OpenCRVS infrastructure in ./' + infrastructureDirName + '...\n')
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
execSync('git clone --depth 1 ' + INFRASTRUCTURE_REPO_URL + ' ' + infrastructureDirName, { stdio: 'inherit' })
|
|
82
|
-
} catch (err) {
|
|
83
|
-
console.error('Failed to clone the infrastructure repository:', err.message)
|
|
84
|
-
process.exit(1)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
fs.rmSync(path.join(infrastructureTargetDir, '.git'), { recursive: true, force: true })
|
|
89
|
-
} catch (err) {
|
|
90
|
-
console.error('Failed to remove .git directory from infrastructure:', err.message)
|
|
91
|
-
process.exit(1)
|
|
65
|
+
console.warn(
|
|
66
|
+
`Warning: No package.json found in the cloned repository. Project name was not updated.`
|
|
67
|
+
)
|
|
92
68
|
}
|
|
93
69
|
|
|
94
|
-
console.log(
|
|
95
|
-
console.log(
|
|
96
|
-
console.log(
|
|
97
|
-
console.log(
|
|
98
|
-
console.log(' cd ' + countryconfigDirName)
|
|
99
|
-
console.log(' git init')
|
|
100
|
-
console.log(' npm install\n')
|
|
101
|
-
console.log('To get started with the infrastructure:\n')
|
|
102
|
-
console.log(' cd ' + infrastructureDirName)
|
|
103
|
-
console.log(' git init\n')
|
|
70
|
+
console.log(`\nDone! To get started:\n`)
|
|
71
|
+
console.log(` cd ${projectName}`)
|
|
72
|
+
console.log(` git init`)
|
|
73
|
+
console.log(` npm install\n`)
|