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.
- package/CHANGELOG.md +38 -2
- package/METADATA.md +2 -0
- package/README.md +255 -165
- package/build/AsYouType.js +6 -8
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js +13 -14
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js +4 -4
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +4 -4
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeParser.js +42 -29
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/AsYouTypeState.js +21 -17
- package/build/AsYouTypeState.js.map +1 -1
- package/build/PhoneNumber.js +2 -2
- package/build/PhoneNumber.js.map +1 -1
- package/build/findNumbers/Leniency.js +0 -1
- package/build/findNumbers/Leniency.js.map +1 -1
- package/build/format.js +4 -4
- package/build/format.js.map +1 -1
- package/build/formatPhoneNumberForMobileDialing.js +2 -2
- package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/build/helpers/checkNumberLength.js +39 -7
- package/build/helpers/checkNumberLength.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js +51 -12
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.js +13 -10
- package/build/helpers/extractCountryCallingCode.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js +3 -3
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +10 -8
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/build/helpers/extractNationalNumber.js +15 -5
- package/build/helpers/extractNationalNumber.js.map +1 -1
- package/build/helpers/extractNationalNumber.test.js +10 -2
- package/build/helpers/extractNationalNumber.test.js.map +1 -1
- package/build/helpers/getCountryByCallingCode.js +3 -2
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getCountryByNationalNumber.js +27 -6
- package/build/helpers/getCountryByNationalNumber.js.map +1 -1
- package/build/helpers/matchesEntirely.js +4 -4
- package/build/helpers/matchesEntirely.js.map +1 -1
- package/build/isPossible.js +4 -4
- package/build/isPossible.js.map +1 -1
- package/build/isPossible.test.js +9 -0
- package/build/isPossible.test.js.map +1 -1
- package/build/isPossiblePhoneNumber.test.js +6 -0
- package/build/isPossiblePhoneNumber.test.js.map +1 -1
- package/build/metadata.js +2 -2
- package/build/metadata.js.map +1 -1
- package/build/parse.js +9 -7
- package/build/parse.js.map +1 -1
- package/build/parseIncompletePhoneNumber.js +7 -7
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parsePhoneNumber.test.js +15 -0
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/build/validatePhoneNumberLength.js +1 -1
- package/build/validatePhoneNumberLength.js.map +1 -1
- package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +87 -0
- package/build-scripts/check-for-metadata-changes-and-release.js +92 -0
- package/build-scripts/check-for-uncommitted-files.js +11 -0
- package/{runnable/json-to-js.js → build-scripts/create-js-file-for-json-file.js} +2 -2
- package/{runnable/metadata-branch.js → build-scripts/create-metadata-update-branch.js} +6 -1
- package/{runnable/generate-country-codes.js → build-scripts/generate-country-codes-list-in-typescript.js} +1 -0
- package/{runnable/generate.js → build-scripts/generate-metadata-from-google-metadata.js} +8 -14
- package/{runnable/modules → build-scripts/helpers}/commit.js +1 -0
- package/{runnable/modules → build-scripts/helpers}/exec.js +1 -0
- package/build-scripts/helpers/getUncommittedChanges.js +33 -0
- package/{runnable/modules/update-metadata.js → build-scripts/helpers/update-metadata-from-google-metadata.js} +9 -7
- package/{runnable/download.js → build-scripts/pull-google-metadata.js} +12 -4
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/core/index.d.cts +1 -1
- package/core/index.d.ts +1 -1
- package/custom.d.ts +1 -1
- package/es6/AsYouType.js +6 -8
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js +13 -14
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js +4 -4
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +4 -4
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeParser.js +42 -29
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/AsYouTypeState.js +21 -17
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/PhoneNumber.js +1 -2
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/findNumbers/Leniency.js +0 -1
- package/es6/findNumbers/Leniency.js.map +1 -1
- package/es6/format.js +4 -4
- package/es6/format.js.map +1 -1
- package/es6/formatPhoneNumberForMobileDialing.js +2 -2
- package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6/helpers/checkNumberLength.js +39 -7
- package/es6/helpers/checkNumberLength.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js +49 -12
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.js +13 -10
- package/es6/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js +3 -3
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +10 -8
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6/helpers/extractNationalNumber.js +15 -5
- package/es6/helpers/extractNationalNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumber.test.js +10 -2
- package/es6/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6/helpers/getCountryByCallingCode.js +3 -2
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getCountryByNationalNumber.js +28 -6
- package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6/helpers/matchesEntirely.js +4 -4
- package/es6/helpers/matchesEntirely.js.map +1 -1
- package/es6/isPossible.js +4 -4
- package/es6/isPossible.js.map +1 -1
- package/es6/isPossible.test.js +9 -0
- package/es6/isPossible.test.js.map +1 -1
- package/es6/isPossiblePhoneNumber.test.js +6 -0
- package/es6/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6/metadata.js +2 -2
- package/es6/metadata.js.map +1 -1
- package/es6/parse.js +9 -7
- package/es6/parse.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +7 -7
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +15 -0
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/es6/validatePhoneNumberLength.js +1 -1
- package/es6/validatePhoneNumberLength.js.map +1 -1
- package/index.d.cts +1 -1
- package/index.d.ts +1 -1
- package/max/index.d.cts +1 -1
- package/max/index.d.ts +1 -1
- package/min/index.d.cts +1 -1
- package/min/index.d.ts +1 -1
- package/mobile/index.d.cts +1 -1
- package/mobile/index.d.ts +1 -1
- package/package.json +17 -23
- package/source/AsYouType.js +8 -10
- package/source/AsYouType.test.js +13 -14
- package/source/AsYouTypeFormatter.complete.js +4 -4
- package/source/AsYouTypeFormatter.js +4 -4
- package/source/AsYouTypeParser.js +45 -28
- package/source/AsYouTypeState.js +21 -17
- package/source/PhoneNumber.js +1 -2
- package/source/findNumbers/Leniency.js +0 -1
- package/source/format.js +4 -4
- package/source/formatPhoneNumberForMobileDialing.js +2 -2
- package/source/helpers/checkNumberLength.js +40 -7
- package/source/helpers/checkNumberLength.test.js +54 -12
- package/source/helpers/extractCountryCallingCode.js +15 -10
- package/source/helpers/extractCountryCallingCode.test.js +3 -3
- package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +19 -8
- package/source/helpers/extractNationalNumber.js +15 -5
- package/source/helpers/extractNationalNumber.test.js +11 -2
- package/source/helpers/getCountryByCallingCode.js +2 -2
- package/source/helpers/getCountryByNationalNumber.js +27 -6
- package/source/helpers/matchesEntirely.js +4 -4
- package/source/isPossible.js +4 -4
- package/source/isPossible.test.js +11 -0
- package/source/isPossiblePhoneNumber.test.js +7 -0
- package/source/metadata.js +2 -2
- package/source/parse.js +9 -5
- package/source/parseIncompletePhoneNumber.js +7 -7
- package/source/parsePhoneNumber.test.js +17 -0
- package/source/validatePhoneNumberLength.js +1 -1
- package/runnable/metadata-update-and-push-and-pull-request.js +0 -47
- package/runnable/metadata-update-and-push.js +0 -30
- package/runnable/metadata-update-and-release.js +0 -36
- /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
|
-
|
|
8
|
+
createJsFileForJsonFile(path)
|
|
9
9
|
|
|
10
|
-
function
|
|
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
|
-
|
|
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
|
|
|
@@ -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
|
|
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(
|
|
45
|
+
fs.writeFileSync('./metadata.json', JSON.stringify(output, undefined, 3))
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
// Compress the generated metadata
|
|
52
|
-
fs.writeFileSync(
|
|
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
|
})
|
|
@@ -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
|
-
|
|
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(
|
|
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 !==
|
|
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 `
|
|
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(
|
|
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
|
|
4
|
+
const metadataFileOutputPath = process.argv[2]
|
|
5
|
+
const infoFileOutputPath = process.argv[3]
|
|
5
6
|
|
|
6
|
-
|
|
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(
|
|
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(
|
|
25
|
+
fs.writeFileSync(metadataFileOutputPath, xml)
|
|
18
26
|
}).catch((error) => {
|
|
19
27
|
console.error(error)
|
|
20
28
|
process.exit(1)
|