libphonenumber-js 1.12.17 → 1.12.21

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 (179) hide show
  1. package/CHANGELOG.md +38 -2
  2. package/METADATA.md +2 -0
  3. package/README.md +255 -165
  4. package/build/AsYouType.js +6 -8
  5. package/build/AsYouType.js.map +1 -1
  6. package/build/AsYouType.test.js +13 -14
  7. package/build/AsYouType.test.js.map +1 -1
  8. package/build/AsYouTypeFormatter.complete.js +4 -4
  9. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  10. package/build/AsYouTypeFormatter.js +4 -4
  11. package/build/AsYouTypeFormatter.js.map +1 -1
  12. package/build/AsYouTypeParser.js +42 -29
  13. package/build/AsYouTypeParser.js.map +1 -1
  14. package/build/AsYouTypeState.js +21 -17
  15. package/build/AsYouTypeState.js.map +1 -1
  16. package/build/PhoneNumber.js +2 -2
  17. package/build/PhoneNumber.js.map +1 -1
  18. package/build/findNumbers/Leniency.js +0 -1
  19. package/build/findNumbers/Leniency.js.map +1 -1
  20. package/build/format.js +4 -4
  21. package/build/format.js.map +1 -1
  22. package/build/formatPhoneNumberForMobileDialing.js +2 -2
  23. package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
  24. package/build/helpers/checkNumberLength.js +39 -7
  25. package/build/helpers/checkNumberLength.js.map +1 -1
  26. package/build/helpers/checkNumberLength.test.js +51 -12
  27. package/build/helpers/checkNumberLength.test.js.map +1 -1
  28. package/build/helpers/extractCountryCallingCode.js +13 -10
  29. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  30. package/build/helpers/extractCountryCallingCode.test.js +3 -3
  31. package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
  32. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +10 -8
  33. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  34. package/build/helpers/extractNationalNumber.js +15 -5
  35. package/build/helpers/extractNationalNumber.js.map +1 -1
  36. package/build/helpers/extractNationalNumber.test.js +10 -2
  37. package/build/helpers/extractNationalNumber.test.js.map +1 -1
  38. package/build/helpers/getCountryByCallingCode.js +3 -2
  39. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  40. package/build/helpers/getCountryByNationalNumber.js +27 -6
  41. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  42. package/build/helpers/matchesEntirely.js +4 -4
  43. package/build/helpers/matchesEntirely.js.map +1 -1
  44. package/build/isPossible.js +4 -4
  45. package/build/isPossible.js.map +1 -1
  46. package/build/isPossible.test.js +9 -0
  47. package/build/isPossible.test.js.map +1 -1
  48. package/build/isPossiblePhoneNumber.test.js +6 -0
  49. package/build/isPossiblePhoneNumber.test.js.map +1 -1
  50. package/build/metadata.js +2 -2
  51. package/build/metadata.js.map +1 -1
  52. package/build/parse.js +9 -7
  53. package/build/parse.js.map +1 -1
  54. package/build/parseIncompletePhoneNumber.js +7 -7
  55. package/build/parseIncompletePhoneNumber.js.map +1 -1
  56. package/build/parsePhoneNumber.test.js +15 -0
  57. package/build/parsePhoneNumber.test.js.map +1 -1
  58. package/build/validatePhoneNumberLength.js +1 -1
  59. package/build/validatePhoneNumberLength.js.map +1 -1
  60. package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +87 -0
  61. package/build-scripts/check-for-metadata-changes-and-release.js +92 -0
  62. package/build-scripts/check-for-uncommitted-files.js +11 -0
  63. package/{runnable/json-to-js.js → build-scripts/create-js-file-for-json-file.js} +2 -2
  64. package/{runnable/metadata-branch.js → build-scripts/create-metadata-update-branch.js} +6 -1
  65. package/{runnable/generate-country-codes.js → build-scripts/generate-country-codes-list-in-typescript.js} +1 -0
  66. package/{runnable/generate.js → build-scripts/generate-metadata-from-google-metadata.js} +8 -14
  67. package/{runnable/modules → build-scripts/helpers}/commit.js +1 -0
  68. package/{runnable/modules → build-scripts/helpers}/exec.js +1 -0
  69. package/build-scripts/helpers/getUncommittedChanges.js +33 -0
  70. package/{runnable/modules/update-metadata.js → build-scripts/helpers/update-metadata-from-google-metadata.js} +9 -7
  71. package/{runnable/download.js → build-scripts/pull-google-metadata.js} +12 -4
  72. package/bundle/libphonenumber-js.min.js +1 -1
  73. package/bundle/libphonenumber-js.min.js.map +1 -1
  74. package/bundle/libphonenumber-max.js +1 -1
  75. package/bundle/libphonenumber-max.js.map +1 -1
  76. package/bundle/libphonenumber-min.js +1 -1
  77. package/bundle/libphonenumber-min.js.map +1 -1
  78. package/bundle/libphonenumber-mobile.js +1 -1
  79. package/bundle/libphonenumber-mobile.js.map +1 -1
  80. package/core/index.d.cts +1 -1
  81. package/core/index.d.ts +1 -1
  82. package/custom.d.ts +1 -1
  83. package/es6/AsYouType.js +6 -8
  84. package/es6/AsYouType.js.map +1 -1
  85. package/es6/AsYouType.test.js +13 -14
  86. package/es6/AsYouType.test.js.map +1 -1
  87. package/es6/AsYouTypeFormatter.complete.js +4 -4
  88. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  89. package/es6/AsYouTypeFormatter.js +4 -4
  90. package/es6/AsYouTypeFormatter.js.map +1 -1
  91. package/es6/AsYouTypeParser.js +42 -29
  92. package/es6/AsYouTypeParser.js.map +1 -1
  93. package/es6/AsYouTypeState.js +21 -17
  94. package/es6/AsYouTypeState.js.map +1 -1
  95. package/es6/PhoneNumber.js +1 -2
  96. package/es6/PhoneNumber.js.map +1 -1
  97. package/es6/findNumbers/Leniency.js +0 -1
  98. package/es6/findNumbers/Leniency.js.map +1 -1
  99. package/es6/format.js +4 -4
  100. package/es6/format.js.map +1 -1
  101. package/es6/formatPhoneNumberForMobileDialing.js +2 -2
  102. package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
  103. package/es6/helpers/checkNumberLength.js +39 -7
  104. package/es6/helpers/checkNumberLength.js.map +1 -1
  105. package/es6/helpers/checkNumberLength.test.js +49 -12
  106. package/es6/helpers/checkNumberLength.test.js.map +1 -1
  107. package/es6/helpers/extractCountryCallingCode.js +13 -10
  108. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  109. package/es6/helpers/extractCountryCallingCode.test.js +3 -3
  110. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
  111. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +10 -8
  112. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  113. package/es6/helpers/extractNationalNumber.js +15 -5
  114. package/es6/helpers/extractNationalNumber.js.map +1 -1
  115. package/es6/helpers/extractNationalNumber.test.js +10 -2
  116. package/es6/helpers/extractNationalNumber.test.js.map +1 -1
  117. package/es6/helpers/getCountryByCallingCode.js +3 -2
  118. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  119. package/es6/helpers/getCountryByNationalNumber.js +28 -6
  120. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  121. package/es6/helpers/matchesEntirely.js +4 -4
  122. package/es6/helpers/matchesEntirely.js.map +1 -1
  123. package/es6/isPossible.js +4 -4
  124. package/es6/isPossible.js.map +1 -1
  125. package/es6/isPossible.test.js +9 -0
  126. package/es6/isPossible.test.js.map +1 -1
  127. package/es6/isPossiblePhoneNumber.test.js +6 -0
  128. package/es6/isPossiblePhoneNumber.test.js.map +1 -1
  129. package/es6/metadata.js +2 -2
  130. package/es6/metadata.js.map +1 -1
  131. package/es6/parse.js +9 -7
  132. package/es6/parse.js.map +1 -1
  133. package/es6/parseIncompletePhoneNumber.js +7 -7
  134. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  135. package/es6/parsePhoneNumber.test.js +15 -0
  136. package/es6/parsePhoneNumber.test.js.map +1 -1
  137. package/es6/validatePhoneNumberLength.js +1 -1
  138. package/es6/validatePhoneNumberLength.js.map +1 -1
  139. package/index.d.cts +1 -1
  140. package/index.d.ts +1 -1
  141. package/max/index.d.cts +1 -1
  142. package/max/index.d.ts +1 -1
  143. package/min/index.d.cts +1 -1
  144. package/min/index.d.ts +1 -1
  145. package/mobile/index.d.cts +1 -1
  146. package/mobile/index.d.ts +1 -1
  147. package/package.json +17 -23
  148. package/source/AsYouType.js +8 -10
  149. package/source/AsYouType.test.js +13 -14
  150. package/source/AsYouTypeFormatter.complete.js +4 -4
  151. package/source/AsYouTypeFormatter.js +4 -4
  152. package/source/AsYouTypeParser.js +45 -28
  153. package/source/AsYouTypeState.js +21 -17
  154. package/source/PhoneNumber.js +1 -2
  155. package/source/findNumbers/Leniency.js +0 -1
  156. package/source/format.js +4 -4
  157. package/source/formatPhoneNumberForMobileDialing.js +2 -2
  158. package/source/helpers/checkNumberLength.js +40 -7
  159. package/source/helpers/checkNumberLength.test.js +54 -12
  160. package/source/helpers/extractCountryCallingCode.js +15 -10
  161. package/source/helpers/extractCountryCallingCode.test.js +3 -3
  162. package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +19 -8
  163. package/source/helpers/extractNationalNumber.js +15 -5
  164. package/source/helpers/extractNationalNumber.test.js +11 -2
  165. package/source/helpers/getCountryByCallingCode.js +2 -2
  166. package/source/helpers/getCountryByNationalNumber.js +27 -6
  167. package/source/helpers/matchesEntirely.js +4 -4
  168. package/source/isPossible.js +4 -4
  169. package/source/isPossible.test.js +11 -0
  170. package/source/isPossiblePhoneNumber.test.js +7 -0
  171. package/source/metadata.js +2 -2
  172. package/source/parse.js +9 -5
  173. package/source/parseIncompletePhoneNumber.js +7 -7
  174. package/source/parsePhoneNumber.test.js +17 -0
  175. package/source/validatePhoneNumberLength.js +1 -1
  176. package/runnable/metadata-update-and-push-and-pull-request.js +0 -47
  177. package/runnable/metadata-update-and-push.js +0 -30
  178. package/runnable/metadata-update-and-release.js +0 -36
  179. /package/{runnable/create-commonjs-package-json.js → build-scripts/create-commonjs-package-json-file.js} +0 -0
