@appsemble/cli 0.20.27 → 0.20.29

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 (136) hide show
  1. package/README.md +4 -4
  2. package/index.js +0 -0
  3. package/package.json +5 -5
  4. package/__fixtures__/getBlockConfigFromTypeScript/comments/index.ts +0 -40
  5. package/__fixtures__/getBlockConfigFromTypeScript/comments/tsconfig.json +0 -7
  6. package/__fixtures__/getBlockConfigFromTypeScript/duplicateActions/index.ts +0 -34
  7. package/__fixtures__/getBlockConfigFromTypeScript/duplicateActions/tsconfig.json +0 -7
  8. package/__fixtures__/getBlockConfigFromTypeScript/duplicateEventEmitters/index.ts +0 -34
  9. package/__fixtures__/getBlockConfigFromTypeScript/duplicateEventEmitters/tsconfig.json +0 -7
  10. package/__fixtures__/getBlockConfigFromTypeScript/duplicateEventListeners/index.ts +0 -34
  11. package/__fixtures__/getBlockConfigFromTypeScript/duplicateEventListeners/tsconfig.json +0 -7
  12. package/__fixtures__/getBlockConfigFromTypeScript/duplicateParameters/index.ts +0 -34
  13. package/__fixtures__/getBlockConfigFromTypeScript/duplicateParameters/tsconfig.json +0 -7
  14. package/__fixtures__/getBlockConfigFromTypeScript/fontawesomeParameters/index.ts +0 -11
  15. package/__fixtures__/getBlockConfigFromTypeScript/fontawesomeParameters/tsconfig.json +0 -7
  16. package/__fixtures__/getBlockConfigFromTypeScript/tsError/index.ts +0 -4
  17. package/__fixtures__/getBlockConfigFromTypeScript/tsError/tsconfig.json +0 -8
  18. package/__fixtures__/getBlockConfigFromTypeScript/valid/index.ts +0 -28
  19. package/__fixtures__/getBlockConfigFromTypeScript/valid/tsconfig.json +0 -7
  20. package/__fixtures__/makePayload/with-icon/icon.svg +0 -2
  21. package/assets/appsemblerc.schema.json +0 -150
  22. package/changed/added/.gitkeep +0 -0
  23. package/changed/changed/.gitkeep +0 -0
  24. package/changed/deprecated/.gitkeep +0 -0
  25. package/changed/fixed/.gitkeep +0 -0
  26. package/changed/removed/.gitkeep +0 -0
  27. package/changed/security/.gitkeep +0 -0
  28. package/commands/app/create.js.map +0 -1
  29. package/commands/app/create.ts +0 -104
  30. package/commands/app/extract-messages.js.map +0 -1
  31. package/commands/app/extract-messages.ts +0 -56
  32. package/commands/app/index.js.map +0 -1
  33. package/commands/app/index.ts +0 -18
  34. package/commands/app/update.js.map +0 -1
  35. package/commands/app/update.ts +0 -111
  36. package/commands/asset/create.js.map +0 -1
  37. package/commands/asset/create.ts +0 -84
  38. package/commands/asset/index.js.map +0 -1
  39. package/commands/asset/index.ts +0 -12
  40. package/commands/block/build.js.map +0 -1
  41. package/commands/block/build.ts +0 -32
  42. package/commands/block/extract-messages.js.map +0 -1
  43. package/commands/block/extract-messages.ts +0 -41
  44. package/commands/block/index.js.map +0 -1
  45. package/commands/block/index.ts +0 -18
  46. package/commands/block/publish.js.map +0 -1
  47. package/commands/block/publish.ts +0 -58
  48. package/commands/cleanupResources.js.map +0 -1
  49. package/commands/cleanupResources.ts +0 -45
  50. package/commands/config/get.js.map +0 -1
  51. package/commands/config/get.ts +0 -27
  52. package/commands/config/index.js.map +0 -1
  53. package/commands/config/index.ts +0 -16
  54. package/commands/config/set.js.map +0 -1
  55. package/commands/config/set.ts +0 -45
  56. package/commands/login.js.map +0 -1
  57. package/commands/login.ts +0 -5
  58. package/commands/logout.js.map +0 -1
  59. package/commands/logout.ts +0 -5
  60. package/commands/migrate.js.map +0 -1
  61. package/commands/migrate.ts +0 -50
  62. package/commands/organization/create.js.map +0 -1
  63. package/commands/organization/create.ts +0 -65
  64. package/commands/organization/index.js.map +0 -1
  65. package/commands/organization/index.ts +0 -16
  66. package/commands/organization/update.js.map +0 -1
  67. package/commands/organization/update.ts +0 -65
  68. package/commands/resource/create.js.map +0 -1
  69. package/commands/resource/create.ts +0 -78
  70. package/commands/resource/index.js.map +0 -1
  71. package/commands/resource/index.ts +0 -16
  72. package/commands/resource/update.js.map +0 -1
  73. package/commands/resource/update.ts +0 -77
  74. package/commands/runCronJobs.js.map +0 -1
  75. package/commands/runCronJobs.ts +0 -45
  76. package/commands/start.js.map +0 -1
  77. package/commands/start.ts +0 -140
  78. package/commands/team/create.js.map +0 -1
  79. package/commands/team/create.ts +0 -60
  80. package/commands/team/delete.js.map +0 -1
  81. package/commands/team/delete.ts +0 -54
  82. package/commands/team/index.js.map +0 -1
  83. package/commands/team/index.ts +0 -20
  84. package/commands/team/member/delete.js.map +0 -1
  85. package/commands/team/member/delete.ts +0 -61
  86. package/commands/team/member/index.js.map +0 -1
  87. package/commands/team/member/index.ts +0 -18
  88. package/commands/team/member/invite.js.map +0 -1
  89. package/commands/team/member/invite.ts +0 -61
  90. package/commands/team/member/update.js.map +0 -1
  91. package/commands/team/member/update.ts +0 -70
  92. package/commands/team/update.js.map +0 -1
  93. package/commands/team/update.ts +0 -60
  94. package/index.js.map +0 -1
  95. package/index.ts +0 -74
  96. package/jest.config.js +0 -3
  97. package/jest.setup.js.map +0 -1
  98. package/jest.setup.ts +0 -4
  99. package/lib/__snapshots__/getBlockConfigFromTypeScript.test.ts.snap +0 -4241
  100. package/lib/app.js.map +0 -1
  101. package/lib/app.ts +0 -795
  102. package/lib/asset.js.map +0 -1
  103. package/lib/asset.ts +0 -43
  104. package/lib/authentication.js.map +0 -1
  105. package/lib/authentication.ts +0 -194
  106. package/lib/block.js.map +0 -1
  107. package/lib/block.test.js.map +0 -1
  108. package/lib/block.test.ts +0 -103
  109. package/lib/block.ts +0 -384
  110. package/lib/coercers.js.map +0 -1
  111. package/lib/coercers.test.js.map +0 -1
  112. package/lib/coercers.test.ts +0 -27
  113. package/lib/coercers.ts +0 -58
  114. package/lib/getBlockConfigFromTypeScript.js.map +0 -1
  115. package/lib/getBlockConfigFromTypeScript.test.js.map +0 -1
  116. package/lib/getBlockConfigFromTypeScript.test.ts +0 -282
  117. package/lib/getBlockConfigFromTypeScript.ts +0 -356
  118. package/lib/initAxios.js.map +0 -1
  119. package/lib/initAxios.ts +0 -16
  120. package/lib/loadWebpackConfig.js.map +0 -1
  121. package/lib/loadWebpackConfig.ts +0 -52
  122. package/lib/organization.js.map +0 -1
  123. package/lib/organization.ts +0 -105
  124. package/lib/output.js.map +0 -1
  125. package/lib/output.ts +0 -19
  126. package/lib/processCss.js.map +0 -1
  127. package/lib/processCss.ts +0 -24
  128. package/lib/resource.js.map +0 -1
  129. package/lib/resource.ts +0 -128
  130. package/lib/serverImport.js.map +0 -1
  131. package/lib/serverImport.ts +0 -42
  132. package/lib/team.js.map +0 -1
  133. package/lib/team.ts +0 -152
  134. package/tsconfig.json +0 -9
  135. package/types.js.map +0 -1
  136. package/types.ts +0 -110
