neonctl 1.28.0 → 1.29.1

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 (184) hide show
  1. package/.bump +1 -0
  2. package/.editorconfig +7 -0
  3. package/.eslintrc.cjs +15 -0
  4. package/.github/workflows/commitlint.yml +46 -0
  5. package/.github/workflows/pr.yml +25 -0
  6. package/.github/workflows/release.yml +30 -0
  7. package/.husky/commit-msg +4 -0
  8. package/.husky/pre-commit +4 -0
  9. package/.nvmrc +1 -0
  10. package/.prettierignore +3 -0
  11. package/.prettierrc.json +3 -0
  12. package/.releaserc.json +47 -0
  13. package/LICENSE +202 -0
  14. package/commitlint.config.cjs +7 -0
  15. package/generateOptionsFromSpec.ts +68 -0
  16. package/jest/setup.js +5 -0
  17. package/jest.config.ts +199 -0
  18. package/mocks/bin/psql.cjs +9 -0
  19. package/mocks/main/projects/GET.js +27 -0
  20. package/mocks/main/projects/POST.js +22 -0
  21. package/mocks/main/projects/shared/GET.js +16 -0
  22. package/mocks/main/projects/test/DELETE.json +7 -0
  23. package/mocks/main/projects/test/GET.json +13 -0
  24. package/mocks/main/projects/test/PATCH.js +18 -0
  25. package/mocks/main/projects/test/branches/GET.json +25 -0
  26. package/mocks/main/projects/test/branches/POST.js +83 -0
  27. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/DELETE.json +7 -0
  28. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/GET.json +9 -0
  29. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/PATCH.js +14 -0
  30. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/databases/GET.json +6 -0
  31. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/databases/POST.js +13 -0
  32. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/databases/test_db/DELETE.json +6 -0
  33. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/endpoints/GET.json +26 -0
  34. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/endpoints/POST.json +6 -0
  35. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/roles/GET.json +3 -0
  36. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/roles/POST.js +14 -0
  37. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/roles/test_role/DELETE.json +6 -0
  38. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/roles/test_role/reveal_password/GET.json +3 -0
  39. package/mocks/main/projects/test/branches/br-cloudy-branch-12345678/set_as_primary/POST.json +9 -0
  40. package/mocks/main/projects/test/branches/br-numbered-branch-123456/GET.json +10 -0
  41. package/mocks/main/projects/test/branches/br-sunny-branch-123456/DELETE.json +7 -0
  42. package/mocks/main/projects/test/branches/br-sunny-branch-123456/GET.json +10 -0
  43. package/mocks/main/projects/test/branches/br-sunny-branch-123456/PATCH.js +14 -0
  44. package/mocks/main/projects/test/branches/br-sunny-branch-123456/databases/GET.json +6 -0
  45. package/mocks/main/projects/test/branches/br-sunny-branch-123456/databases/POST.js +13 -0
  46. package/mocks/main/projects/test/branches/br-sunny-branch-123456/databases/test_db/DELETE.json +6 -0
  47. package/mocks/main/projects/test/branches/br-sunny-branch-123456/endpoints/GET.json +26 -0
  48. package/mocks/main/projects/test/branches/br-sunny-branch-123456/endpoints/POST.json +6 -0
  49. package/mocks/main/projects/test/branches/br-sunny-branch-123456/restore/POST.js +16 -0
  50. package/mocks/main/projects/test/branches/br-sunny-branch-123456/roles/GET.json +3 -0
  51. package/mocks/main/projects/test/branches/br-sunny-branch-123456/roles/POST.js +14 -0
  52. package/mocks/main/projects/test/branches/br-sunny-branch-123456/roles/test_role/DELETE.json +6 -0
  53. package/mocks/main/projects/test/branches/br-sunny-branch-123456/roles/test_role/reveal_password/GET.json +3 -0
  54. package/mocks/main/projects/test/branches/br-sunny-branch-123456/set_as_primary/POST.json +9 -0
  55. package/mocks/main/projects/test/endpoints/GET.json +9 -0
  56. package/mocks/main/projects/test/endpoints/POST.js +32 -0
  57. package/mocks/main/projects/test/endpoints/test_endpoint_id/DELETE.json +7 -0
  58. package/mocks/main/projects/test/endpoints/test_endpoint_id/GET.json +9 -0
  59. package/mocks/main/projects/test/endpoints/test_endpoint_id/PATCH.js +17 -0
  60. package/mocks/main/projects/test/operations/GET.json +22 -0
  61. package/mocks/main/users/me/GET.json +5 -0
  62. package/mocks/restore/projects/test/branches/GET.json +21 -0
  63. package/mocks/restore/projects/test/branches/br-another-branch-123456/GET.json +6 -0
  64. package/mocks/restore/projects/test/branches/br-another-branch-123456/restore/POST.js +13 -0
  65. package/mocks/restore/projects/test/branches/br-any-branch-123456/GET.json +6 -0
  66. package/mocks/restore/projects/test/branches/br-parent-tots-123456/GET.json +7 -0
  67. package/mocks/restore/projects/test/branches/br-parent-tots-123456/restore/POST.js +14 -0
  68. package/mocks/restore/projects/test/branches/br-self-tolsn-123456/GET.json +6 -0
  69. package/mocks/restore/projects/test/branches/br-self-tolsn-123456/restore/POST.js +15 -0
  70. package/mocks/single_project/projects/GET.json +10 -0
  71. package/mocks/single_project/projects/test-project-123456/GET.json +14 -0
  72. package/mocks/single_project/projects/test-project-123456/branches/GET.json +11 -0
  73. package/mocks/single_project/projects/test-project-123456/branches/br-main-branch-123456/databases/GET.json +3 -0
  74. package/mocks/single_project/projects/test-project-123456/branches/br-main-branch-123456/endpoints/GET.json +10 -0
  75. package/mocks/single_project/projects/test-project-123456/branches/br-main-branch-123456/roles/GET.json +3 -0
  76. package/mocks/single_project/projects/test-project-123456/branches/br-main-branch-123456/roles/test_role/reveal_password/GET.json +3 -0
  77. package/package.json +6 -5
  78. package/pkg.js +45 -3
  79. package/rollup.config.js +20 -0
  80. package/snapshots/commands/branches.test.snap +221 -0
  81. package/snapshots/commands/connection_string.test.snap +70 -0
  82. package/snapshots/commands/databases.test.snap +20 -0
  83. package/snapshots/commands/ip_allow.test.snap +55 -0
  84. package/snapshots/commands/operations.test.snap +17 -0
  85. package/snapshots/commands/projects.test.snap +141 -0
  86. package/snapshots/commands/roles.test.snap +19 -0
  87. package/snapshots/commands/set_context.test.snap +30 -0
  88. package/snapshots/writer.test.snap +60 -0
  89. package/snapshotsResolver.cjs +32 -0
  90. package/src/analytics.ts +95 -0
  91. package/src/api.ts +44 -0
  92. package/src/auth.ts +137 -0
  93. package/{cli.js → src/cli.ts} +1 -0
  94. package/src/commands/auth.test.ts +62 -0
  95. package/src/commands/auth.ts +148 -0
  96. package/src/commands/branches.test.ts +354 -0
  97. package/src/commands/branches.ts +451 -0
  98. package/src/commands/connection_string.test.ts +250 -0
  99. package/src/commands/connection_string.ts +210 -0
  100. package/src/commands/databases.test.ts +55 -0
  101. package/src/commands/databases.ts +129 -0
  102. package/src/commands/help.test.ts +13 -0
  103. package/{commands/index.js → src/commands/index.ts} +11 -10
  104. package/src/commands/ip_allow.test.ts +86 -0
  105. package/src/commands/ip_allow.ts +202 -0
  106. package/src/commands/operations.test.ts +13 -0
  107. package/src/commands/operations.ts +41 -0
  108. package/src/commands/projects.test.ts +147 -0
  109. package/src/commands/projects.ts +275 -0
  110. package/src/commands/roles.test.ts +46 -0
  111. package/src/commands/roles.ts +100 -0
  112. package/src/commands/set_context.test.ts +64 -0
  113. package/src/commands/set_context.ts +27 -0
  114. package/src/commands/user.ts +21 -0
  115. package/src/config.ts +22 -0
  116. package/src/context.ts +61 -0
  117. package/src/env.ts +7 -0
  118. package/src/errors.ts +24 -0
  119. package/src/help.ts +185 -0
  120. package/src/index.ts +180 -0
  121. package/src/log.ts +16 -0
  122. package/src/parameters.gen.ts +332 -0
  123. package/src/pkg.ts +9 -0
  124. package/src/test_utils/mock_server.ts +27 -0
  125. package/src/test_utils/oauth_server.ts +10 -0
  126. package/src/test_utils/test_cli_command.ts +117 -0
  127. package/src/types.ts +25 -0
  128. package/src/utils/enrichers.ts +73 -0
  129. package/src/utils/formats.test.ts +41 -0
  130. package/src/utils/formats.ts +11 -0
  131. package/src/utils/middlewares.ts +23 -0
  132. package/src/utils/point_in_time.ts +86 -0
  133. package/src/utils/psql.ts +29 -0
  134. package/src/utils/string.ts +8 -0
  135. package/src/utils/ui.ts +64 -0
  136. package/src/writer.test.ts +98 -0
  137. package/src/writer.ts +131 -0
  138. package/tsconfig.json +17 -0
  139. package/analytics.js +0 -78
  140. package/api.js +0 -35
  141. package/auth.js +0 -101
  142. package/commands/auth.js +0 -102
  143. package/commands/auth.test.js +0 -42
  144. package/commands/branches.js +0 -303
  145. package/commands/branches.test.js +0 -321
  146. package/commands/connection_string.js +0 -137
  147. package/commands/connection_string.test.js +0 -204
  148. package/commands/databases.js +0 -79
  149. package/commands/databases.test.js +0 -51
  150. package/commands/help.test.js +0 -11
  151. package/commands/ip_allow.js +0 -135
  152. package/commands/ip_allow.test.js +0 -78
  153. package/commands/operations.js +0 -28
  154. package/commands/operations.test.js +0 -11
  155. package/commands/projects.js +0 -170
  156. package/commands/projects.test.js +0 -132
  157. package/commands/roles.js +0 -57
  158. package/commands/roles.test.js +0 -42
  159. package/commands/set_context.js +0 -22
  160. package/commands/set_context.test.js +0 -53
  161. package/commands/user.js +0 -15
  162. package/config.js +0 -11
  163. package/context.js +0 -48
  164. package/env.js +0 -6
  165. package/errors.js +0 -16
  166. package/help.js +0 -146
  167. package/index.js +0 -168
  168. package/log.js +0 -15
  169. package/parameters.gen.js +0 -322
  170. package/test_utils/mock_server.js +0 -16
  171. package/test_utils/oauth_server.js +0 -9
  172. package/test_utils/test_cli_command.js +0 -80
  173. package/types.js +0 -1
  174. package/utils/enrichers.js +0 -49
  175. package/utils/formats.js +0 -5
  176. package/utils/formats.test.js +0 -32
  177. package/utils/middlewares.js +0 -20
  178. package/utils/point_in_time.js +0 -44
  179. package/utils/psql.js +0 -24
  180. package/utils/string.js +0 -5
  181. package/utils/ui.js +0 -59
  182. package/writer.js +0 -87
  183. package/writer.test.js +0 -86
  184. /package/{callback.html → src/callback.html} +0 -0
