json-as 1.1.14-preview.1 → 1.1.14-preview.2
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/README.md +1 -1
- package/assembly/__tests__/array.spec.ts +6 -5
- package/assembly/__tests__/generics.spec.ts +32 -23
- package/assembly/__tests__/resolving.spec.ts +13 -5
- package/assembly/__tests__/types.spec.ts +3 -2
- package/assembly/deserialize/simple/array/raw.ts +1 -1
- package/assembly/test.ts +7 -1
- package/assembly/types.ts +26 -18
- package/package.json +23 -22
- package/publish.sh +78 -0
- package/transform/lib/builder.js.map +1 -1
- package/transform/lib/index.js +26 -50
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linkers/custom.js.map +1 -1
- package/transform/src/builder.ts +1 -1
- package/transform/src/index.ts +258 -297
- package/transform/src/linkers/alias.ts +1 -2
- package/transform/src/linkers/classes.ts +1 -1
- package/transform/src/linkers/custom.ts +26 -26
- package/transform/src/types.ts +1 -1
- package/assembly/test.json.ts +0 -388
package/README.md
CHANGED
|
@@ -106,14 +106,14 @@ describe("Should deserialize raw arrays", () => {
|
|
|
106
106
|
expect(r2[0][1].toString()).toBe('{"x":3.4,"y":-2.1,"z":9.3}');
|
|
107
107
|
expect(r2[1][0].toString()).toBe('{"x":0.1,"y":-7.3,"z":4.5}');
|
|
108
108
|
|
|
109
|
-
const r3 = JSON.parse<JSON.Raw[]>(
|
|
109
|
+
const r3 = JSON.parse<JSON.Raw[]>("[1,2,3,4,5]");
|
|
110
110
|
expect(r3[0]).toBe(1);
|
|
111
111
|
expect(r3[1]).toBe(2);
|
|
112
112
|
expect(r3[2]).toBe(3);
|
|
113
113
|
expect(r3[3]).toBe(4);
|
|
114
114
|
expect(r3[4]).toBe(5);
|
|
115
115
|
|
|
116
|
-
const r4 = JSON.parse<JSON.Raw[][]>(
|
|
116
|
+
const r4 = JSON.parse<JSON.Raw[][]>("[[1,2,3,4,5],[6,7,8,9,10]]");
|
|
117
117
|
expect(r4[0][0]).toBe(1);
|
|
118
118
|
expect(r4[0][1]).toBe(2);
|
|
119
119
|
expect(r4[0][2]).toBe(3);
|
|
@@ -125,17 +125,18 @@ describe("Should deserialize raw arrays", () => {
|
|
|
125
125
|
expect(r4[1][2]).toBe(8);
|
|
126
126
|
expect(r4[1][3]).toBe(9);
|
|
127
127
|
expect(r4[1][4]).toBe(10);
|
|
128
|
-
|
|
128
|
+
|
|
129
129
|
const r5 = JSON.parse<JSON.Raw[]>('[{"x":3.4,"y":1.2,"z":8.3},[1,2,3,4,5],"12345",true,false,null,[[]]]');
|
|
130
130
|
expect(r5[0].toString()).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
131
|
-
expect(r5[1].toString()).toBe(
|
|
131
|
+
expect(r5[1].toString()).toBe("[1,2,3,4,5]");
|
|
132
132
|
expect(r5[2]).toBe('"12345"');
|
|
133
133
|
expect(r5[3]).toBe(true);
|
|
134
134
|
expect(r5[4]).toBe(false);
|
|
135
135
|
expect(r5[5]).toBe(null);
|
|
136
|
-
expect(r5[6].toString()).toBe(
|
|
136
|
+
expect(r5[6].toString()).toBe("[[]]");
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
+
|
|
139
140
|
@json
|
|
140
141
|
class Vec3 {
|
|
141
142
|
x: f64 = 0.0;
|
|
@@ -1,40 +1,49 @@
|
|
|
1
1
|
import { JSON } from "..";
|
|
2
2
|
import { describe, expect } from "./lib";
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@json
|
|
5
6
|
class GenericTest<T> {
|
|
6
|
-
|
|
7
|
+
public foo: T;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
constructor(foo: T) {
|
|
10
|
+
this.foo = foo;
|
|
11
|
+
}
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
|
|
13
15
|
@json
|
|
14
16
|
class Vec3 {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
public x!: i32;
|
|
18
|
+
public y!: i32;
|
|
19
|
+
public z!: i32;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
describe("Should serialize generics", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
expect(JSON.stringify(new GenericTest<string>("bar"))).toBe('{"foo":"bar"}');
|
|
24
|
+
expect(JSON.stringify(new GenericTest<i32>(42))).toBe('{"foo":42}');
|
|
25
|
+
expect(JSON.stringify(new GenericTest<boolean>(true))).toBe('{"foo":true}');
|
|
26
|
+
expect(JSON.stringify(new GenericTest<Vec3>({ x: 1, y: 2, z: 3 }))).toBe('{"foo":{"x":1,"y":2,"z":3}}');
|
|
27
|
+
expect(JSON.stringify(new GenericTest<string[]>(["item1", "item2"]))).toBe('{"foo":["item1","item2"]}');
|
|
28
|
+
expect(
|
|
29
|
+
JSON.stringify(
|
|
30
|
+
new GenericTest<Vec3[]>([
|
|
31
|
+
{ x: 1, y: 2, z: 3 },
|
|
32
|
+
{ x: 4, y: 5, z: 6 },
|
|
33
|
+
]),
|
|
34
|
+
),
|
|
35
|
+
).toBe('{"foo":[{"x":1,"y":2,"z":3},{"x":4,"y":5,"z":6}]}');
|
|
36
|
+
expect(JSON.stringify(new GenericTest<i32[]>([1, 2, 3]))).toBe('{"foo":[1,2,3]}');
|
|
37
|
+
expect(JSON.stringify(new GenericTest<boolean[]>([true, false, true]))).toBe('{"foo":[true,false,true]}');
|
|
29
38
|
});
|
|
30
39
|
|
|
31
40
|
describe("Should deserialize generics", () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
expect(JSON.parse<GenericTest<string>>('{"foo":"bar"}').foo).toBe("bar");
|
|
42
|
+
expect(JSON.parse<GenericTest<i32>>('{"foo":42}').foo.toString()).toBe("42");
|
|
43
|
+
expect(JSON.parse<GenericTest<boolean>>('{"foo":true}').foo).toBe(true);
|
|
44
|
+
expect(JSON.stringify(JSON.parse<GenericTest<Vec3>>('{"foo":{"x":1,"y":2,"z":3}}'))).toBe('{"foo":{"x":1,"y":2,"z":3}}');
|
|
45
|
+
expect(JSON.stringify(JSON.parse<GenericTest<string[]>>('{"foo":["item1","item2"]}'))).toBe('{"foo":["item1","item2"]}');
|
|
46
|
+
expect(JSON.stringify(JSON.parse<GenericTest<Vec3[]>>('{"foo":[{"x":1,"y":2,"z":3},{"x":4,"y":5,"z":6}]}'))).toBe('{"foo":[{"x":1,"y":2,"z":3},{"x":4,"y":5,"z":6}]}');
|
|
47
|
+
expect(JSON.stringify(JSON.parse<GenericTest<i32[]>>('{"foo":[1,2,3]}'))).toBe('{"foo":[1,2,3]}');
|
|
48
|
+
expect(JSON.stringify(JSON.parse<GenericTest<boolean[]>>('{"foo":[true,false,true]}'))).toBe('{"foo":[true,false,true]}');
|
|
40
49
|
});
|
|
@@ -2,14 +2,20 @@ import { JSON } from "..";
|
|
|
2
2
|
import { describe, expect } from "./lib";
|
|
3
3
|
import { Vec3 } from "./types";
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
@json
|
|
6
7
|
class Player {
|
|
8
|
+
|
|
7
9
|
@alias("first name")
|
|
8
10
|
firstName!: string;
|
|
9
11
|
lastName!: string;
|
|
10
12
|
lastActive!: i32[];
|
|
13
|
+
|
|
14
|
+
|
|
11
15
|
@omitif((self: Player) => self.age < 18)
|
|
12
16
|
age!: i32;
|
|
17
|
+
|
|
18
|
+
|
|
13
19
|
@omitnull()
|
|
14
20
|
pos!: Vec3 | null;
|
|
15
21
|
isVerified!: boolean;
|
|
@@ -28,20 +34,22 @@ const player: Player = {
|
|
|
28
34
|
isVerified: true,
|
|
29
35
|
};
|
|
30
36
|
|
|
37
|
+
|
|
31
38
|
@json
|
|
32
39
|
class Foo {
|
|
33
|
-
|
|
40
|
+
bar: Bar = new Bar();
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
|
|
36
44
|
@json
|
|
37
45
|
class Bar {
|
|
38
|
-
|
|
46
|
+
baz: string = "buz";
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
describe("Should resolve imported schemas", () => {
|
|
42
|
-
|
|
50
|
+
expect(JSON.stringify(player)).toBe('{"age":18,"pos":{"x":3.4,"y":1.2,"z":8.3},"first name":"Jairus","lastName":"Tanaka","lastActive":[3,9,2025],"isVerified":true}');
|
|
43
51
|
});
|
|
44
52
|
|
|
45
53
|
describe("Should resolve local schemas", () => {
|
|
46
|
-
|
|
47
|
-
});
|
|
54
|
+
expect(JSON.stringify(new Foo())).toBe('{"bar":{"baz":"buz"}}');
|
|
55
|
+
});
|
|
@@ -7,6 +7,7 @@ type StringAlias2 = StringAlias1;
|
|
|
7
7
|
type StringAlias3 = StringAlias2;
|
|
8
8
|
type StringAlias4 = StringAlias3;
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
@json
|
|
11
12
|
class Alias {
|
|
12
13
|
public foo: StringAlias4 = "";
|
|
@@ -18,9 +19,9 @@ class Alias {
|
|
|
18
19
|
const alias = new Alias("bar");
|
|
19
20
|
|
|
20
21
|
describe("Should serialize with type aliases", () => {
|
|
21
|
-
|
|
22
|
+
expect(JSON.stringify(alias)).toBe('{"foo":"bar"}');
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
describe("Should deserialize with type aliases", () => {
|
|
25
|
-
|
|
26
|
+
expect(JSON.stringify(JSON.parse<Alias>('{"foo":"bar"}'))).toBe('{"foo":"bar"}');
|
|
26
27
|
});
|
|
@@ -99,7 +99,7 @@ export function deserializeRawArray(srcStart: usize, srcEnd: usize, dst: usize):
|
|
|
99
99
|
} else if (isSpace(code)) {
|
|
100
100
|
srcStart += 2;
|
|
101
101
|
} else {
|
|
102
|
-
throw new Error("Unexpected character in JSON object '" + String.fromCharCode(code) + "' at position " + (srcEnd - srcStart).toString() + " " + ptrToStr(lastIndex, srcStart+10));
|
|
102
|
+
throw new Error("Unexpected character in JSON object '" + String.fromCharCode(code) + "' at position " + (srcEnd - srcStart).toString() + " " + ptrToStr(lastIndex, srcStart + 10));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
return out;
|
package/assembly/test.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { JSON } from ".";
|
|
2
2
|
import { Vec3 } from "./types";
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@json
|
|
5
6
|
class Player {
|
|
7
|
+
|
|
6
8
|
@alias("first name")
|
|
7
9
|
firstName!: string;
|
|
8
10
|
lastName!: string;
|
|
9
11
|
lastActive!: i32[];
|
|
12
|
+
|
|
13
|
+
|
|
10
14
|
@omitif((self: Player) => self.age < 18)
|
|
11
15
|
age!: i32;
|
|
16
|
+
|
|
17
|
+
|
|
12
18
|
@omitnull()
|
|
13
19
|
pos!: Vec3 | null;
|
|
14
20
|
isVerified!: boolean;
|
|
@@ -30,4 +36,4 @@ const player: Player = {
|
|
|
30
36
|
const serialized = JSON.stringify(player);
|
|
31
37
|
console.log("Serialized: " + serialized);
|
|
32
38
|
const deserialized = JSON.parse<Player>(serialized);
|
|
33
|
-
console.log("Deserialized: " + JSON.stringify(deserialized))
|
|
39
|
+
console.log("Deserialized: " + JSON.stringify(deserialized));
|
package/assembly/types.ts
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
import { JSON } from "."
|
|
1
|
+
import { JSON } from ".";
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
@json
|
|
4
5
|
export class GenericEnum<T> {
|
|
5
|
-
private tag: string = ""
|
|
6
|
-
private value: T | null = null
|
|
6
|
+
private tag: string = "";
|
|
7
|
+
private value: T | null = null;
|
|
7
8
|
|
|
8
9
|
constructor() {
|
|
9
|
-
this.tag = ""
|
|
10
|
-
this.value = null
|
|
10
|
+
this.tag = "";
|
|
11
|
+
this.value = null;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
static create<T>(tag: string, value: T): GenericEnum<T> {
|
|
14
|
-
const item = new GenericEnum<T>()
|
|
15
|
-
item.tag = tag
|
|
16
|
-
item.value = value
|
|
17
|
-
return item
|
|
15
|
+
const item = new GenericEnum<T>();
|
|
16
|
+
item.tag = tag;
|
|
17
|
+
item.value = value;
|
|
18
|
+
return item;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
getTag(): string {
|
|
21
|
-
return this.tag
|
|
22
|
+
return this.tag;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
getValue(): T | null {
|
|
25
|
-
return this.value
|
|
26
|
+
return this.value;
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
|
|
27
30
|
@serializer
|
|
28
31
|
serialize<T>(self: GenericEnum<T>): string {
|
|
29
32
|
const tagJson = JSON.stringify(self.tag);
|
|
30
33
|
const valueJson = JSON.stringify(self.value);
|
|
31
|
-
return `{${tagJson}:${valueJson}}
|
|
34
|
+
return `{${tagJson}:${valueJson}}`;
|
|
32
35
|
}
|
|
36
|
+
|
|
37
|
+
|
|
33
38
|
@deserializer
|
|
34
39
|
deserialize(data: string): GenericEnum<T> {
|
|
35
40
|
const parsed = JSON.parse<Map<string, JSON.Raw>>(data);
|
|
@@ -45,19 +50,21 @@ export class GenericEnum<T> {
|
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
|
|
48
54
|
@json
|
|
49
55
|
export class Node<T> {
|
|
50
|
-
name: string
|
|
51
|
-
id: u32
|
|
52
|
-
data: T
|
|
56
|
+
name: string;
|
|
57
|
+
id: u32;
|
|
58
|
+
data: T;
|
|
53
59
|
|
|
54
60
|
constructor() {
|
|
55
|
-
this.name = ""
|
|
56
|
-
this.id = 0
|
|
61
|
+
this.name = "";
|
|
62
|
+
this.id = 0;
|
|
57
63
|
this.data = changetype<T>(0);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
|
|
61
68
|
@json
|
|
62
69
|
export class Vec3 {
|
|
63
70
|
x: f32 = 0.0;
|
|
@@ -65,5 +72,6 @@ export class Vec3 {
|
|
|
65
72
|
z: f32 = 0.0;
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
|
|
68
76
|
@json
|
|
69
|
-
export class Point {
|
|
77
|
+
export class Point {}
|
package/package.json
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "1.1.14-preview.
|
|
3
|
+
"version": "1.1.14-preview.2",
|
|
4
4
|
"author": "Jairus Tanaka",
|
|
5
|
-
"description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
|
|
6
|
-
"types": "assembly/index.ts",
|
|
7
|
-
"main": "transform/lib/index.js",
|
|
8
|
-
"homepage": "https://github.com/JairusSW/json-as#readme",
|
|
9
|
-
"license": "MIT",
|
|
10
5
|
"repository": {
|
|
11
6
|
"type": "git",
|
|
12
7
|
"url": "git+https://github.com/JairusSW/json-as.git"
|
|
13
8
|
},
|
|
14
|
-
"
|
|
15
|
-
"url": "https://github.com/JairusSW/json-as/issues"
|
|
16
|
-
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"ci": "act",
|
|
19
|
-
"test": "bash ./run-tests.sh",
|
|
20
|
-
"bench:as": "bash ./run-bench.as.sh",
|
|
21
|
-
"bench:js": "bash ./run-bench.js.sh",
|
|
22
|
-
"build:test": "rm -rf ./build/ && JSON_DEBUG=1 JSON_WRITE=assembly/test.ts asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --debug --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
|
|
23
|
-
"test:wasmtime": "wasmtime ./build/test.wasm",
|
|
24
|
-
"test:wasmer": "wasmer ./build/test.wasm",
|
|
25
|
-
"build:transform": "tsc -p ./transform",
|
|
26
|
-
"bench:wasmer": "wasmer ./build/bench.wasm --llvm",
|
|
27
|
-
"prettier": "prettier -w ."
|
|
28
|
-
},
|
|
9
|
+
"main": "transform/lib/index.js",
|
|
29
10
|
"devDependencies": {
|
|
30
11
|
"@assemblyscript/wasi-shim": "^0.1.0",
|
|
31
12
|
"@types/node": "^22.15.24",
|
|
@@ -35,6 +16,9 @@
|
|
|
35
16
|
"tsx": "^4.19.4",
|
|
36
17
|
"typescript": "^5.8.3"
|
|
37
18
|
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/JairusSW/json-as/issues"
|
|
21
|
+
},
|
|
38
22
|
"contributors": [
|
|
39
23
|
"DogWhich",
|
|
40
24
|
"Romdotdog",
|
|
@@ -47,6 +31,8 @@
|
|
|
47
31
|
"Loredana Cirstea",
|
|
48
32
|
"Accipiter Nisus"
|
|
49
33
|
],
|
|
34
|
+
"description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
|
|
35
|
+
"homepage": "https://github.com/JairusSW/json-as#readme",
|
|
50
36
|
"keywords": [
|
|
51
37
|
"assemblyscript",
|
|
52
38
|
"json",
|
|
@@ -62,8 +48,23 @@
|
|
|
62
48
|
"fast",
|
|
63
49
|
"algorithm"
|
|
64
50
|
],
|
|
51
|
+
"license": "MIT",
|
|
65
52
|
"publishConfig": {
|
|
66
53
|
"@JairusSW:registry": "https://npm.pkg.github.com"
|
|
67
54
|
},
|
|
68
|
-
"
|
|
55
|
+
"scripts": {
|
|
56
|
+
"ci": "act",
|
|
57
|
+
"test": "bash ./run-tests.sh",
|
|
58
|
+
"bench:as": "bash ./run-bench.as.sh",
|
|
59
|
+
"bench:js": "bash ./run-bench.js.sh",
|
|
60
|
+
"build:test": "rm -rf ./build/ && JSON_DEBUG=1 JSON_WRITE=assembly/test.ts asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --debug --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
|
|
61
|
+
"test:wasmtime": "wasmtime ./build/test.wasm",
|
|
62
|
+
"test:wasmer": "wasmer ./build/test.wasm",
|
|
63
|
+
"build:transform": "tsc -p ./transform",
|
|
64
|
+
"bench:wasmer": "wasmer ./build/bench.wasm --llvm",
|
|
65
|
+
"format": "prettier -w .",
|
|
66
|
+
"publish": "bash ./publish.sh"
|
|
67
|
+
},
|
|
68
|
+
"type": "module",
|
|
69
|
+
"types": "assembly/index.ts"
|
|
69
70
|
}
|
package/publish.sh
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
PACKAGE_NAME="json-as"
|
|
6
|
+
|
|
7
|
+
echo -e "\n🔧 Building transform..."
|
|
8
|
+
if ! npm run build:transform; then
|
|
9
|
+
echo "❌ Build failed. Exiting."
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
read -r -p "✨ Do you want to format the code before publishing? [Y/n] " FORMAT_RESP
|
|
14
|
+
FORMAT_RESP=${FORMAT_RESP,,}
|
|
15
|
+
|
|
16
|
+
if [[ "$FORMAT_RESP" =~ ^(yes|y| ) || -z "$FORMAT_RESP" ]]; then
|
|
17
|
+
echo "🧹 Formatting code..."
|
|
18
|
+
npm run format
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
echo -e "\n🧪 Running tests"
|
|
22
|
+
if ! npm run test; then
|
|
23
|
+
echo "❌ Tests failed. Exiting."
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
28
|
+
echo -e "\n📦 Current version: $VERSION"
|
|
29
|
+
|
|
30
|
+
if [[ "$VERSION" == *"-preview."* ]]; then
|
|
31
|
+
TAG="preview"
|
|
32
|
+
elif [[ "$VERSION" == *"-"* ]]; then
|
|
33
|
+
echo "⚠️ Unknown pre-release format. Not publishing."
|
|
34
|
+
exit 1
|
|
35
|
+
else
|
|
36
|
+
TAG="latest"
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
echo ""
|
|
40
|
+
|
|
41
|
+
read -r -p "✅ All checks passed. Ready to publish $PACKAGE_NAME@$VERSION with tag '$TAG'? [Y/n] " PUBLISH_RESP
|
|
42
|
+
PUBLISH_RESP=${PUBLISH_RESP,,}
|
|
43
|
+
|
|
44
|
+
if [[ "$PUBLISH_RESP" =~ ^(n|no)$ ]]; then
|
|
45
|
+
echo "❌ Publish canceled by user. Exiting."
|
|
46
|
+
exit 0
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
echo -e "\n🚀 Publishing $PACKAGE_NAME@$VERSION with tag '$TAG'...\n"
|
|
50
|
+
npm publish --tag "$TAG"
|
|
51
|
+
echo -e "\n✅ Published successfully."
|
|
52
|
+
|
|
53
|
+
echo -e "\n🧹 Cleaning up old dist-tags..."
|
|
54
|
+
npm dist-tag rm "$PACKAGE_NAME" alpha 2>/dev/null || true
|
|
55
|
+
npm dist-tag rm "$PACKAGE_NAME" beta 2>/dev/null || true
|
|
56
|
+
|
|
57
|
+
echo ""
|
|
58
|
+
read -r -p "❓ Do you want to deprecate all alpha/beta versions? [Y/n] " DEPRECATE_RESP
|
|
59
|
+
DEPRECATE_RESP=${DEPRECATE_RESP,,}
|
|
60
|
+
|
|
61
|
+
if [[ "$DEPRECATE_RESP" =~ ^(n|no)$ ]]; then
|
|
62
|
+
echo -e "\n❌ Skipping deprecation."
|
|
63
|
+
else
|
|
64
|
+
echo -e "\n📦 Deprecating alpha/beta versions...\n"
|
|
65
|
+
|
|
66
|
+
VERSIONS=$(npm show "$PACKAGE_NAME" versions --json | jq -r '.[]')
|
|
67
|
+
|
|
68
|
+
for VER in $VERSIONS; do
|
|
69
|
+
if [[ "$VER" == *"alpha"* || "$VER" == *"beta"* ]]; then
|
|
70
|
+
echo "⚠️ Deprecating $PACKAGE_NAME@$VER..."
|
|
71
|
+
npm deprecate "$PACKAGE_NAME@$VER" "Deprecated: use latest or preview release."
|
|
72
|
+
fi
|
|
73
|
+
done
|
|
74
|
+
|
|
75
|
+
echo -e "\n✅ Deprecation complete."
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
echo -e "\n🎉 Done."
|