adapt-migrations 1.3.0 → 1.4.0

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/lib/Task.js +17 -1
  2. package/package.json +2 -1
package/lib/Task.js CHANGED
@@ -5,6 +5,8 @@ import chalk from 'chalk'
5
5
  import TaskContext from './TaskContext.js'
6
6
  import Journal from '../lib/Journal.js'
7
7
  import { exec } from 'child_process'
8
+ import pkgUp from 'pkg-up'
9
+ import semver from 'semver'
8
10
 
9
11
  function makeTable(items, columnNames) {
10
12
  // calculate the max column widths for the items
@@ -277,9 +279,23 @@ export default class Task {
277
279
  toDelete.forEach(filePath => fs.rmSync(filePath))
278
280
  let i = 0
279
281
  for (const filePath of scripts) {
282
+ let fileContents = fs.readFileSync(filePath, 'utf8')
280
283
  const cachedPath = path.join(cachePath, `a${++i}.js`).replace(/\\/g, '/')
281
284
  Task.mapCacheToSource[cachedPath] = filePath.replace(/\\/g, '/')
282
- fs.copyFileSync(filePath, cachedPath)
285
+ const replacements = ['@@CURRENT_VERSION', '@@RELEASE_VERSION']
286
+ const shouldReplaceVersions = replacements.some(item => fileContents.includes(item))
287
+ if (shouldReplaceVersions) {
288
+ const packageJsonPath = await pkgUp({ cwd: filePath })
289
+ if (!packageJsonPath) return logger.error(`Task -- Unable to find package.json for ${filePath}`)
290
+ const packageJson = await fs.readJson(packageJsonPath)
291
+ const currentVersion = packageJson.version
292
+ const releaseVersion = semver.inc(currentVersion, 'patch')
293
+ fileContents = fileContents
294
+ .replace(/@@CURRENT_VERSION/g, currentVersion)
295
+ .replace(/@@RELEASE_VERSION/g, releaseVersion)
296
+ logger.info(`Task -- ${filePath} @@CURRENT_VERSION/@@RELEASE_VERSION replaced with ${currentVersion}/${releaseVersion}`)
297
+ }
298
+ fs.writeFileSync(cachedPath, fileContents, 'utf8')
283
299
  }
284
300
  fs.writeJsonSync(path.join(cachePath, 'package.json'), {
285
301
  name: 'migrations',
package/package.json CHANGED
@@ -2,11 +2,12 @@
2
2
  "name": "adapt-migrations",
3
3
  "type": "module",
4
4
  "main": "index.js",
5
- "version": "1.3.0",
5
+ "version": "1.4.0",
6
6
  "repositoryUrl": "https://github.com/adaptlearning/adapt-migrations.git",
7
7
  "dependencies": {
8
8
  "fs-extra": "^11.1.1",
9
9
  "globs": "^0.1.4",
10
+ "pkg-up": "^3.1.0",
10
11
  "semver": "^7.5.4"
11
12
  },
12
13
  "devDependencies": {