libphonenumber-js 1.12.12 → 1.12.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.12.12",
3
+ "version": "1.12.13",
4
4
  "description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -132,7 +132,7 @@
132
132
  "metadata:generate:max:js": "node runnable/json-to-js ./metadata.max.json",
133
133
  "metadata:generate:mobile:js": "node runnable/json-to-js ./metadata.mobile.json",
134
134
  "metadata:generate:mobile:examples:js": "node runnable/json-to-js ./examples.mobile.json",
135
- "metadata:download": "node runnable/download https://raw.githubusercontent.com/googlei18n/libphonenumber/master/resources/PhoneNumberMetadata.xml PhoneNumberMetadata.xml",
135
+ "metadata:download": "node runnable/download PhoneNumberMetadata.xml",
136
136
  "generate-country-codes": "node --experimental-json-modules runnable/generate-country-codes",
137
137
  "transform-mocha-tests-into-jest-tests": "npx jest-codemods",
138
138
  "test": "npm run test--mocha",
@@ -1,11 +1,20 @@
1
1
  import fs from 'fs'
2
2
  import { download } from 'libphonenumber-metadata-generator'
3
3
 
4
- const url = process.argv[2]
5
- const outputPath = process.argv[3]
4
+ const outputPath = process.argv[2]
6
5
 
7
- download(url).then((contents) => {
8
- fs.writeFileSync(outputPath, contents)
6
+ download().then(({ version, changes, xml }) => {
7
+ // Print the metadata version and a list of changes.
8
+ console.log('========================================')
9
+ console.log(`= Metadata / ${version}`)
10
+ console.log('=')
11
+ const consoleOutputPrefix = '= '
12
+ console.log(`= Changes:\n${changes.map(_ => consoleOutputPrefix + '* ' + _.replace(/\n/g, '\n' + consoleOutputPrefix + ' ')).join('\n')}`)
13
+ console.log('========================================')
14
+ // Write metadata changes info.
15
+ fs.writeFileSync('./metadata-update.json', JSON.stringify({ version, changes }, null, 2))
16
+ // Write the latest metadata XML to `PhoneNumberMetadata.xml` file.
17
+ fs.writeFileSync(outputPath, xml)
9
18
  }).catch((error) => {
10
19
  console.error(error)
11
20
  process.exit(1)
@@ -1,8 +1,11 @@
1
+ import fs from 'fs'
2
+ import semver from 'semver'
3
+
1
4
  import exec from './exec.js'
2
5
 
3
6
  export default function()
4
7
  {
5
- var metadata_changed = exec('git ls-files --modified PhoneNumberMetadata.xml')
8
+ let metadata_changed = exec('git ls-files --modified PhoneNumberMetadata.xml')
6
9
 
7
10
  if (!metadata_changed)
8
11
  {
@@ -33,9 +36,9 @@ export default function()
33
36
  console.log(exec('npm run build'))
34
37
  console.log(exec('npm test'))
35
38
 
36
- var modified_files = exec('git ls-files --modified').split(/\s/)
39
+ let modified_files = exec('git ls-files --modified').split(/\s/)
37
40
 
38
- var unexpected_modified_files = modified_files.filter(function(file)
41
+ let unexpected_modified_files = modified_files.filter(function(file)
39
42
  {
40
43
  return file !== 'PhoneNumberMetadata.xml' &&
41
44
  !/^metadata\.[a-z]+\.json$/.test(file) &&
@@ -48,7 +51,7 @@ export default function()
48
51
  // (perhaps something related to line endings)
49
52
  if (false && unexpected_modified_files.length > 0)
50
53
  {
51
- var error
54
+ let error
52
55
 
53
56
  error += 'Only `PhoneNumberMetadata.xml`, `metadata.*.json` and `examples.*.json` files should be modified. Unexpected modified files:'
54
57
  error += '\n'
@@ -68,7 +71,7 @@ export default function()
68
71
  // Doesn't work
69
72
  //
70
73
  // // http://stackoverflow.com/questions/33610682/git-list-of-staged-files
71
- // var staged_files = exec('git diff --name-only --cached').split(/\s/)
74
+ // let staged_files = exec('git diff --name-only --cached').split(/\s/)
72
75
  //
73
76
  // if (staged_files.length > 0)
74
77
  // {
@@ -84,5 +87,43 @@ export default function()
84
87
  // process.exit(1)
85
88
  // }
86
89
 
90
+ // Add an entry in `CHANGELOG.md`.
91
+ addMetadataUpdateChangelogEntry()
92
+
87
93
  return true
94
+ }
95
+
96
+ function addMetadataUpdateChangelogEntry() {
97
+ const {
98
+ version: metadataVersion,
99
+ changes: metadataChanges
100
+ } = JSON.parse(fs.readFileSync('./metadata-update.json', 'utf8'))
101
+
102
+ const packageVersion = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
103
+ const nextPackageVersion = semver.inc(packageVersion, 'patch')
104
+
105
+ const now = new Date()
106
+
107
+ let changesLog = ''
108
+ changesLog += `${nextPackageVersion} / ${now.getDate()}.${now.getMonth() + 1}.${now.getFullYear()}`
109
+ changesLog += '\n'
110
+ changesLog += '==================='
111
+ changesLog += '\n'
112
+ changesLog += '\n'
113
+ changesLog += `* Updated metadata to version ${metadataVersion}:`
114
+ changesLog += '\n'
115
+ changesLog += metadataChanges.map(change => ` - ${change.replace(/\n/g, '\n' + ' ')}`).join('\n')
116
+
117
+ const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8')
118
+
119
+ const changesLogStartMarker = '<!-- CHANGELOG START -->'
120
+ const changesLogStartMarkerStartsAt = changelog.indexOf(changesLogStartMarker)
121
+ if (changesLogStartMarkerStartsAt < 0) {
122
+ throw new Error('Changelog start marker not found in CHANGELOG.md')
123
+ }
124
+ const changesLogStartsAt = changesLogStartMarkerStartsAt + changesLogStartMarker.length
125
+ const changelogPre = changelog.slice(0, changesLogStartsAt)
126
+ const previousChangesLog = changelog.slice(changesLogStartsAt).trim()
127
+
128
+ fs.writeFileSync('./CHANGELOG.md', changelogPre + '\n\n' + changesLog + '\n\n' + previousChangesLog)
88
129
  }