@@ -0,0 +1,87 @@
1
+ // (deprecated because unused)
2
+
3
+ // * Creates a pull request in the github repository from a local "metadata-update" branch.
4
+ // * Deletes the "metadata-update" branch.
5
+
6
+ // In order for this script to work:
7
+ //
8
+ // * Install `hub` command line tool: https://hub.github.com/
9
+ // * Create a "Personal Access Token" in GitHub account settings (just "repo_public" would be enough)
10
+ // * Tell `hub` to use the token for creating GitHub pull requests: `echo "---\ngithub.com:\n- protocol: https\n user: GITHUB_USERNAME\n oauth_token: TOKEN" >> ~/.config/hub`
11
+
12
+ import update_metadata_from_google_metadata from './helpers/update-metadata-from-google-metadata.js'
13
+ import commit from './helpers/commit.js'
14
+ import exec from './helpers/exec.js'
15
+
16
+ const googleMetadataFilePath = process.argv[2]
17
+ const metadataInfoFilePath = process.argv[3]
18
+
19
+ // This script is meant to be run from a local "update-metadata" branch.
20
+ // See `createMetadataUpdateBranch()` function for how it could be set up.
21
+ throw new Error('Run `createMetadataUpdateBranch()` function first')
22
+
23
+ if (update_metadata_from_google_metadata(googleMetadataFilePath, metadataInfoFilePath))
24
+ {
25
+ commit()
26
+
27
+ console.log()
28
+ console.log('========================================')
29
+ console.log('= Pushing changes =')
30
+ console.log('========================================')
31
+ console.log()
32
+
33
+ // Delete pre-existing remote `update-metadata` remote branch
34
+ // (if it already exists)
35
+ if (exec('git ls-remote --heads origin update-metadata'))
36
+ {
37
+ console.log(exec('git push origin update-metadata --delete'))
38
+ }
39
+
40
+ // Push the local `update-metadata` branch to GitHub
41
+ console.log(exec('git push origin update-metadata'))
42
+
43
+ console.log()
44
+ console.log('========================================')
45
+ console.log('= Pushed. Creating Pull Request. =')
46
+ console.log('========================================')
47
+ console.log()
48
+
49
+ console.log(exec('hub pull-request -m "Updated metadata" -b catamphetamine/libphonenumber-js:master -h update-metadata'))
50
+
51
+ console.log()
52
+ console.log('========================================')
53
+ console.log('= Pull Request created =')
54
+ console.log('========================================')
55
+ console.log()
56
+
57
+ console.log(exec('git checkout master'))
58
+ console.log(exec('git branch -D update-metadata'))
59
+ }
60
+
61
+ // This function creates "update-metadata" branch and switches into it.
62
+ function createMetadataUpdateBranch() {
63
+ let metadata_branch_exists = false
64
+
65
+ try
66
+ {
67
+ exec('git rev-parse --verify update-metadata')
68
+ metadata_branch_exists = true
69
+ }
70
+ catch (error)
71
+ {
72
+ if (error.message.indexOf('fatal: Needed a single revision') === -1)
73
+ {
74
+ throw error
75
+ }
76
+ }
77
+
78
+ if (metadata_branch_exists)
79
+ {
80
+ console.log(exec('git checkout master'))
81
+ console.log(exec('git branch -D update-metadata'))
82
+ }
83
+
84
+ console.log(exec('git pull'))
85
+ console.log(exec('git branch update-metadata origin/master'))
86
+ console.log(exec('git checkout update-metadata'))
87
+ }
@@ -0,0 +1,92 @@
1
+ // Pulls the latest metadata from Google's repo, and, if it has changed,
2
+ // pushes the changes in the main branch and releases a new version on `npm`.
3
+
4
+ import fs from 'fs'
5
+ import gmailSend from 'gmail-send'
6
+
7
+ import update_metadata_from_google_metadata from './helpers/update-metadata-from-google-metadata.js'
8
+ import commit from './helpers/commit.js'
9
+ import exec from './helpers/exec.js'
10
+
11
+ const googleMetadataFilePath = process.argv[2]
12
+ const metadataInfoFilePath = process.argv[3]
13
+
14
+ if (update_metadata_from_google_metadata(googleMetadataFilePath, metadataInfoFilePath))
15
+ {
16
+ commit()
17
+
18
+ console.log()
19
+ console.log('========================================')
20
+ console.log('= Push the changes to the repository =')
21
+ console.log('========================================')
22
+ console.log()
23
+
24
+ console.log(exec('git push'))
25
+
26
+ console.log()
27
+ console.log('========================================')
28
+ console.log('= Increment the version =')
29
+ console.log('========================================')
30
+ console.log()
31
+
32
+ console.log(exec('npm version patch'))
33
+ console.log(exec('git push'))
34
+
35
+ console.log()
36
+ console.log('========================================')
37
+ console.log('= Publish the new version =')
38
+ console.log('========================================')
39
+ console.log()
40
+
41
+ // `npm` requires "two-factor authentication", so running an `npm publish`
42
+ // command programmatically won't work without human intervention.
43
+ //
44
+ // To work around that, one could optionally specify GMail credentials.
45
+ // In that case, instead of attempting to run `npm publish` command,
46
+ // it will send an email notification to do that manually.
47
+ //
48
+ const emailSettings = getEmailSettings()
49
+ if (emailSettings) {
50
+ // Send an email notification about manually publishing the new version of the package to `npm`.
51
+ gmailSend({
52
+ user: emailSettings.email,
53
+ pass: emailSettings.accessToken,
54
+ to: emailSettings.email,
55
+ subject: '[libphonenumber-js] Publish a new version',
56
+ text: 'A new version of `libphonenumber-js` has been pushed to the repository and should be published manually to `npm` — run `npm publish` in `libphonenumber-js` directory.',
57
+ // html: '<b>html text</b>' // alternative to specifying `text`, one could specify `html`.
58
+ })()
59
+
60
+ console.log()
61
+ console.log('==========================================================')
62
+ console.log('= Email notification sent. Publish the package manually. =')
63
+ console.log('==========================================================')
64
+ console.log()
65
+ } else {
66
+ console.log(exec('npm publish'))
67
+
68
+ console.log()
69
+ console.log('========================================')
70
+ console.log('= Published =')
71
+ console.log('========================================')
72
+ console.log()
73
+ }
74
+ }
75
+
76
+ // Reads email settings from a JSON file just outside of `libphonenumber-js` repo folder.
77
+ function getEmailSettings() {
78
+ const emailSettingsPath = '../libphonenumber-js-autoupdate-email-notification-settings.json'
79
+ if (fs.existsSync(emailSettingsPath)) {
80
+ const emailSettings = JSON.parse(fs.readFileSync(emailSettingsPath, 'utf-8'))
81
+ // Validate `emailSettings`.
82
+ if (!emailSettings.email) {
83
+ throw new Error('`email` parameter not specified in the email config file')
84
+ }
85
+ // The instructions on how to obtain an `accessToken` are described in `gmail-send` readme:
86
+ // https://www.npmjs.com/package/gmail-send
87
+ if (!emailSettings.accessToken) {
88
+ throw new Error('`accessToken` parameter not specified in the email config file')
89
+ }
90
+ return emailSettings;
91
+ }
92
+ }
@@ -0,0 +1,11 @@
1
+ import getUncommittedChanges from './helpers/getUncommittedChanges.js';
2
+
3
+ getUncommittedChanges().then((uncommittedChanges) => {
4
+ if (uncommittedChanges.length > 0) {
5
+ console.error(new Error(`You have uncommitted files in your repository:\n${uncommittedChanges.map(({ filename }) => filename).join('\n')}`))
6
+ process.exit(1)
7
+ }
8
+ }).catch((error) => {
9
+ console.error(error)
10
+ process.exit(1)
11
+ })
@@ -5,9 +5,9 @@ const COMMENT = '// This file is a workaround for a bug in web browsers\' "nativ
5
5
  '// https://github.com/catamphetamine/libphonenumber-js/issues/239'
