@opencrvs/create-countryconfig 2.1.0-rc.12673aa → 2.1.0-rc.14fb6a5

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 +59 -30
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -96,27 +96,29 @@ function getLatestCommonReleaseTag() {
96
96
  }
97
97
 
98
98
  /**
99
- * A prerelease-shaped own version (e.g. "2.1.0-rc.f5ea803", what npm resolves
100
- * `@next` to - a build published from every push to a branch) never has a
101
- * matching release tag, so it's resolved as a branch instead. Its base
102
- * version (stripped of the "-rc.<sha>" suffix) tells apart two different
103
- * situations: an RC for a version already being stabilized on its own
104
- * "release/X.Y.Z" branch (e.g. "2.0.1-rc.*" while a patch release is in
105
- * progress) versus an RC for a version that hasn't been branched off yet and
106
- * only exists on develop (e.g. "2.1.0-rc.*" while that release branch hasn't
107
- * been cut). Scaffold from the release branch when it exists in both
108
- * repositories, otherwise fall back to develop.
99
+ * Resolves the ref that both repositories are cloned from. A single ref
100
+ * clones both, so every candidate must exist in *both* - a tag present in
101
+ * only one of them can't be used.
109
102
  *
110
- * Otherwise, the own "X.Y.Z" version - whether resolved via npm's `latest`
111
- * dist-tag (bare invocation) or an explicit `@X.Y.Z` pin - scaffolds from the
112
- * matching "vX.Y.Z" tag when it exists in both repositories. If it doesn't
113
- * (e.g. `latest` lagging behind the repos, or a pin that predates one repo's
114
- * tagging), fall back to the highest release tag common to both, rather than
115
- * a mismatched pairing of one tagged repo at that version and another repo
116
- * at a different release. Exits with an error if no matching release tag
117
- * exists in both repositories.
103
+ * The exact "v<version>" tag wins whenever it exists: it pins a commit, so
104
+ * a release, an explicit `@X.Y.Z` pin, or a blessed prerelease (npm `@beta`,
105
+ * published from that tag) reproduces however late it's scaffolded.
106
+ *
107
+ * Otherwise a prerelease falls back to a branch, since a rolling release
108
+ * candidate (npm `@next`) is never tagged: "release/X.Y.Z" of the base
109
+ * version when that release has been cut, otherwise develop. A release
110
+ * falls back to the highest tag common to both repositories - never a
111
+ * mismatched pairing of the two at different releases - or errors.
118
112
  */
119
113
  function resolveRef() {
114
+ const versionTag = 'v' + version
115
+ if (
116
+ tagExists(CORE_REPO_URL, versionTag) &&
117
+ tagExists(INFRASTRUCTURE_REPO_URL, versionTag)
118
+ ) {
119
+ return versionTag
120
+ }
121
+
120
122
  if (version.includes('-')) {
121
123
  const releaseBranch = 'release/' + version.split('-')[0]
122
124
  if (
@@ -128,19 +130,11 @@ function resolveRef() {
128
130
  return 'develop'
129
131
  }
130
132
 
131
- const tag = 'v' + version
132
- if (
133
- tagExists(CORE_REPO_URL, tag) &&
134
- tagExists(INFRASTRUCTURE_REPO_URL, tag)
135
- ) {
136
- return tag
137
- }
138
-
139
133
  const latestCommonTag = getLatestCommonReleaseTag()
140
134
  if (latestCommonTag) {
141
135
  console.warn(
142
136
  '\nWarning: tag "' +
143
- tag +
137
+ versionTag +
144
138
  '" was not found in both repositories; falling back to the latest ' +
145
139
  'available release, ' +
146
140
  latestCommonTag +
@@ -162,13 +156,43 @@ function resolveRef() {
162
156
  * @param {*} param0 repository - The repository to clone (e.g., 'opencrvs/opencrvs-core').
163
157
  * @param {*} param0 repositorySubPath - The subpath within the repository to clone (optional). Otherwise the entire repository will be cloned.
164
158
  * @param {*} param0 branch - The branch to clone (optional). Defaults to the default branch if not specified.
159
+ * @param {*} param0 keepHistory - Keep the repository's git history instead of degit's usual history-free copy (optional, defaults to false). The cloned "origin" remote is replaced with "upstream", leaving the directory ready for the user to add their own fork/repo as "origin". Not supported together with repositorySubPath, since a plain git clone can't fetch a single subdirectory.
165
160
  *
166
161
  * @param {*} targetDir - The target directory where the repository will be cloned.
167
162
  */
168
163
  async function cloneRepository(
169
- { repository, repositorySubPath, branch },
164
+ { repository, repositorySubPath, branch, keepHistory = false },
170
165
  targetDir
171
166
  ) {
167
+ if (keepHistory && repositorySubPath) {
168
+ throw new Error(
169
+ 'cloneRepository: keepHistory is not supported together with repositorySubPath.'
170
+ )
171
+ }
172
+
173
+ if (keepHistory) {
174
+ const repoUrl = `https://github.com/${repository}.git`
175
+ console.log(
176
+ `Cloning repository from ${repoUrl}#${branch} to ${targetDir}...`
177
+ )
178
+
179
+ execSync('git clone --branch ' + branch + ' ' + repoUrl + ' ' + targetDir, {
180
+ stdio: 'inherit'
181
+ })
182
+
183
+ console.log(
184
+ `Copied files from ${repoUrl}#${branch} to ${targetDir} succesfully.`
185
+ )
186
+
187
+ console.log(`Replacing 'origin' remote with 'upstream' in ${targetDir}...`)
188
+ execSync('git remote remove origin', { cwd: targetDir, stdio: 'inherit' })
189
+ execSync('git remote add upstream ' + repoUrl, {
190
+ cwd: targetDir,
191
+ stdio: 'inherit'
192
+ })
193
+ return
194
+ }
195
+
172
196
  const repositoryPath = joinValues([repository, repositorySubPath], '/')
173
197
  const fullPath = joinValues([repositoryPath, branch], '#')
174
198
 
@@ -424,7 +448,7 @@ async function main() {
424
448
 
425
449
  try {
426
450
  await cloneRepository(
427
- { repository: INFRASTRUCTURE_REPOSITORY, branch: ref },
451
+ { repository: INFRASTRUCTURE_REPOSITORY, branch: ref, keepHistory: true },
428
452
  infrastructureTargetPath
429
453
  )
430
454
  } catch (err) {
@@ -450,7 +474,12 @@ async function main() {
450
474
  console.log(' tilt up\n')
451
475
  console.log('To get started with the infrastructure:\n')
452
476
  console.log(' cd ' + infrastructureDirName)
453
- console.log(' git init\n')
477
+ console.log(' git remote add origin <your-infrastructure-repo-url>')
478
+ console.log(' git push -u origin ' + ref + '\n')
479
+ console.log(
480
+ 'The "upstream" remote points at the official infrastructure repository, ' +
481
+ 'so you can pull future releases with `git fetch upstream`.\n'
482
+ )
454
483
  }
455
484
 
456
485
  main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/create-countryconfig",
3
- "version": "2.1.0-rc.12673aa",
3
+ "version": "2.1.0-rc.14fb6a5",
4
4
  "description": "Scaffold a new OpenCRVS country configuration",
5
5
  "bin": {
6
6
  "create-countryconfig": "./index.js"