@opencrvs/create-countryconfig 2.1.0-rc.511e19f → 2.1.0-rc.517ffcd
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 +114 -66
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -11,93 +11,141 @@
|
|
|
11
11
|
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const { execSync } = require('child_process')
|
|
15
14
|
const path = require('path')
|
|
16
15
|
const fs = require('fs')
|
|
16
|
+
const degit = require('degit').default
|
|
17
|
+
|
|
18
|
+
const INFRASTRUCTURE_REPOSITORY = 'opencrvs/infrastructure'
|
|
19
|
+
const CORE_REPOSITORY = 'opencrvs/opencrvs-core'
|
|
20
|
+
const COUNTRYCONFIG_TEMPLATE_REPOSITORY_SUBPATH =
|
|
21
|
+
'packages/countryconfig-template'
|
|
22
|
+
|
|
23
|
+
function joinValues(values, separator) {
|
|
24
|
+
return values
|
|
25
|
+
.filter((value) => !!value)
|
|
26
|
+
.join(separator)
|
|
27
|
+
.trim()
|
|
28
|
+
}
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Clones a repository from GitHub to a target directory.
|
|
32
|
+
*
|
|
33
|
+
* @param {*} param0 repository - The repository to clone (e.g., 'opencrvs/opencrvs-core').
|
|
34
|
+
* @param {*} param0 repositorySubPath - The subpath within the repository to clone (optional). Otherwise the entire repository will be cloned.
|
|
35
|
+
* @param {*} param0 branch - The branch to clone (optional). Defaults to the default branch if not specified.
|
|
36
|
+
*
|
|
37
|
+
* @param {*} targetDir - The target directory where the repository will be cloned.
|
|
38
|
+
*/
|
|
39
|
+
async function cloneRepository(
|
|
40
|
+
{ repository, repositorySubPath, branch },
|
|
41
|
+
targetDir
|
|
42
|
+
) {
|
|
43
|
+
const repositoryPath = joinValues([repository, repositorySubPath], '/')
|
|
44
|
+
const fullPath = joinValues([repositoryPath, branch], '#')
|
|
22
45
|
|
|
23
|
-
|
|
46
|
+
console.log(`Cloning repository from ${fullPath} to ${targetDir}...`)
|
|
24
47
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
process.exit(1)
|
|
30
|
-
}
|
|
48
|
+
const emitter = degit(fullPath, {
|
|
49
|
+
mode: 'git'
|
|
50
|
+
})
|
|
31
51
|
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
await emitter.clone(targetDir)
|
|
53
|
+
console.log(`Copied files from ${fullPath} to ${targetDir} succesfully.`)
|
|
54
|
+
}
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
const
|
|
56
|
+
function ensureTargetDirectoryDoesNotExist(directoryName) {
|
|
57
|
+
const targetDirectoryPath = path.resolve(process.cwd(), directoryName)
|
|
37
58
|
|
|
38
|
-
if (fs.existsSync(
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
if (fs.existsSync(targetDirectoryPath)) {
|
|
60
|
+
console.error(
|
|
61
|
+
'Error: Directory already exists in path "' + targetDirectoryPath + '".'
|
|
62
|
+
)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
41
65
|
}
|
|
42
66
|
|
|
43
|
-
|
|
44
|
-
console.
|
|
45
|
-
|
|
67
|
+
function updatePackageJsonName(targetPath, newName) {
|
|
68
|
+
console.log('\nUpdating package.json with project name: ' + newName + '\n')
|
|
69
|
+
|
|
70
|
+
const pkgPath = path.join(targetPath, 'package.json')
|
|
71
|
+
if (fs.existsSync(pkgPath)) {
|
|
72
|
+
try {
|
|
73
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
74
|
+
pkg.name = newName
|
|
75
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error('\nFailed to update package.json:', err.message)
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
console.warn(
|
|
82
|
+
'\nWarning: No package.json found in the targetPath: ' +
|
|
83
|
+
targetPath +
|
|
84
|
+
'. Project name was not updated.'
|
|
85
|
+
)
|
|
86
|
+
}
|
|
46
87
|
}
|
|
47
88
|
|
|
48
|
-
|
|
89
|
+
async function main() {
|
|
90
|
+
const projectName = process.argv[2]
|
|
49
91
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
92
|
+
if (!projectName) {
|
|
93
|
+
console.error(
|
|
94
|
+
'Please specify a project name:\n\n npm create @opencrvs/countryconfig <project-name>\n'
|
|
95
|
+
)
|
|
96
|
+
process.exit(1)
|
|
97
|
+
}
|
|
56
98
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
99
|
+
const countryconfigDirName = projectName + '-countryconfig'
|
|
100
|
+
const countryconfigTargetPath = path.resolve(
|
|
101
|
+
process.cwd(),
|
|
102
|
+
countryconfigDirName
|
|
103
|
+
)
|
|
104
|
+
const infrastructureDirName = projectName + '-infrastructure'
|
|
105
|
+
const infrastructureTargetPath = path.resolve(
|
|
106
|
+
process.cwd(),
|
|
107
|
+
infrastructureDirName
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
ensureTargetDirectoryDoesNotExist(countryconfigDirName)
|
|
111
|
+
ensureTargetDirectoryDoesNotExist(infrastructureDirName)
|
|
63
112
|
|
|
64
|
-
const pkgPath = path.join(countryconfigTargetDir, 'package.json')
|
|
65
|
-
if (fs.existsSync(pkgPath)) {
|
|
66
113
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
114
|
+
await cloneRepository(
|
|
115
|
+
{
|
|
116
|
+
repository: CORE_REPOSITORY,
|
|
117
|
+
repositorySubPath: COUNTRYCONFIG_TEMPLATE_REPOSITORY_SUBPATH,
|
|
118
|
+
branch: 'ocrvs-13179' // @todo: remove this hardcoded branch once the countryconfig-template is merged into main
|
|
119
|
+
},
|
|
120
|
+
countryconfigTargetPath
|
|
121
|
+
)
|
|
70
122
|
} catch (err) {
|
|
71
|
-
console.error('
|
|
123
|
+
console.error('\nFailed to clone country config template:', err.message)
|
|
72
124
|
process.exit(1)
|
|
73
125
|
}
|
|
74
|
-
} else {
|
|
75
|
-
console.warn('Warning: No package.json found in the cloned country config repository. Project name was not updated.')
|
|
76
|
-
}
|
|
77
126
|
|
|
78
|
-
|
|
127
|
+
updatePackageJsonName(countryconfigTargetPath, countryconfigDirName)
|
|
79
128
|
|
|
80
|
-
try {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
129
|
+
try {
|
|
130
|
+
await cloneRepository(
|
|
131
|
+
{ repository: INFRASTRUCTURE_REPOSITORY },
|
|
132
|
+
infrastructureTargetPath
|
|
133
|
+
)
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error('Failed to clone the infrastructure repository:', err.message)
|
|
136
|
+
process.exit(1)
|
|
137
|
+
}
|
|
86
138
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
console.
|
|
91
|
-
|
|
139
|
+
console.log('\nDone! Your project has been set up in two directories:\n')
|
|
140
|
+
console.log(' ./' + countryconfigDirName + ' -- country configuration')
|
|
141
|
+
console.log(' ./' + infrastructureDirName + ' -- server infrastructure\n')
|
|
142
|
+
console.log('To get started with the country config:\n')
|
|
143
|
+
console.log(' cd ' + countryconfigDirName)
|
|
144
|
+
console.log(' git init')
|
|
145
|
+
console.log(' tilt up\n')
|
|
146
|
+
console.log('To get started with the infrastructure:\n')
|
|
147
|
+
console.log(' cd ' + infrastructureDirName)
|
|
148
|
+
console.log(' git init\n')
|
|
92
149
|
}
|
|
93
150
|
|
|
94
|
-
|
|
95
|
-
console.log(' ./' + countryconfigDirName + ' -- country configuration')
|
|
96
|
-
console.log(' ./' + infrastructureDirName + ' -- server infrastructure\n')
|
|
97
|
-
console.log('To get started with the country config:\n')
|
|
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')
|
|
151
|
+
main()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencrvs/create-countryconfig",
|
|
3
|
-
"version": "2.1.0-rc.
|
|
3
|
+
"version": "2.1.0-rc.517ffcd",
|
|
4
4
|
"description": "Scaffold a new OpenCRVS country configuration",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-countryconfig": "./index.js"
|
|
@@ -17,5 +17,8 @@
|
|
|
17
17
|
"countryconfig",
|
|
18
18
|
"create"
|
|
19
19
|
],
|
|
20
|
-
"license": "MPL-2.0"
|
|
20
|
+
"license": "MPL-2.0",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"degit": "^3.6.5"
|
|
23
|
+
}
|
|
21
24
|
}
|