@@ -1,282 +0,0 @@
1
- import { readdirSync } from 'node:fs';
2
- import process from 'node:process';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import { AppsembleError, resolveFixture } from '@appsemble/node-utils';
6
- import { ts } from 'ts-json-schema-generator';
7
-
8
- import { getBlockConfigFromTypeScript } from './getBlockConfigFromTypeScript.js';
9
-
10
- beforeEach(() => {
11
- import.meta.jest.spyOn(process, 'cwd').mockReturnValue(resolveFixture('.'));
12
- });
13
-
14
- describe('getBlockConfigFromTypeScript', () => {
15
- it('should extract configuration from a TypeScript project', () => {
16
- const result = getBlockConfigFromTypeScript({
17
- name: '',
18
- layout: 'float',
19
- version: '1.33.7',
20
- webpack: '',
21
- output: '',
22
- dir: resolveFixture('getBlockConfigFromTypeScript/valid'),
23
- });
24
- expect(result).toStrictEqual({
25
- actions: { testAction: { description: undefined } },
26
- events: {
27
- emit: { testEmit: { description: undefined } },
28
- listen: { testListener: { description: undefined } },
29
- },
30
- messages: undefined,
31
- parameters: {
32
- $schema: 'http://json-schema.org/draft-07/schema#',
33
- additionalProperties: false,
34
- properties: {
35
- param1: { type: 'string' },
36
- param2: { type: 'number' },
37
- param3: { type: 'boolean' },
38
- param4: { type: 'string' },
39
- param5: {
40
- additionalProperties: false,
41
- properties: {
42
- nested1: { type: 'string' },
43
- nested2: { type: 'number' },
44
- nested3: { type: 'boolean' },
45
- },
46
- required: ['nested1', 'nested2', 'nested3'],
47
- type: 'object',
48
- },
49
- param6: { items: { type: 'string' }, type: 'array' },
50
- },
51
- required: ['param1', 'param2', 'param3', 'param5', 'param6'],
52
- type: 'object',
53
- },
54
- });
55
- });
56
-
57
- it('should not use TypeScript if all metadata is present in the original config', () => {
58
- import.meta.jest.spyOn(ts, 'createProgram');
59
- const input = {
60
- actions: {},
61
- events: { emit: { foo: {} }, listen: { bar: {} } },
62
- layout: 'float',
63
- parameters: { type: 'object' },
64
- version: '1.33.7',
65
- webpack: '',
66
- output: '',
67
- dir: resolveFixture('getBlockConfigFromTypeScript/valid'),
68
- name: '',
69
- } as const;
70
- const result = getBlockConfigFromTypeScript(input);
71
-
72
- expect(result).toBe(input);
73
- expect(ts.createProgram).not.toHaveBeenCalled();
74
- });
75
-
76
- it('should prefer actions overrides over TypeScript actions', () => {
77
- const result = getBlockConfigFromTypeScript({
78
- actions: {},
79
- version: '1.33.7',
80
- webpack: '',
81
- output: '',
82
- dir: resolveFixture('getBlockConfigFromTypeScript/valid'),
83
- name: '',
84
- });
85
-
86
- expect(result.actions).toStrictEqual({});
87
- });
88
-
89
- it('should prefer events overrides over TypeScript events', () => {
90
- const result = getBlockConfigFromTypeScript({
91
- events: { emit: { onSuccess: {} } },
92
- version: '1.33.7',
93
- webpack: '',
94
- output: '',
95
- dir: resolveFixture('getBlockConfigFromTypeScript/valid'),
96
- name: '',
97
- });
98
-
99
- expect(result.events).toStrictEqual({ emit: { onSuccess: {} } });
100
- });
101
-
102
- it('should prefer parameters overrides over TypeScript parameters', () => {
103
- const result = getBlockConfigFromTypeScript({
104
- parameters: { type: 'object' },
105
- version: '1.33.7',
106
- webpack: '',
107
- output: '',
108
- dir: resolveFixture('getBlockConfigFromTypeScript/valid'),
109
- name: '',
110
- });
111
-
112
- expect(result.parameters).toStrictEqual({ type: 'object' });
113
- });
114
-
115
- it('should throw if duplicate Actions are found', () => {
116
- expect(() =>
117
- getBlockConfigFromTypeScript({
118
- webpack: '',
119
- output: '',
120
- dir: resolveFixture('getBlockConfigFromTypeScript/duplicateActions'),
121
- name: '',
122
- version: '1.33.7',
123
- }),
124
- ).toThrow(
125
- new AppsembleError(
126
- "Found duplicate interface 'Actions' in 'getBlockConfigFromTypeScript/duplicateActions/index.ts:31'",
127
- ),
128
- );
129
- });
130
-
131
- it('should throw if duplicate EventEmitters are found', () => {
132
- expect(() =>
133
- getBlockConfigFromTypeScript({
134
- webpack: '',
135
- output: '',
136
- dir: resolveFixture('getBlockConfigFromTypeScript/duplicateEventEmitters'),
137
- name: '',
138
- version: '1.33.7',
139
- }),
140
- ).toThrow(
141
- new AppsembleError(
142
- "Found duplicate interface 'EventEmitters' in 'getBlockConfigFromTypeScript/duplicateEventEmitters/index.ts:31'",
143
- ),
144
- );
145
- });
146
-
147
- it('should throw if duplicate EventListeners are found', () => {
148
- expect(() =>
149
- getBlockConfigFromTypeScript({
150
- webpack: '',
151
- output: '',
152
- dir: resolveFixture('getBlockConfigFromTypeScript/duplicateEventListeners'),
153
- name: '',
154
- version: '1.33.7',
155
- }),
156
- ).toThrow(
157
- new AppsembleError(
158
- "Found duplicate interface 'EventListeners' in 'getBlockConfigFromTypeScript/duplicateEventListeners/index.ts:31'",
159
- ),
160
- );
161
- });
162
-
163
- it('should throw if duplicate Parameters are found', () => {
164
- expect(() =>
165
- getBlockConfigFromTypeScript({
166
- webpack: '',
167
- output: '',
168
- dir: resolveFixture('getBlockConfigFromTypeScript/duplicateParameters'),
169
- name: '',
170
- version: '1.33.7',
171
- }),
172
- ).toThrow(
173
- new AppsembleError(
174
- "Found duplicate interface 'Parameters' in 'getBlockConfigFromTypeScript/duplicateParameters/index.ts:31'",
175
- ),
176
- );
177
- });
178
-
179
- it('should handle fontawesome icons', () => {
180
- const result = getBlockConfigFromTypeScript({
181
- webpack: '',
182
- output: '',
183
- dir: resolveFixture('getBlockConfigFromTypeScript/fontawesomeParameters'),
184
- name: '',
185
- version: '1.33.7',
186
- });
187
-
188
- expect(result).toStrictEqual({
189
- actions: undefined,
190
- events: undefined,
191
- messages: undefined,
192
- parameters: {
193
- $schema: 'http://json-schema.org/draft-07/schema#',
194
- additionalProperties: false,
195
- properties: {
196
- icon: { description: 'This is an icon.', format: 'fontawesome', type: 'string' },
197
- },
198
- type: 'object',
199
- },
200
- });
201
- });
202
-
203
- it('should handle TypeScript pre emit diagnostics', () => {
204
- function fn(): void {
205
- getBlockConfigFromTypeScript({
206
- name: '',
207
- layout: 'float',
208
- version: '1.33.7',
209
- webpack: '',
210
- output: '',
211
- dir: resolveFixture('getBlockConfigFromTypeScript/tsError'),
212
- });
213
- }
214
- expect(fn).toThrow(AppsembleError);
215
- expect(fn).toThrow(/'unused' is declared but its value is never read/);
216
- });
217
-
218
- it('should extract comments', () => {
219
- const result = getBlockConfigFromTypeScript({
220
- name: '',
221
- layout: 'float',
222
- version: '1.33.7',
223
- webpack: '',
224
- output: '',
225
- dir: resolveFixture('getBlockConfigFromTypeScript/comments'),
226
- });
227
-
228
- expect(result).toStrictEqual({
229
- actions: {
230
- comment: {
231
- description: 'Valid action comment',
232
- },
233
- duplicate: {
234
- description: 'Expected comment',
235
- },
236
- line: {
237
- description: undefined,
238
- },
239
- },
240
- events: {
241
- emit: {
242
- testEmit: {
243
- description: 'Test event emitter.',
244
- },
245
- },
246
- listen: {
247
- testListener: {
248
- description: 'Test event listener.',
249
- },
250
- },
251
- },
252
- messages: undefined,
253
- parameters: {
254
- $schema: 'http://json-schema.org/draft-07/schema#',
255
- additionalProperties: false,
256
- properties: {
257
- param: {},
258
- },
259
- required: ['param'],
260
- type: 'object',
261
- },
262
- });
263
- });
264
-
265
- describe('official blocks', () => {
266
- const blocksDir = new URL('../../../blocks/', import.meta.url);
267
-
268
- it.each(readdirSync(blocksDir))('%s', (name) => {
269
- const dir = fileURLToPath(new URL(name, blocksDir));
270
-
271
- const result = getBlockConfigFromTypeScript({
272
- name,
273
- version: '',
274
- output: '',
275
- webpack: undefined,
276
- dir,
277
- });
278
-
279
- expect(result).toMatchSnapshot();
280
- });
281
- });
282
- });
@@ -1,356 +0,0 @@
1
- import { relative } from 'node:path';
2
-
3
- import { AppsembleError, logger } from '@appsemble/node-utils';
4
- import { BlockConfig, BlockManifest } from '@appsemble/types';
5
- import { parse } from 'comment-parser';
6
- import { Schema } from 'jsonschema';
7
- import normalizePath from 'normalize-path';
8
- import { createFormatter, createParser, SchemaGenerator, ts } from 'ts-json-schema-generator';
9
-
10
- // eslint-disable-next-line jsdoc/require-returns-check
11
- /**
12
- * Get the tsdoc comment for a TypeScript node.
13
- *
14
- * @param checker The type checker instance to use.
15
- * @param node The node for which to get the tsdoc.
16
- * @returns The tsdoc comment as a string, if present.
17
- */
18
- function getNodeComments(checker: ts.TypeChecker, node: ts.TypeElement): string {
19
- const symbol = checker.getSymbolAtLocation(node.name);
20
- if (!symbol) {
21
- return;
22
- }
23
-
24
- const comments = symbol.getDocumentationComment(checker);
25
- if (comments.length) {
26
- return comments
27
- .map((comment) =>
28
- comment.kind === 'lineBreak' ? comment.text : comment.text.trim().replace(/\r\n/g, '\n'),
29
- )
30
- .join('');
31
- }
32
- }
33
-
34
- // eslint-disable-next-line jsdoc/require-returns-check
35
- /**
36
- * Process keys from an interface into an object.
37
- *
38
- * This asserts only index signature members and regular alphanumerical properties are used.
39
- *
40
- * @param iface The TypeScript interface to check.
41
- * @param checker The TypeScript type checker.
42
- * @param convert A function for converting extracted data to a value. It will be called with the
43
- * name and JSDoc description. The name is `undefined` for index signatures. The function should
44
- * return a tuple of key and value.
45
- * @returns A record created from the returned key/value pairs.
46
- */
47
- function processInterface<T>(
48
- iface: ts.InterfaceDeclaration,
49
- checker: ts.TypeChecker,
50
- convert: (name: string, description: string) => [string, T],
51
- ): Record<string, T> {
52
- if (!iface?.members.length) {
53
- return;
54
- }
55
-
56
- const source = iface.getSourceFile().getText();
57
-
58
- return Object.fromEntries(
59
- iface.members.map((member) => {
60
- const description = getNodeComments(checker, member);
61
- if (ts.isIndexSignatureDeclaration(member)) {
62
- // Comments aren’t properly extracted for index signatures.
63
- const commentRanges = ts.getLeadingCommentRanges(source, member.pos);
64
- if (commentRanges) {
65
- const comments = commentRanges?.map((r) => source.slice(r.pos, r.end)) ?? [];
66
- const [block] = parse(comments[0]);
67
- const processedDescription = block.source
68
- .map((src) => src.tokens.description)
69
- .join('\n')
70
- .replace(/^\s+|\s+$/g, '');
71
-
72
- return convert(undefined, processedDescription);
73
- }
74
-
75
- return convert(undefined, description);
76
- }
77
-
78
- if (!ts.isPropertySignature(member)) {
79
- throw new AppsembleError(
80
- `Only property and index signatures are allowed as ${
81
- iface.name
82
- } keys. Found: ${member.getFullText()}`,
83
- );
84
- }
85
-
86
- const { name } = member;
87
-
88
- if (!ts.isIdentifier(name)) {
89
- throw new AppsembleError(
90
- `Only property and index signatures are allowed as ${
91
- iface.name
92
- } keys. Found: ${name.getFullText()}`,
93
- );
94
- }
95
-
96
- const { text } = name;
97
-
98
- if (!/^[\da-z]+$/i.test(text)) {
99
- throw new AppsembleError(
100
- `Found property named ‘${text}’ in ${iface.name} interface. Only alphanumerical identifiers are supported.`,
101
- );
102
- }
103
-
104
- return convert(text, description);
105
- }),
106
- );
107
- }
108
-
109
- /**
110
- * Get an actions object based on a TypeScript interface node.
111
- *
112
- * @param iface The node to base the actions on.
113
- * @param checker The TypeScript type checker.
114
- * @returns The action manifest to upload.
115
- */
116
- function processActions(
117
- iface: ts.InterfaceDeclaration,
118
- checker: ts.TypeChecker,
119
- ): BlockManifest['actions'] {
120
- return processInterface(iface, checker, (name, description) => [name ?? '$any', { description }]);
121
- }
122
-
123
- /**
124
- * Get an events object based on TypeScript interface nodes.
125
- *
126
- * @param eventListenerInterface The node to base the event listeners on.
127
- * @param eventEmitterInterface The node to base the event emitters on.
128
- * @param checker The TypeScript type checker.
129
- * @returns The events manifest to upload.
130
- */
131
- function processEvents(
132
- eventListenerInterface: ts.InterfaceDeclaration,
133
- eventEmitterInterface: ts.InterfaceDeclaration,
134
- checker: ts.TypeChecker,
135
- ): BlockManifest['events'] {
136
- const listen = processInterface(eventListenerInterface, checker, (name, description) => [
137
- name ?? '$any',
138
- { description },
139
- ]);
140
- const emit = processInterface(eventEmitterInterface, checker, (name, description) => [
141
- name ?? '$any',
142
- { description },
143
- ]);
144
-
145
- return (emit || listen) && { emit, listen };
146
- }
147
-
148
- // eslint-disable-next-line jsdoc/require-returns-check
149
- /**
150
- * Get the JSON schema for parameters based on a TypeScript program.
151
- *
152
- * @param program The TypeScript program from which to extract parameters.
153
- * @param iface The interface node from which to extract parameters.
154
- * @returns The JSON schema for the block parameters.
155
- */
156
- function processParameters(program: ts.Program, iface: ts.InterfaceDeclaration): Schema {
157
- if (!iface) {
158
- return;
159
- }
160
- const formatter = createFormatter({}, (fmt) => {
161
- fmt.addTypeFormatter({
162
- supportsType: (type) => type.getName() === 'IconName',
163
- getDefinition: () => ({ type: 'string', format: 'fontawesome' }),
164
- getChildren: () => [],
165
- });
166
- fmt.addTypeFormatter({
167
- supportsType: (type) => type.getName() === 'Remapper',
168
- getDefinition: () => ({ format: 'remapper' }),
169
- getChildren: () => [],
170
- });
171
- });
172
- const parser = createParser(program, { expose: 'all', topRef: false });
173
- const generator = new SchemaGenerator(program, parser, formatter);
174
- const schema = generator.createSchemaFromNodes([iface]) as Schema;
175
- if (schema.definitions && !Object.keys(schema.definitions).length) {
176
- delete schema.definitions;
177
- }
178
- // This is the tsdoc that has been added to the SDK to aid the block developer.
179
- delete schema.description;
180
- return schema;
181
- }
182
-
183
- /**
184
- * Get a messages object based on a TypeScript interface node.
185
- *
186
- * @param iface The node to base the messages on.
187
- * @param checker The TypeScript type checker.
188
- * @returns The action manifest to upload.
189
- */
190
- function processMessages(
191
- iface: ts.InterfaceDeclaration,
192
- checker: ts.TypeChecker,
193
- ): BlockManifest['messages'] {
194
- return processInterface(iface, checker, (name, description) => [name, { description }]);
195
- }
196
-
197
- /**
198
- * Get the TypeScript program for a given path.
199
- *
200
- * @param blockPath The path for which to get the TypeScript program.
201
- * @returns The TypeScript program.
202
- */
203
- function getProgram(blockPath: string): ts.Program {
204
- const diagnosticHost: ts.FormatDiagnosticsHost = {
205
- getNewLine: () => ts.sys.newLine,
206
- getCurrentDirectory: ts.sys.getCurrentDirectory,
207
- getCanonicalFileName: (x) => x,
208
- };
209
- const tsConfigPath = ts.findConfigFile(blockPath, ts.sys.fileExists);
210
- const { config, error } = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
211
- if (error) {
212
- throw new AppsembleError(ts.formatDiagnostic(error, diagnosticHost));
213
- }
214
- if (!config.files || !config.include) {
215
- config.files = ts.sys
216
- .readDirectory(blockPath, ['.ts', '.tsx'])
217
- .map((f) => relative(blockPath, f));
218
- }
219
- const { errors, fileNames, options } = ts.parseJsonConfigFileContent(
220
- config,
221
- ts.sys,
222
- blockPath,
223
- undefined,
224
- tsConfigPath,
225
- );
226
- // Filter: 'rootDir' is expected to contain all source files.
227
- const diagnostics = errors.filter(({ code }) => code !== 6059);
228
- if (diagnostics.length) {
229
- throw new AppsembleError(ts.formatDiagnosticsWithColorAndContext(diagnostics, diagnosticHost));
230
- }
231
-
232
- options.noEmit = true;
233
- delete options.out;
234
- delete options.outDir;
235
- delete options.outFile;
236
- delete options.declaration;
237
- delete options.declarationDir;
238
- delete options.declarationMap;
239
- const program = ts.createProgram(fileNames, options);
240
- const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
241
- if (preEmitDiagnostics.length) {
242
- throw new AppsembleError(
243
- ts.formatDiagnosticsWithColorAndContext(preEmitDiagnostics, diagnosticHost),
244
- );
245
- }
246
- return program;
247
- }
248
-
249
- /**
250
- * Generate a block manifest from the block metadata and TypeScript project.
251
- *
252
- * Uses the .appsemblerc file and the type definitions of the block.
253
- *
254
- * @param blockConfig The block configuration
255
- * @returns The block configuration appended from the TypeScript project.
256
- */
257
- export function getBlockConfigFromTypeScript(
258
- blockConfig: BlockConfig,
259
- ): Pick<BlockManifest, 'actions' | 'events' | 'messages' | 'parameters'> {
260
- if ('actions' in blockConfig && 'events' in blockConfig && 'parameters' in blockConfig) {
261
- return blockConfig;
262
- }
263
- logger.info(`Extracting data from TypeScript project ${blockConfig.dir}`);
264
- const program = getProgram(blockConfig.dir);
265
- const checker = program.getTypeChecker();
266
-
267
- let actionInterface: ts.InterfaceDeclaration;
268
- let eventEmitterInterface: ts.InterfaceDeclaration;
269
- let eventListenerInterface: ts.InterfaceDeclaration;
270
- let messagesInterface: ts.InterfaceDeclaration;
271
- let patametersInterface: ts.InterfaceDeclaration;
272
-
273
- for (const sourceFile of program.getSourceFiles()) {
274
- const fileName = relative(process.cwd(), sourceFile.fileName);
275
- // Filter TypeScript default libs
276
- if (program.isSourceFileDefaultLibrary(sourceFile)) {
277
- logger.silly(`Skipping metadata extraction from: ${fileName}`);
278
- continue;
279
- }
280
- logger.verbose(`Searching metadata in: ${fileName}`);
281
- // eslint-disable-next-line @typescript-eslint/no-loop-func
282
- ts.forEachChild(sourceFile, (mod) => {
283
- // This node doesn’t override SDK types
284
- if (!ts.isModuleDeclaration(mod)) {
285
- return;
286
- }
287
- // This module defines other types
288
- if (mod.name.text !== '@appsemble/sdk') {
289
- return;
290
- }
291
- ts.forEachChild(mod.body, (iface) => {
292
- // Appsemble only uses module interface augmentation.
293
- if (!ts.isInterfaceDeclaration(iface)) {
294
- return;
295
- }
296
- const { line } = sourceFile.getLineAndCharacterOfPosition(iface.getStart(sourceFile));
297
- // Line numbers are 0 indexed, whereas they are usually represented as 1 indexed.
298
- const loc = `${normalizePath(fileName)}:${line + 1}`;
299
-
300
- switch (iface.name.text) {
301
- case 'Actions':
302
- logger.info(`Found augmented interface 'Actions' in '${loc}'`);
303
- if (actionInterface) {
304
- throw new AppsembleError(`Found duplicate interface 'Actions' in '${loc}'`);
305
- }
306
- actionInterface = iface;
307
- break;
308
- case 'EventEmitters':
309
- logger.info(`Found augmented interface 'EventEmitters' in '${loc}'`);
310
- if (eventEmitterInterface) {
311
- throw new AppsembleError(`Found duplicate interface 'EventEmitters' in '${loc}'`);
312
- }
313
- eventEmitterInterface = iface;
314
- break;
315
- case 'EventListeners':
316
- logger.info(`Found augmented interface 'EventListeners' in '${loc}'`);
317
- if (eventListenerInterface) {
318
- throw new AppsembleError(`Found duplicate interface 'EventListeners' in '${loc}'`);
319
- }
320
- eventListenerInterface = iface;
321
- break;
322
- case 'Parameters':
323
- logger.info(`Found augmented interface 'Parameters' in '${loc}'`);
324
- if (patametersInterface) {
325
- throw new AppsembleError(`Found duplicate interface 'Parameters' in '${loc}'`);
326
- }
327
- patametersInterface = iface;
328
- break;
329
- case 'Messages':
330
- logger.info(`Found augmented interface 'Messages' in '${loc}'`);
331
- messagesInterface = iface;
332
- break;
333
- default:
334
- logger.warn(`Detected unused augmented type ${iface.name.text} in ${loc}`);
335
- }
336
- });
337
- });
338
- }
339
-
340
- return {
341
- actions:
342
- 'actions' in blockConfig ? blockConfig.actions : processActions(actionInterface, checker),
343
- events:
344
- 'events' in blockConfig
345
- ? blockConfig.events
346
- : processEvents(eventListenerInterface, eventEmitterInterface, checker),
347
- parameters:
348
- 'parameters' in blockConfig
349
- ? blockConfig.parameters
350
- : processParameters(program, patametersInterface),
351
- messages:
352
- 'messages' in blockConfig
353
- ? blockConfig.messages
354
- : processMessages(messagesInterface, checker),
355
- };
356
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"initAxios.js","sourceRoot":"","sources":["initAxios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,GAAG,MAAM,iBAAiB,CAAC,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;AAG1D;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,MAAM,EAAiB;IACjD,KAAK,CAAC,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC;IAChC,MAAM,CAAC,OAAO,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAClD,cAAc,CAAC,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC"}
package/lib/initAxios.ts DELETED
@@ -1,16 +0,0 @@
1
- import { configureAxios, logger } from '@appsemble/node-utils';
2
- import axios from 'axios';
3
-
4
- import pkg from '../package.json' assert { type: 'json' };
5
- import { BaseArguments } from '../types.js';
6
-
7
- /**
8
- * Configure the default axios URL.
9
- *
10
- * @param argv The parsed command line arguments.
11
- */
12
- export function initAxios({ remote }: BaseArguments): void {
13
- axios.defaults.baseURL = remote;
14
- logger.verbose(`Request remote set to ${remote}`);
15
- configureAxios('AppsembleCLI', pkg.version);
16
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadWebpackConfig.js","sourceRoot":"","sources":["loadWebpackConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAkB,EAClB,IAAmC,EACnC,UAAmB;IAEnB,IAAI,UAAkB,CAAC;IACvB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7C;SAAM;QACL,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;QAClD,IAAI;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC;SACxB;QAAC,MAAM;YACN,UAAU,GAAG,2BAA2B,CAAC;SAC1C;KACF;IACD,MAAM,CAAC,IAAI,CAAC,6BAA6B,UAAU,EAAE,CAAC,CAAC;IACvD,MAAM,UAAU,GAAG,eAAe,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,OAAO,GAAG,CAAC;IAC1E,IAAI,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC;IAC1C,MAAM,GAAG,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAEzF,8FAA8F;IAC9F,4FAA4F;IAC5F,UAAU;IACV,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,UAAU,IAAI,UAAU,CAAC;IAC9C,MAAM,CAAC,OAAO,CAAC,yCAAyC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9E,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC;IACtC,MAAM,CAAC,OAAO,CAAC,+CAA+C,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IAE1F,OAAO,MAAM,CAAC;AAChB,CAAC"}