6
6
 
7
7
  const path = process.argv[2]
8
- jsonToJs(path)
8
+ createJsFileForJsonFile(path)
9
9
 
10
- function jsonToJs(path) {
10
+ function createJsFileForJsonFile(path) {
11
11
  let contents = fs.readFileSync(path, 'utf-8')
12
12
  contents = COMMENT + '\n' + 'export default ' + contents
13
13
  fs.writeFileSync(path + '.js', contents)
@@ -1,4 +1,9 @@
1
- import exec from './modules/exec.js'
1
+ // (deprecated because unused)
2
+
3
+ // Ccreates a new git branch called "update-metadata" and switches into it.
4
+ // If the branch with such name already exists, it overwrites it with a new one.
5
+
6
+ import exec from './helpers/exec.js'
2
7
 
3
8
  let metadata_branch_exists = false
4
9
 
@@ -3,6 +3,7 @@ import fs from 'fs'
3
3
 
4
4
  const countryCodes = Object.keys(metadata.countries)
5
5
 
6
+ // Fills in the list of possible values of `CountryCode` type in the TypeScript definition file.
6
7
  fs.writeFileSync(
7
8
  './types.d.ts',
8
9
  fs.readFileSync('./types.d.ts', 'utf-8').replace(
@@ -1,20 +1,17 @@
1
+ // Generates JSON metadata from Google's `PhoneNumberMetadata.xml` file.
2
+
1
3
  import minimist from 'minimist'
2
- import path from 'path'
3
4
  import fs from 'fs'
4
5
 
5
6
  import { version, generate, compress } from 'libphonenumber-metadata-generator'
6
7
 
7
- // https://ru.stackoverflow.com/questions/1281148/referenceerror-dirname-is-not-defined
8
- import { fileURLToPath } from 'url'
9
- import { dirname } from 'path'
10
- const __filename = fileURLToPath(import.meta.url)
11
- const __dirname = dirname(__filename)
12
-
13
8
  // const REGION_CODE_FOR_NON_GEO_ENTITY = '001'
14
9
 
15
- const input = fs.readFileSync(path.join(__dirname, process.argv[2]), 'utf8')
10
+ const input_file = process.argv[2]
16
11
  const output_file = process.argv[3]
17
12
 
13
+ const input = fs.readFileSync(input_file, 'utf8')
14
+
18
15
  const command_line_arguments = minimist(process.argv.slice(4))
19
16
 
20
17
  // Included countries
@@ -45,11 +42,11 @@ generate(input, version, included_countries, extended, included_phone_number_typ
45
42
  // Write uncompressed metadata into a file for easier debugging
46
43
  if (command_line_arguments.debug) {
47
44
  console.log('Output uncompressed JSON for debugging')
48
- fs.writeFileSync(path.join(__dirname, '../metadata.json'), JSON.stringify(output, undefined, 3))
45
+ fs.writeFileSync('./metadata.json', JSON.stringify(output, undefined, 3))
49
46
  }
50
47
 
51
48
  // Compress the generated metadata
52
- fs.writeFileSync(path.join(__dirname, output_file), JSON.stringify(compress(output)))
49
+ fs.writeFileSync(output_file, JSON.stringify(compress(output)))
53
50
 
54
51
  // Output mobile phone number type examples
55
52
  if (command_line_arguments.examples === 'mobile') {
@@ -73,9 +70,6 @@ generate(input, version, included_countries, extended, included_phone_number_typ
73
70
  }
74
71
  return out
75
72
  }, {})
76
- fs.writeFileSync(
77
- path.join(__dirname, '../examples.mobile.json'),
78
- JSON.stringify(examples)
79
- )
73
+ fs.writeFileSync('./examples.mobile.json', JSON.stringify(examples))
80
74
  }
81
75
  })
@@ -1,5 +1,6 @@
1
1
  import exec from './exec.js'
2
2
 
3
+ // Commits the current changes files in the local git repository.
3
4
  export default function()
4
5
  {
5
6
  console.log()
@@ -1,5 +1,6 @@
1
1
  import child_process from 'child_process'
2
2
 
3
+ // Executes a command.
3
4
  export default function exec(command)
4
5
  {
5
6
  return child_process.execSync(command).toString().trim()
@@ -0,0 +1,33 @@
1
+ import { exec } from 'child_process'
2
+
3
+ export default function getUncommittedChanges() {
4
+ return new Promise((resolve, reject) => {
5
+ exec('git status --porcelain', (error, stdout, stderr) => {
6
+ if (error) {
7
+ reject(error);
8
+ return
9
+ }
10
+
11
+ if (stderr) {
12
+ reject(new Error(stderr.toString()))
13
+ return
14
+ }
15
+
16
+ const output = stdout.toString().trim()
17
+
18
+ if (!output) {
19
+ resolve([]);
20
+ }
21
+
22
+ const uncommittedFiles = output.trim().split('\n').map((line) => {
23
+ line = line.trim()
24
+ const status = line[0]
25
+ line = line.slice(2)
26
+ const filename = line
27
+ return { status, filename }
28
+ })
29
+
30
+ resolve(uncommittedFiles)
31
+ })
32
+ })
33
+ }
@@ -3,9 +3,11 @@ import semver from 'semver'
3
3
 
4
4
  import exec from './exec.js'
5
5
 
6
- export default function()
6
+ // Checks if Google's metadata XML file has changes, and, if it has,
7
+ // generates JSON metadata files from it, runs the tests and updates `CHANGELOG.md`.
8
+ export default function(googleMetadataFilePath, metadataInfoFilePath)
7
9
  {
8
- let metadata_changed = exec('git ls-files --modified PhoneNumberMetadata.xml')
10
+ let metadata_changed = true || exec(`git ls-files --modified ${googleMetadataFilePath}`)
9
11
 
10
12
  if (!metadata_changed)
11
13
  {
@@ -40,7 +42,7 @@ export default function()
40
42
 
41
43
  let unexpected_modified_files = modified_files.filter(function(file)
42
44
  {
43
- return file !== 'PhoneNumberMetadata.xml' &&
45
+ return file !== googleMetadataFilePath &&
44
46
  !/^metadata\.[a-z]+\.json$/.test(file) &&
45
47
  !/^examples\.[a-z]+\.json$/.test(file)
46
48
  })
@@ -53,7 +55,7 @@ export default function()
53
55
  {
54
56
  let error
55
57
 
56
- error += 'Only `PhoneNumberMetadata.xml`, `metadata.*.json` and `examples.*.json` files should be modified. Unexpected modified files:'
58
+ error += 'Only `' + googleMetadataFilePath + '`, `metadata.*.json` and `examples.*.json` files should be modified. Unexpected modified files:'
57
59
  error += '\n'
58
60
  error += '\n'
59
61
  error += unexpected_modified_files.join('\n')
@@ -88,16 +90,16 @@ export default function()
88
90
  // }
89
91
 
90
92
  // Add an entry in `CHANGELOG.md`.
91
- addMetadataUpdateChangelogEntry()
93
+ addMetadataUpdateChangelogEntry(metadataInfoFilePath)
92
94
 
93
95
  return true
94
96
  }
95
97
 
96
- function addMetadataUpdateChangelogEntry() {
98
+ function addMetadataUpdateChangelogEntry(metadataInfoFilePath) {
97
99
  const {
98
100
  version: metadataVersion,
99
101
  changes: metadataChanges
100
- } = JSON.parse(fs.readFileSync('./metadata-update.json', 'utf8'))
102
+ } = JSON.parse(fs.readFileSync(metadataInfoFilePath, 'utf8'))
101
103
 
102
104
  const packageVersion = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
103
105
  const nextPackageVersion = semver.inc(packageVersion, 'patch')
@@ -1,20 +1,28 @@
1
1
  import fs from 'fs'
2
2
  import { download } from 'libphonenumber-metadata-generator'
3
3
 
4
- const outputPath = process.argv[2]
4
+ const metadataFileOutputPath = process.argv[2]
5
+ const infoFileOutputPath = process.argv[3]
5
6
 
6
- download().then(({ version, changes, xml }) => {
7
+ // Pulls the latest released metadata from Google's repostory.
8
+ // Updates `PhoneNumberMetadata.xml` and `metadata-info.json` files.
9
+ download().then(({ date, version, changes, xml }) => {
7
10
  // Print the metadata version and a list of changes.
8
11
  console.log('========================================')
9
12
  console.log(`= Metadata / ${version}`)
10
13
  console.log('=')
14
+ console.log(`= Date: ${date.toUTCString()
15
+ .slice(0, date.toUTCString().indexOf('00:00:00') - 1)
16
+ .slice(date.toUTCString().indexOf(',') + ', '.length)
17
+ }`)
18
+ console.log('=')
11
19
  const consoleOutputPrefix = '= '
12
20
  console.log(`= Changes:\n${changes.map(_ => consoleOutputPrefix + '* ' + _.replace(/\n/g, '\n' + consoleOutputPrefix + ' ')).join('\n')}`)
13
21
  console.log('========================================')
14
22
  // Write metadata changes info.
15
- fs.writeFileSync('./metadata-update.json', JSON.stringify({ version, changes }, null, 2))
23
+ fs.writeFileSync(infoFileOutputPath, JSON.stringify({ date, version, changes }, null, 2))
16
24
  // Write the latest metadata XML to `PhoneNumberMetadata.xml` file.
17
- fs.writeFileSync(outputPath, xml)
25
+ fs.writeFileSync(metadataFileOutputPath, xml)
18
26
  }).catch((error) => {
19
27
  console.error(error)
20
28
  process.exit(1)