@homebridge/hap-client 2.0.2-beta.0 → 2.0.3-beta.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.
- package/.github/npm-version-script-esm.js +85 -0
- package/.github/workflows/beta-release.yml +4 -4
- package/.github/workflows/codeql-analysis.yml +3 -3
- package/.github/workflows/release.yml +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/eventedHttpClient/httpParser.d.ts +5 -15
- package/dist/eventedHttpClient/httpParser.d.ts.map +1 -0
- package/dist/eventedHttpClient/httpParser.js +39 -40
- package/dist/eventedHttpClient/httpParser.js.map +1 -1
- package/dist/eventedHttpClient/index.d.ts +10 -2
- package/dist/eventedHttpClient/index.d.ts.map +1 -0
- package/dist/eventedHttpClient/index.js +12 -17
- package/dist/eventedHttpClient/index.js.map +1 -1
- package/dist/hap-types.d.ts +1 -0
- package/dist/hap-types.d.ts.map +1 -0
- package/dist/hap-types.js +41 -44
- package/dist/hap-types.js.map +1 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -78
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +33 -13
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +1 -2
- package/dist/monitor.d.ts +7 -6
- package/dist/monitor.d.ts.map +1 -0
- package/dist/monitor.js +30 -30
- package/dist/monitor.js.map +1 -1
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +4 -8
- package/dist/uuid.js.map +1 -1
- package/eslint.config.js +57 -0
- package/package.json +32 -30
- package/scripts/gen-hap-types.ts +26 -22
- package/.eslintrc.json +0 -15
- package/.github/npm-version-script.js +0 -93
- package/scripts/test.ts +0 -9
package/dist/monitor.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const node_events_1 = require("node:events");
|
|
5
|
-
const eventedHttpClient_1 = require("./eventedHttpClient");
|
|
6
|
-
class HapMonitor extends node_events_1.EventEmitter {
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { createConnection, parseMessage } from './eventedHttpClient/index.js';
|
|
3
|
+
export class HapMonitor extends EventEmitter {
|
|
7
4
|
pin;
|
|
8
5
|
evInstances;
|
|
9
6
|
services;
|
|
@@ -21,35 +18,37 @@ class HapMonitor extends node_events_1.EventEmitter {
|
|
|
21
18
|
}
|
|
22
19
|
start() {
|
|
23
20
|
for (const instance of this.evInstances) {
|
|
24
|
-
instance.socket =
|
|
21
|
+
instance.socket = createConnection(instance, this.pin, { characteristics: instance.evCharacteristics });
|
|
25
22
|
this.debug(`[HapClient] [${instance.ipAddress}:${instance.port} (${instance.username})] Connected`);
|
|
26
23
|
instance.socket.on('data', (data) => {
|
|
27
|
-
const message =
|
|
24
|
+
const message = parseMessage(data);
|
|
28
25
|
if (message.statusCode === 401) {
|
|
29
26
|
if (this.logger) {
|
|
30
|
-
this.debug(`[HapClient] [${instance.ipAddress}:${instance.port} (${instance.username})] `
|
|
31
|
-
`${message.statusCode} ${message.statusMessage} - make sure Homebridge pin for this instance is set to ${this.pin}.`);
|
|
27
|
+
this.debug(`[HapClient] [${instance.ipAddress}:${instance.port} (${instance.username})] `
|
|
28
|
+
+ `${message.statusCode} ${message.statusMessage} - make sure Homebridge pin for this instance is set to ${this.pin}.`);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
if (message.protocol === 'EVENT') {
|
|
35
32
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
characteristic
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
if (message.body) {
|
|
34
|
+
const body = JSON.parse(message.body);
|
|
35
|
+
if (body.characteristics && body.characteristics.length) {
|
|
36
|
+
this.debug(`[HapClient] [${instance.ipAddress}:${instance.port} (${instance.username})] `
|
|
37
|
+
+ `Got Event: ${JSON.stringify(body.characteristics)}`);
|
|
38
|
+
const response = body.characteristics.map((c) => {
|
|
39
|
+
const services = this.services.filter(x => x.aid === c.aid && x.instance.username === instance.username);
|
|
40
|
+
const service = services.find(x => x.serviceCharacteristics.find(y => y.iid === c.iid));
|
|
41
|
+
if (service) {
|
|
42
|
+
const characteristic = service.serviceCharacteristics.find(x => x.iid === c.iid);
|
|
43
|
+
if (characteristic) {
|
|
44
|
+
characteristic.value = c.value;
|
|
45
|
+
service.values[characteristic.type] = c.value;
|
|
46
|
+
return service;
|
|
47
|
+
}
|
|
49
48
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
});
|
|
50
|
+
this.emit('service-update', response.filter((x) => x));
|
|
51
|
+
}
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
catch (e) {
|
|
@@ -80,14 +79,15 @@ class HapMonitor extends node_events_1.EventEmitter {
|
|
|
80
79
|
this.evInstances.push(newInstance);
|
|
81
80
|
}
|
|
82
81
|
const instance = this.evInstances.find(x => x.username === service.instance.username);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
instance.evCharacteristics.
|
|
82
|
+
if (instance?.evCharacteristics) {
|
|
83
|
+
for (const evCharacteristic of evCharacteristics) {
|
|
84
|
+
if (!instance.evCharacteristics.find(x => x.aid === service.aid && x.iid === evCharacteristic.iid)) {
|
|
85
|
+
instance.evCharacteristics.push({ aid: service.aid, iid: evCharacteristic.iid, ev: true });
|
|
86
|
+
}
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
|
-
exports.HapMonitor = HapMonitor;
|
|
93
93
|
//# sourceMappingURL=monitor.js.map
|
package/dist/monitor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor.js","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AC;IACH,CAAC;CACF"}
|
package/dist/uuid.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,WAEnC;AAGD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAiC,UAYjF"}
|
package/dist/uuid.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValid = isValid;
|
|
4
|
-
exports.toLongFormUUID = toLongFormUUID;
|
|
5
1
|
const VALID_UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6
|
-
function isValid(UUID) {
|
|
2
|
+
export function isValid(UUID) {
|
|
7
3
|
return VALID_UUID_REGEX.test(UUID);
|
|
8
4
|
}
|
|
9
5
|
const VALID_SHORT_REGEX = /^[0-9a-f]{1,8}$/i;
|
|
10
|
-
function toLongFormUUID(uuid, base = '-0000-1000-8000-0026BB765291') {
|
|
6
|
+
export function toLongFormUUID(uuid, base = '-0000-1000-8000-0026BB765291') {
|
|
11
7
|
if (isValid(uuid)) {
|
|
12
8
|
return uuid.toUpperCase();
|
|
13
9
|
}
|
|
14
10
|
if (!VALID_SHORT_REGEX.test(uuid)) {
|
|
15
11
|
throw new TypeError('uuid was not a valid UUID or short form UUID');
|
|
16
12
|
}
|
|
17
|
-
if (!isValid(
|
|
13
|
+
if (!isValid(`00000000${base}`)) {
|
|
18
14
|
throw new TypeError('base was not a valid base UUID');
|
|
19
15
|
}
|
|
20
|
-
return ((
|
|
16
|
+
return ((`00000000${uuid}`).substr(-8) + base).toUpperCase();
|
|
21
17
|
}
|
|
22
18
|
//# sourceMappingURL=uuid.js.map
|
package/dist/uuid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG,iEAAiE,CAAA;AAE1F,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACpC,CAAC;AACD,MAAM,iBAAiB,GAAG,kBAAkB,CAAA;AAE5C,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,IAAI,GAAG,8BAA8B;IAChF,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAA;IAC3B,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAA;IACrE,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAA;IACvD,CAAC;IAED,OAAO,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAA;AAC9D,CAAC"}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import antfu from '@antfu/eslint-config'
|
|
2
|
+
|
|
3
|
+
export default antfu({
|
|
4
|
+
ignores: ['dist', 'docs'],
|
|
5
|
+
jsx: false,
|
|
6
|
+
typescript: true,
|
|
7
|
+
formatters: {
|
|
8
|
+
markdown: true,
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
'curly': ['error', 'multi-line'],
|
|
12
|
+
'import/extensions': ['error', 'ignorePackages'],
|
|
13
|
+
'import/order': 0,
|
|
14
|
+
'jsdoc/check-alignment': 'error',
|
|
15
|
+
'jsdoc/check-line-alignment': 'error',
|
|
16
|
+
'no-undef': 'off', // Turn off no-undef for TypeScript, handled by TS itself
|
|
17
|
+
'perfectionist/sort-exports': 'error',
|
|
18
|
+
'perfectionist/sort-imports': [
|
|
19
|
+
'error',
|
|
20
|
+
{
|
|
21
|
+
groups: [
|
|
22
|
+
'builtin-type',
|
|
23
|
+
'external-type',
|
|
24
|
+
'internal-type',
|
|
25
|
+
['parent-type', 'sibling-type', 'index-type'],
|
|
26
|
+
'builtin',
|
|
27
|
+
'external',
|
|
28
|
+
'internal',
|
|
29
|
+
['parent', 'sibling', 'index'],
|
|
30
|
+
'object',
|
|
31
|
+
'unknown',
|
|
32
|
+
],
|
|
33
|
+
order: 'asc',
|
|
34
|
+
type: 'natural',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
'perfectionist/sort-named-exports': 'error',
|
|
38
|
+
'perfectionist/sort-named-imports': 'error',
|
|
39
|
+
'sort-imports': 0,
|
|
40
|
+
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
41
|
+
'style/quote-props': ['error', 'consistent-as-needed'],
|
|
42
|
+
'test/no-only-tests': 'error',
|
|
43
|
+
'unicorn/no-useless-spread': 'error',
|
|
44
|
+
'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
|
|
45
|
+
},
|
|
46
|
+
overrides: [
|
|
47
|
+
{
|
|
48
|
+
files: ['*.ts', '*.tsx'], // Apply to TypeScript files only
|
|
49
|
+
env: {
|
|
50
|
+
node: true, // Enables Node.js global variables and type definitions
|
|
51
|
+
},
|
|
52
|
+
parserOptions: {
|
|
53
|
+
project: './tsconfig.json', // Directs ESLint to use your TypeScript config
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
})
|
package/package.json
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebridge/hap-client",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.3-beta.0",
|
|
4
5
|
"description": "A client for HAP-NodeJS.",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"check": "npm install && npm outdated",
|
|
8
|
-
"lint": "eslint src/**.ts",
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"gen": "ts-node -P tsconfig.gen.json scripts/gen-hap-types.ts",
|
|
11
|
-
"prepublishOnly": "npm run lint && npm run build",
|
|
12
|
-
"clean": "rimraf ./dist",
|
|
13
|
-
"test": "eslint src/**.ts"
|
|
14
|
-
},
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/homebridge/hap-client.git"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"hap",
|
|
22
|
-
"homebridge",
|
|
23
|
-
"api"
|
|
24
|
-
],
|
|
25
6
|
"author": {
|
|
26
7
|
"name": "oznu",
|
|
27
8
|
"email": "dev@oz.nu"
|
|
@@ -33,28 +14,49 @@
|
|
|
33
14
|
}
|
|
34
15
|
],
|
|
35
16
|
"license": "MIT",
|
|
17
|
+
"homepage": "https://github.com/homebridge/hap-client/blob/latest#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/homebridge/hap-client.git"
|
|
21
|
+
},
|
|
36
22
|
"bugs": {
|
|
37
23
|
"url": "https://github.com/homebridge/hap-client/issues/"
|
|
38
24
|
},
|
|
39
|
-
"
|
|
25
|
+
"keywords": [
|
|
26
|
+
"hap",
|
|
27
|
+
"homebridge",
|
|
28
|
+
"api"
|
|
29
|
+
],
|
|
30
|
+
"exports": "./dist/index.js",
|
|
31
|
+
"types": "dist/index.d.ts",
|
|
40
32
|
"engines": {
|
|
41
33
|
"node": "^18 || ^20 || ^22"
|
|
42
34
|
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"check": "npm install && npm outdated",
|
|
38
|
+
"clean": "rimraf dist && rimraf coverage",
|
|
39
|
+
"gen": "node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/gen-hap-types.ts",
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"lint:fix": "npm run lint -- --fix",
|
|
42
|
+
"prepublishOnly": "npm run lint && npm run build",
|
|
43
|
+
"test": "echo \"Error: no test specified\" && exit 0"
|
|
44
|
+
},
|
|
43
45
|
"dependencies": {
|
|
44
|
-
"axios": "1.7.
|
|
46
|
+
"axios": "1.7.7",
|
|
45
47
|
"bonjour-service": "1.2.1",
|
|
46
|
-
"decamelize": "
|
|
48
|
+
"decamelize": "^6.0.0",
|
|
47
49
|
"inflection": "3.0.0",
|
|
48
50
|
"source-map-support": "0.5.21"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@
|
|
53
|
+
"@antfu/eslint-config": "^3.0.0",
|
|
54
|
+
"@types/node": "^22.8.2",
|
|
52
55
|
"@types/source-map-support": "^0.5.10",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"hap-nodejs": "^1.1.1-beta.0",
|
|
56
|
+
"eslint": "^9.9.1",
|
|
57
|
+
"eslint-plugin-format": "^0.1.2",
|
|
58
|
+
"hap-nodejs": "^1.1.1-alpha.21",
|
|
59
|
+
"rimraf": "^6.0.1",
|
|
58
60
|
"ts-node": "^10.9.2",
|
|
59
61
|
"typescript": "^5.5.4"
|
|
60
62
|
}
|
package/scripts/gen-hap-types.ts
CHANGED
|
@@ -1,62 +1,66 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
1
|
+
import { writeFileSync } from 'node:fs'
|
|
2
|
+
import { dirname, resolve } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
3
4
|
|
|
4
|
-
import
|
|
5
|
+
import * as hapNodeJs from 'hap-nodejs'
|
|
6
|
+
|
|
7
|
+
const { Characteristic, Service, Categories } = hapNodeJs
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
5
9
|
|
|
6
10
|
/** Generate Service Types */
|
|
7
11
|
|
|
8
12
|
let Services = [
|
|
9
13
|
'export const Services = {',
|
|
10
|
-
] as any
|
|
14
|
+
] as any
|
|
11
15
|
|
|
12
|
-
const uuidMap = new Map()
|
|
16
|
+
const uuidMap = new Map()
|
|
13
17
|
|
|
14
18
|
for (const [name, value] of Object.entries(Service)) {
|
|
15
19
|
if (value.UUID) {
|
|
16
20
|
if (!uuidMap.has(value.UUID)) {
|
|
17
21
|
// If the UUID does not exist, add a new entry
|
|
18
|
-
Services.push(`
|
|
19
|
-
uuidMap.set(value.UUID, Services.length - 1)
|
|
22
|
+
Services.push(` '${value.UUID}': '${name}',`)
|
|
23
|
+
uuidMap.set(value.UUID, Services.length - 1)
|
|
20
24
|
}
|
|
21
|
-
Services.push(`
|
|
25
|
+
Services.push(` '${name}': '${value.UUID}',`)
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
Services.push(`}
|
|
26
|
-
Services = Services.join('\n')
|
|
29
|
+
Services.push(`}\n\n`)
|
|
30
|
+
Services = Services.join('\n')
|
|
27
31
|
|
|
28
32
|
/** Generate Characteristic Types */
|
|
29
33
|
|
|
30
34
|
let Characteristics = [
|
|
31
35
|
'export const Characteristics = {',
|
|
32
|
-
] as any
|
|
36
|
+
] as any
|
|
33
37
|
|
|
34
38
|
for (const [name, value] of Object.entries(Characteristic)) {
|
|
35
39
|
if (value.UUID) {
|
|
36
|
-
Characteristics.push(`
|
|
37
|
-
Characteristics.push(`
|
|
40
|
+
Characteristics.push(` '${value.UUID}': '${name}',`)
|
|
41
|
+
Characteristics.push(` '${name}': '${value.UUID}',`)
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
Characteristics.push(`}
|
|
42
|
-
Characteristics = Characteristics.join('\n')
|
|
45
|
+
Characteristics.push(`}\n\n`)
|
|
46
|
+
Characteristics = Characteristics.join('\n')
|
|
43
47
|
|
|
44
48
|
/** Generate Category Types */
|
|
45
49
|
|
|
46
50
|
let Category = [
|
|
47
51
|
'export const Categories = {',
|
|
48
|
-
] as any
|
|
52
|
+
] as any
|
|
49
53
|
|
|
50
|
-
// @ts-
|
|
54
|
+
// @ts-expect-error - const enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query
|
|
51
55
|
for (const [name, value] of Object.entries(Categories)) {
|
|
52
56
|
if (typeof value === 'number') {
|
|
53
|
-
Category.push(`
|
|
57
|
+
Category.push(` ${name}: ${value},`)
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
Category.push(`}
|
|
58
|
-
Category = Category.join('\n')
|
|
61
|
+
Category.push(`}\n`)
|
|
62
|
+
Category = Category.join('\n')
|
|
59
63
|
|
|
60
|
-
const out = `/* This file is automatically generated */\n\n
|
|
64
|
+
const out = `/* This file is automatically generated */\n\n${Services}${Characteristics}${Category}`
|
|
61
65
|
|
|
62
|
-
writeFileSync(resolve(__dirname, '../src/hap-types.ts'), out, 'utf8')
|
|
66
|
+
writeFileSync(resolve(__dirname, '../src/hap-types.ts'), out, 'utf8')
|
package/.eslintrc.json
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This scripts queries the npm registry to pull out the latest version for a given tag.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require("fs");
|
|
8
|
-
const semver = require("semver");
|
|
9
|
-
const child_process = require("child_process");
|
|
10
|
-
const assert = require("assert");
|
|
11
|
-
|
|
12
|
-
const BRANCH_VERSION_PATTERN = /^([A-Za-z]*)-(\d+.\d+.\d+)$/
|
|
13
|
-
|
|
14
|
-
// Load the contents of the package.json file
|
|
15
|
-
const packageJSON = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
16
|
-
|
|
17
|
-
let refArgument = process.argv[2];
|
|
18
|
-
let tagArgument = process.argv[3] || "latest";
|
|
19
|
-
|
|
20
|
-
if (refArgument == null) {
|
|
21
|
-
console.error("ref argument is missing");
|
|
22
|
-
console.error("Usage: npm-version-script.js <ref> [tag]");
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Queries the NPM registry for the latest version for the provided tag.
|
|
28
|
-
* @param tag The tag to query for.
|
|
29
|
-
* @returns {string} Returns the version.
|
|
30
|
-
*/
|
|
31
|
-
function getTagVersionFromNpm(tag) {
|
|
32
|
-
try {
|
|
33
|
-
return child_process.execSync(`npm info ${packageJSON.name} version --tag="${tag}"`).toString("utf8").trim();
|
|
34
|
-
} catch (e) {
|
|
35
|
-
console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`);
|
|
36
|
-
// throw e;
|
|
37
|
-
return "0.0.0";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function desiredTargetVersion(ref) {
|
|
42
|
-
// ref is a GitHub action ref string
|
|
43
|
-
if (ref.startsWith("refs/pull/")) {
|
|
44
|
-
throw Error("The version script was executed inside a PR!");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
assert(ref.startsWith("refs/heads/"))
|
|
48
|
-
let branchName = ref.slice("refs/heads/".length);
|
|
49
|
-
|
|
50
|
-
let results = branchName.match(BRANCH_VERSION_PATTERN);
|
|
51
|
-
if (results != null) {
|
|
52
|
-
if (results[1] !== tagArgument) {
|
|
53
|
-
console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return results[2];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// legacy mode were we use the `betaVersion` property in the package.json
|
|
60
|
-
if (branchName === "beta" && packageJSON.betaVersion) {
|
|
61
|
-
return packageJSON.betaVersion
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// legacy mode were we use the `alphaVersion` property in the package.json
|
|
65
|
-
if (branchName === "alpha" && packageJSON.alphaVersion) {
|
|
66
|
-
return packageJSON.alphaVersion
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// derive the base version from the branch ref
|
|
73
|
-
const baseVersion = desiredTargetVersion(refArgument);
|
|
74
|
-
|
|
75
|
-
// query the npm registry for the latest version of the provided tag name
|
|
76
|
-
const latestReleasedVersion = getTagVersionFromNpm(tagArgument); // e.g. 0.7.0-beta.12
|
|
77
|
-
const latestReleaseBase = semver.inc(latestReleasedVersion, "patch"); // will produce 0.7.0 (removing the preid, needed for the equality check below)
|
|
78
|
-
|
|
79
|
-
let publishTag;
|
|
80
|
-
if (semver.eq(baseVersion, latestReleaseBase)) { // check if we are releasing another version for the latest beta or alpha
|
|
81
|
-
publishTag = latestReleasedVersion; // set the current latest beta or alpha to be incremented
|
|
82
|
-
} else {
|
|
83
|
-
publishTag = baseVersion; // start of with a new beta or alpha version
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// save the package.json
|
|
87
|
-
packageJSON.version = publishTag;
|
|
88
|
-
fs.writeFileSync("package.json", JSON.stringify(packageJSON, null, 2));
|
|
89
|
-
|
|
90
|
-
// perform the same change to the package-lock.json
|
|
91
|
-
const packageLockJSON = JSON.parse(fs.readFileSync("package-lock.json", "utf8"));
|
|
92
|
-
packageLockJSON.version = publishTag;
|
|
93
|
-
fs.writeFileSync("package-lock.json", JSON.stringify(packageLockJSON, null, 2));
|