generator-razor 14.1.9 → 14.1.10

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/app/index.js +42 -0
  2. package/package.json +1 -1
package/app/index.js CHANGED
@@ -20,6 +20,48 @@ export default class extends Generator {
20
20
  this.props = {}
21
21
  }
22
22
 
23
+ /**
24
+ * Yeoman stores global prompt answers in ~/.yo-rc-global.json under
25
+ * "<generator>:<version>", so every release starts with empty defaults.
26
+ * Use a version-independent key instead and migrate the answers from the
27
+ * newest versioned entry once, then drop the obsolete versioned entries.
28
+ */
29
+ _getGlobalStorage () {
30
+ const storageDir = this.options.localConfigOnly ? this.destinationRoot() : os.homedir()
31
+ const storePath = path.join(storageDir, '.yo-rc-global.json')
32
+ const name = this.rootGeneratorName()
33
+
34
+ const rootStorage = this.createStorage(storePath, { allowOutsideRoot: true })
35
+ const storage = this.createStorage(storePath, { name, allowOutsideRoot: true })
36
+
37
+ const compareVersions = (a, b) => {
38
+ const pa = a.split('.').map(Number)
39
+ const pb = b.split('.').map(Number)
40
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
41
+ const diff = (pa[i] || 0) - (pb[i] || 0)
42
+ if (diff !== 0) return diff
43
+ }
44
+ return 0
45
+ }
46
+
47
+ const versionedKeys = Object.keys(rootStorage.getAll())
48
+ .filter(key => key.startsWith(`${name}:`))
49
+ .sort((a, b) => compareVersions(a.slice(name.length + 1), b.slice(name.length + 1)))
50
+
51
+ if (versionedKeys.length > 0) {
52
+ if (!storage.get('promptValues')) {
53
+ const latest = rootStorage.get(versionedKeys[versionedKeys.length - 1])
54
+ if (latest?.promptValues) {
55
+ storage.set('promptValues', latest.promptValues)
56
+ }
57
+ }
58
+
59
+ versionedKeys.forEach(key => rootStorage.delete(key))
60
+ }
61
+
62
+ return storage
63
+ }
64
+
23
65
  async prompting () {
24
66
  const orange = chalk.ansi256(208)
25
67
  const petrol = chalk.ansi256(24)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-razor",
3
- "version": "14.1.9",
3
+ "version": "14.1.10",
4
4
  "description": "Yeoman generator for razor TYPO3 distribution",
5
5
  "license": "MIT",
6
6
  "main": "app/index.js",