@@ -0,0 +1,26 @@
1
+ {
2
+ "endpoints": [
3
+ {
4
+ "host": "ep-cool-king-930914.us-east-2.aws.neon.tech",
5
+ "id": "ep-cool-king-930914",
6
+ "project_id": "test",
7
+ "branch_id": "br-sunny-branch-123456",
8
+ "type": "read_write",
9
+ "created_at": "2023-06-22T14:26:33Z",
10
+ "updated_at": "2023-06-30T04:07:32Z",
11
+ "proxy_host": "us-east-2.aws.neon.tech",
12
+ "provisioner": "k8s-pod"
13
+ },
14
+ {
15
+ "host": "ep-cool-king-933333.us-east-2.aws.neon.tech",
16
+ "id": "ep-cool-king-933333",
17
+ "project_id": "test",
18
+ "branch_id": "br-sunny-branch-123456",
19
+ "type": "read_only",
20
+ "created_at": "2023-06-22T14:26:33Z",
21
+ "updated_at": "2023-06-30T04:07:32Z",
22
+ "proxy_host": "us-east-2.aws.neon.tech",
23
+ "provisioner": "k8s-pod"
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "endpoint": {
3
+ "id": "ep-worthless-fish-123456",
4
+ "host": "localhost"
5
+ }
6
+ }
@@ -0,0 +1,16 @@
1
+ export default function (req, res) {
2
+ expect(req.body).toEqual({
3
+ source_branch_id: 'br-parent-branch-123456',
4
+ });
5
+ res.status(200).json({
6
+ branch: {
7
+ id: 'br-branch-123456',
8
+ name: 'test-branch',
9
+ source_branch_id: 'br-parent-branch-123456',
10
+ project_id: 'pr-project-123456',
11
+ created_at: '2020-01-01T00:00:00.000Z',
12
+ updated_at: '2020-01-01T00:00:00.000Z',
13
+ last_reset_at: '2020-01-01T00:00:00.000Z',
14
+ },
15
+ });
16
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "roles": [{ "name": "test_role", "created_at": "2016-01-01T00:00:00Z" }]
3
+ }
@@ -0,0 +1,14 @@
1
+ export default function (req, res) {
2
+ expect(req.body).toMatchObject({
3
+ role: {
4
+ name: 'test_role',
5
+ },
6
+ });
7
+
8
+ res.send({
9
+ role: {
10
+ name: 'test_role',
11
+ created_at: '2019-01-01T00:00:00.000Z',
12
+ },
13
+ });
14
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "role": {
3
+ "name": "test_role",
4
+ "created_at": "2016-11-16T15:39:18.000Z"
5
+ }
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "branch": {
3
+ "name": "test-branch-sunny",
4
+ "id": "br-sunny-branch-123456",
5
+ "primary": true,
6
+ "created_at": "2019-01-01T00:00:00Z",
7
+ "updated_at": "2019-01-01T00:00:00Z"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "endpoints": [
3
+ {
4
+ "id": "ep-test",
5
+ "created_at": "2019-01-01T00:00:00Z",
6
+ "type": "read_only"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,32 @@
1
+ let retries = 1;
2
+
3
+ export default function (req, res) {
4
+ if (!req.body) {
5
+ res.status(400).send('Missing body');
6
+ return;
7
+ }
8
+ if (req.body.endpoint.branch_id === 'test_branch_with_retry') {
9
+ if (retries > 0) {
10
+ retries -= 1;
11
+ res.status(423).send({ error: 'locked' });
12
+ return;
13
+ }
14
+ }
15
+
16
+ if (req.body.endpoint.branch_id === 'test_branch_id') {
17
+ expect(req.body).toMatchObject({
18
+ endpoint: {
19
+ type: 'read_only',
20
+ },
21
+ });
22
+ }
23
+
24
+ res.send({
25
+ endpoint: {
26
+ id: 'test_endpoint_id',
27
+ branch_id: req.body.endpoint.branch_id,
28
+ created_at: '2019-01-01T00:00:00Z',
29
+ type: req.body.endpoint.type,
30
+ },
31
+ });
32
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "endpoint": {
3
+ "id": "test_endpoint_id",
4
+ "type": "read_only",
5
+ "created_at": "2019-01-01T00:00:00Z"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "endpoint": {
3
+ "id": "test_endpoint_id",
4
+ "type": "read_only",
5
+ "created_at": "2019-01-01T00:00:00Z",
6
+ "branch_id": "test_branch_id",
7
+ "host": "test_host.neon.tech"
8
+ }
9
+ }
@@ -0,0 +1,17 @@
1
+ export default function (req, res) {
2
+ expect(req.body).toMatchObject({
3
+ endpoint: {
4
+ id: 'test_endpoint_id',
5
+ branch_id: 'test_branch_id',
6
+ },
7
+ });
8
+
9
+ res.send({
10
+ endpoint: {
11
+ id: 'test_endpoint_id',
12
+ branch_id: 'test_branch_id',
13
+ created_at: '2019-01-01T00:00:00Z',
14
+ type: 'read_only',
15
+ },
16
+ });
17
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "operations": [
3
+ {
4
+ "id": "1",
5
+ "action": "suspend",
6
+ "status": "finished",
7
+ "created_at": "2016-01-01T00:00:00Z"
8
+ },
9
+ {
10
+ "id": "2",
11
+ "action": "suspend",
12
+ "status": "finished",
13
+ "created_at": "2016-01-01T00:00:00Z"
14
+ },
15
+ {
16
+ "id": "3",
17
+ "action": "start",
18
+ "status": "finished",
19
+ "created_at": "2016-01-01T00:00:00Z"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "id": "1",
3
+ "name": "John Doe",
4
+ "email": "john@example.com"
5
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "branches": [
3
+ {
4
+ "id": "br-self-tolsn-123456",
5
+ "name": "self-tolsn-123456"
6
+ },
7
+ {
8
+ "id": "br-any-branch-123456",
9
+ "name": "any-branch"
10
+ },
11
+ {
12
+ "id": "br-parent-tots-123456",
13
+ "name": "parent-tots",
14
+ "parent_id": "br-any-branch-123456"
15
+ },
16
+ {
17
+ "id": "br-another-branch-123456",
18
+ "name": "another-branch"
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "branch": {
3
+ "id": "br-another-branch-123456",
4
+ "name": "another-branch"
5
+ }
6
+ }
@@ -0,0 +1,13 @@
1
+ export default function (req, res) {
2
+ expect(req.body).toMatchObject({
3
+ source_branch_id: 'br-any-branch-123456',
4
+ });
5
+
6
+ res.status(200).send({
7
+ branch: {
8
+ id: 'br-another-branch-123456',
9
+ name: 'another-branch',
10
+ last_reset_at: '2021-01-01T00:00:00Z',
11
+ },
12
+ });
13
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "branch": {
3
+ "id": "br-any-branch-123456",
4
+ "name": "any-branch"
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "branch": {
3
+ "id": "br-parent-tots-123456",
4
+ "name": "parent-tots",
5
+ "parent_id": "br-any-branch-123456"
6
+ }
7
+ }
@@ -0,0 +1,14 @@
1
+ export default function (req, res) {
2
+ expect(req.body).toMatchObject({
3
+ source_branch_id: 'br-any-branch-123456',
4
+ source_timestamp: '2021-01-01T00:00:00.000Z',
5
+ });
6
+
7
+ res.status(200).send({
8
+ branch: {
9
+ id: 'br-parent-tots-123456',
10
+ name: 'parent-tots',
11
+ last_reset_at: '2021-01-01T00:00:00Z',
12
+ },
13
+ });
14
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "branch": {
3
+ "id": "br-self-tolsn-123456",
4
+ "name": "self-tolsn-123456"
5
+ }
6
+ }
@@ -0,0 +1,15 @@
1
+ export default function (req, res) {
2
+ expect(req.body).toMatchObject({
3
+ source_branch_id: 'br-self-tolsn-123456',
4
+ source_lsn: '0/123ABC',
5
+ preserve_under_name: 'backup',
6
+ });
7
+
8
+ res.status(200).send({
9
+ branch: {
10
+ id: 'br-self-tolsn-123456',
11
+ name: 'self-tolsn',
12
+ last_reset_at: '2021-01-01T00:00:00Z',
13
+ },
14
+ });
15
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "projects": [
3
+ {
4
+ "id": "test-project-123456",
5
+ "name": "",
6
+ "created_at": "2019-01-01T00:00:00.000Z",
7
+ "updated_at": "2019-01-01T00:00:00.000Z"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "project": {
3
+ "id": "test-project-123456",
4
+ "name": "",
5
+ "created_at": "2019-01-01T00:00:00.000Z",
6
+ "updated_at": "2019-01-01T00:00:00.000Z",
7
+ "settings": {
8
+ "allowed_ips": {
9
+ "ips": ["192.168.1.1"],
10
+ "primary_branch_only": false
11
+ }
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "branches": [
3
+ {
4
+ "id": "br-main-branch-123456",
5
+ "name": "main",
6
+ "primary": true,
7
+ "created_at": "2021-01-01T00:00:00.000Z",
8
+ "updated_at": "2021-01-01T00:00:00.000Z"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "databases": [{ "name": "db1", "owner_name": "user1" }]
3
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "endpoints": [
3
+ {
4
+ "id": "ep-test-endpoint-123456",
5
+ "created_at": "2019-01-01T00:00:00Z",
6
+ "type": "read_write",
7
+ "branch_id": "br-main-branch-123456"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "roles": [{ "name": "test_role", "created_at": "2016-01-01T00:00:00Z" }]
3
+ }
package/package.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "name": "neonctl",
3
3
  "repository": {
4
4
  "type": "git",
5
- "url": "git@github.com:neondatabase/neonctl.git"
5
+ "url": "git+ssh://git@github.com/neondatabase/neonctl.git"
6
6
  },
7
7
  "type": "module",
8
- "version": "1.28.0",
8
+ "version": "1.29.1",
9
9
  "description": "CLI tool for NeonDB Cloud management",
10
10
  "main": "index.js",
11
11
  "author": "NeonDB",
@@ -46,7 +46,7 @@
46
46
  "pkg": "^5.8.1",
47
47
  "prettier": "^3.1.0",
48
48
  "rollup": "^3.26.2",
49
- "semantic-release": "^21.0.2",
49
+ "semantic-release": "^23.0.8",
50
50
  "strip-ansi": "^7.1.0",
51
51
  "ts-jest": "^29.1.0",
52
52
  "ts-node": "^10.9.1",
@@ -72,7 +72,8 @@
72
72
  },
73
73
  "pkg": {
74
74
  "assets": [
75
- "callback.html"
75
+ "callback.html",
76
+ "package.json"
76
77
  ],
77
78
  "scripts": [
78
79
  "bundle/*.js"
@@ -91,7 +92,7 @@
91
92
  "build": "npm run generateParams && npm run clean && tsc && cp src/*.html package*.json README.md ./dist",
92
93
  "clean": "rm -rf dist",
93
94
  "generateParams": "node --loader ts-node/esm ./generateOptionsFromSpec.ts",
94
- "start": "node src/index.js",
95
+ "start": "node dist/index.js",
95
96
  "pretest": "npm run build",
96
97
  "test": "node --experimental-vm-modules node_modules/.bin/jest",
97
98
  "prepare": "test -d .git && husky install || true"
package/pkg.js CHANGED
@@ -1,3 +1,45 @@
1
- import { readFileSync } from 'node:fs';
2
- import { fileURLToPath } from 'node:url';
3
- export default JSON.parse(readFileSync(fileURLToPath(new URL('./package.json', import.meta.url)), 'utf-8'));
1
+ import { readFileSync, writeFileSync, cpSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import { rollup } from 'rollup';
5
+ import { exec } from 'pkg';
6
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
7
+ import commonjs from '@rollup/plugin-commonjs';
8
+ import json from '@rollup/plugin-json';
9
+
10
+ const bundle = await rollup({
11
+ input: 'dist/cli.js',
12
+ plugins: [
13
+ nodeResolve({
14
+ exportConditions: ['node'],
15
+ }),
16
+ commonjs(),
17
+ json(),
18
+ ],
19
+ });
20
+
21
+ await bundle.write({
22
+ dir: 'bundle',
23
+ format: 'cjs',
24
+ });
25
+
26
+ await bundle.close();
27
+
28
+ const pkgJson = JSON.parse(readFileSync('package.json', 'utf8'));
29
+ delete pkgJson.type;
30
+
31
+ pkgJson.pkg.assets.forEach((asset) => {
32
+ cpSync(join('dist', asset), join('bundle', asset));
33
+ });
34
+
35
+ writeFileSync('bundle/package.json', JSON.stringify(pkgJson, null, 2));
36
+
37
+ await exec([
38
+ 'bundle',
39
+ '--out-path',
40
+ 'bundle',
41
+ '--compress',
42
+ 'brotli',
43
+ '--options',
44
+ 'no-warnings',
45
+ ]);
@@ -0,0 +1,20 @@
1
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import json from '@rollup/plugin-json';
4
+
5
+ export default {
6
+ input: 'dist/cli.js',
7
+ output: {
8
+ dir: 'bundle',
9
+ format: 'cjs',
10
+ entryFileNames: '[name].cjs',
11
+ chunkFileNames: '[name]-[hash].cjs',
12
+ },
13
+ plugins: [
14
+ nodeResolve({
15
+ exportConditions: ['node'],
16
+ }),
17
+ commonjs(),
18
+ json(),
19
+ ],
20
+ };