@rindo/core 1.17.4 → 2.5.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.
Files changed (164) hide show
  1. package/LICENSE.md +27 -27
  2. package/bin/cli.ts +20 -0
  3. package/bin/rindo +51 -56
  4. package/cli/index.cjs +1263 -0
  5. package/cli/index.d.ts +1 -1
  6. package/cli/index.js +1232 -495
  7. package/cli/package.json +9 -4
  8. package/compiler/lib.d.ts +24 -0
  9. package/compiler/lib.dom.d.ts +20230 -0
  10. package/compiler/lib.dom.iterable.d.ts +351 -0
  11. package/compiler/lib.es2015.collection.d.ts +89 -0
  12. package/compiler/lib.es2015.core.d.ts +517 -0
  13. package/compiler/lib.es2015.d.ts +30 -0
  14. package/compiler/lib.es2015.generator.d.ts +79 -0
  15. package/compiler/lib.es2015.iterable.d.ts +505 -0
  16. package/compiler/lib.es2015.promise.d.ts +150 -0
  17. package/compiler/lib.es2015.proxy.d.ts +41 -0
  18. package/compiler/lib.es2015.reflect.d.ts +123 -0
  19. package/compiler/lib.es2015.symbol.d.ts +48 -0
  20. package/compiler/lib.es2015.symbol.wellknown.d.ts +324 -0
  21. package/compiler/lib.es2016.array.include.d.ts +118 -0
  22. package/compiler/lib.es2016.d.ts +22 -0
  23. package/compiler/lib.es2016.full.d.ts +25 -0
  24. package/compiler/lib.es2017.d.ts +26 -0
  25. package/compiler/lib.es2017.full.d.ts +25 -0
  26. package/compiler/lib.es2017.intl.d.ts +32 -0
  27. package/compiler/lib.es2017.object.d.ts +51 -0
  28. package/compiler/lib.es2017.sharedmemory.d.ts +137 -0
  29. package/compiler/lib.es2017.string.d.ts +47 -0
  30. package/compiler/lib.es2017.typedarrays.d.ts +55 -0
  31. package/compiler/lib.es2018.asyncgenerator.d.ts +79 -0
  32. package/compiler/lib.es2018.asynciterable.d.ts +45 -0
  33. package/compiler/lib.es2018.d.ts +26 -0
  34. package/compiler/lib.es2018.full.d.ts +25 -0
  35. package/compiler/lib.es2018.intl.d.ts +61 -0
  36. package/compiler/lib.es2018.promise.d.ts +32 -0
  37. package/compiler/lib.es2018.regexp.d.ts +39 -0
  38. package/compiler/lib.es2019.array.d.ts +85 -0
  39. package/compiler/lib.es2019.d.ts +25 -0
  40. package/compiler/lib.es2019.full.d.ts +25 -0
  41. package/compiler/lib.es2019.object.d.ts +35 -0
  42. package/compiler/lib.es2019.string.d.ts +33 -0
  43. package/compiler/lib.es2019.symbol.d.ts +26 -0
  44. package/compiler/lib.es2020.bigint.d.ts +728 -0
  45. package/compiler/lib.es2020.d.ts +27 -0
  46. package/compiler/lib.es2020.full.d.ts +25 -0
  47. package/compiler/lib.es2020.intl.d.ts +310 -0
  48. package/compiler/lib.es2020.promise.d.ts +50 -0
  49. package/compiler/lib.es2020.sharedmemory.d.ts +99 -0
  50. package/compiler/lib.es2020.string.d.ts +30 -0
  51. package/compiler/lib.es2020.symbol.wellknown.d.ts +39 -0
  52. package/compiler/lib.es5.d.ts +4435 -0
  53. package/compiler/lib.es6.d.ts +25 -0
  54. package/compiler/lib.esnext.d.ts +25 -0
  55. package/compiler/lib.esnext.full.d.ts +25 -0
  56. package/compiler/lib.esnext.intl.d.ts +32 -0
  57. package/compiler/lib.esnext.promise.d.ts +43 -0
  58. package/compiler/lib.esnext.string.d.ts +35 -0
  59. package/compiler/lib.esnext.weakref.d.ts +75 -0
  60. package/compiler/lib.scripthost.d.ts +327 -0
  61. package/compiler/lib.webworker.d.ts +6042 -0
  62. package/compiler/lib.webworker.importscripts.d.ts +26 -0
  63. package/compiler/lib.webworker.iterable.d.ts +166 -0
  64. package/compiler/package.json +3 -3
  65. package/compiler/rindo.d.ts +0 -16
  66. package/compiler/rindo.js +42738 -40541
  67. package/compiler/rindo.min.js +2 -15
  68. package/dependencies.json +73 -50
  69. package/dev-server/client/index.js +33 -10
  70. package/dev-server/client/package.json +3 -3
  71. package/dev-server/connector.html +3 -3
  72. package/dev-server/index.d.ts +3 -6
  73. package/dev-server/index.js +256 -252
  74. package/dev-server/package.json +3 -3
  75. package/dev-server/server-process.js +1738 -0
  76. package/dev-server/server-worker-thread.js +39 -0
  77. package/dev-server/templates/initial-load.html +160 -160
  78. package/dev-server/ws.js +1 -1
  79. package/internal/app-data/{index.cjs.js → index.cjs} +7 -5
  80. package/internal/app-data/index.d.ts +1 -0
  81. package/internal/app-data/index.js +7 -6
  82. package/internal/app-data/package.json +11 -5
  83. package/internal/client/css-shim.js +2 -2
  84. package/internal/client/dom.js +1 -1
  85. package/internal/client/index.js +193 -119
  86. package/internal/client/package.json +4 -3
  87. package/internal/client/{patch.js → patch-browser.js} +8 -24
  88. package/internal/client/patch-esm.js +23 -0
  89. package/internal/client/polyfills/css-shim.js +1 -1
  90. package/internal/client/polyfills/index.js +34 -34
  91. package/internal/client/shadow-css.js +9 -3
  92. package/internal/hydrate/index.js +305 -281
  93. package/internal/hydrate/package.json +2 -2
  94. package/internal/hydrate/runner.d.ts +24 -12
  95. package/internal/hydrate/runner.js +153 -124
  96. package/internal/hydrate/shadow-css.js +24 -24
  97. package/internal/package.json +5 -4
  98. package/internal/rindo-core/index.cjs +1 -0
  99. package/internal/rindo-core/index.d.ts +51 -2
  100. package/internal/rindo-core/index.js +15 -1
  101. package/internal/rindo-ext-modules.d.ts +41 -39
  102. package/internal/rindo-private.d.ts +93 -148
  103. package/internal/rindo-public-compiler.d.ts +231 -155
  104. package/internal/rindo-public-runtime.d.ts +42 -39
  105. package/internal/testing/index.js +144 -121
  106. package/internal/testing/package.json +2 -2
  107. package/internal/testing/shadow-css.js +24 -24
  108. package/mock-doc/index.cjs +4610 -0
  109. package/mock-doc/index.d.ts +12 -1
  110. package/mock-doc/index.js +177 -67
  111. package/mock-doc/package.json +11 -5
  112. package/package.json +132 -133
  113. package/readme.md +21 -95
  114. package/screenshot/compare/build/app.js +33 -33
  115. package/screenshot/compare/build/p-f4745c2f.entry.js +1 -1
  116. package/screenshot/connector-base.d.ts +1 -1
  117. package/screenshot/connector-local.d.ts +1 -1
  118. package/screenshot/index.js +63 -46
  119. package/screenshot/package.json +10 -3
  120. package/screenshot/pixel-match.js +54 -57
  121. package/screenshot/screenshot-compare.d.ts +1 -1
  122. package/screenshot/screenshot-fs.d.ts +1 -1
  123. package/sys/deno/index.js +1785 -0
  124. package/sys/deno/node-compat.js +2654 -0
  125. package/sys/deno/worker.js +44 -0
  126. package/sys/node/autoprefixer.js +8 -1
  127. package/sys/node/glob.js +1 -1
  128. package/sys/node/graceful-fs.js +1 -1
  129. package/sys/node/index.d.ts +1 -1
  130. package/sys/node/index.js +689 -705
  131. package/sys/node/node-fetch.js +1 -1
  132. package/sys/node/package.json +3 -3
  133. package/sys/node/prompts.js +1 -1
  134. package/sys/node/worker.js +38 -19
  135. package/testing/index.d.ts +3 -3
  136. package/testing/index.js +863 -749
  137. package/testing/jest/jest-config.d.ts +2 -89
  138. package/testing/jest/jest-environment.d.ts +1 -1
  139. package/testing/jest/jest-runner.d.ts +1 -1
  140. package/testing/jest/jest-screenshot.d.ts +1 -1
  141. package/testing/jest-preset.js +32 -32
  142. package/testing/matchers/events.d.ts +1 -1
  143. package/testing/matchers/screenshot.d.ts +1 -1
  144. package/testing/mock-fetch.d.ts +1 -1
  145. package/testing/mocks.d.ts +1 -1
  146. package/testing/package.json +3 -3
  147. package/testing/puppeteer/index.d.ts +1 -1
  148. package/testing/puppeteer/puppeteer-browser.d.ts +2 -2
  149. package/testing/puppeteer/puppeteer-declarations.d.ts +11 -11
  150. package/testing/puppeteer/puppeteer-element.d.ts +3 -3
  151. package/testing/puppeteer/puppeteer-emulate.d.ts +1 -1
  152. package/testing/puppeteer/puppeteer-events.d.ts +3 -3
  153. package/testing/puppeteer/puppeteer-page.d.ts +1 -1
  154. package/testing/puppeteer/puppeteer-screenshot.d.ts +2 -2
  155. package/testing/reset-build-conditionals.d.ts +1 -1
  156. package/testing/spec-page.d.ts +1 -1
  157. package/testing/test-transpile.d.ts +1 -1
  158. package/testing/testing-logger.d.ts +1 -1
  159. package/testing/testing-utils.d.ts +1 -1
  160. package/testing/testing.d.ts +1 -1
  161. package/cli/index.cjs.js +0 -524
  162. package/dev-server/content-type-db.json +0 -1
  163. package/dev-server/server-worker.js +0 -1570
  164. package/mock-doc/index.cjs.js +0 -4500
package/cli/index.cjs ADDED
@@ -0,0 +1,1263 @@
1
+ /*!
2
+ Rindo CLI (CommonJS) v2.5.2 | MIT Licensed | https://rindojs.web.app
3
+ */
4
+ 'use strict';
5
+
6
+ Object.defineProperty(exports, '__esModule', { value: true });
7
+
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () {
18
+ return e[k];
19
+ }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n['default'] = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ const toLowerCase = (str) => str.toLowerCase();
29
+ const dashToPascalCase = (str) => toLowerCase(str)
30
+ .split('-')
31
+ .map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
32
+ .join('');
33
+ const isFunction = (v) => typeof v === 'function';
34
+ const isString = (v) => typeof v === 'string';
35
+
36
+ const buildError = (diagnostics) => {
37
+ const diagnostic = {
38
+ level: 'error',
39
+ type: 'build',
40
+ header: 'Build Error',
41
+ messageText: 'build error',
42
+ relFilePath: null,
43
+ absFilePath: null,
44
+ lines: [],
45
+ };
46
+ if (diagnostics) {
47
+ diagnostics.push(diagnostic);
48
+ }
49
+ return diagnostic;
50
+ };
51
+ const catchError = (diagnostics, err, msg) => {
52
+ const diagnostic = {
53
+ level: 'error',
54
+ type: 'build',
55
+ header: 'Build Error',
56
+ messageText: 'build error',
57
+ relFilePath: null,
58
+ absFilePath: null,
59
+ lines: [],
60
+ };
61
+ if (isString(msg)) {
62
+ diagnostic.messageText = msg;
63
+ }
64
+ else if (err != null) {
65
+ if (err.stack != null) {
66
+ diagnostic.messageText = err.stack.toString();
67
+ }
68
+ else {
69
+ if (err.message != null) {
70
+ diagnostic.messageText = err.message.toString();
71
+ }
72
+ else {
73
+ diagnostic.messageText = err.toString();
74
+ }
75
+ }
76
+ }
77
+ if (diagnostics != null && !shouldIgnoreError(diagnostic.messageText)) {
78
+ diagnostics.push(diagnostic);
79
+ }
80
+ return diagnostic;
81
+ };
82
+ const hasError = (diagnostics) => {
83
+ if (diagnostics == null || diagnostics.length === 0) {
84
+ return false;
85
+ }
86
+ return diagnostics.some(d => d.level === 'error' && d.type !== 'runtime');
87
+ };
88
+ const shouldIgnoreError = (msg) => {
89
+ return msg === TASK_CANCELED_MSG;
90
+ };
91
+ const TASK_CANCELED_MSG = `task canceled`;
92
+
93
+ /**
94
+ * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
95
+ * Forward-slash paths can be used in Windows as long as they're not
96
+ * extended-length paths and don't contain any non-ascii characters.
97
+ * This was created since the path methods in Node.js outputs \\ paths on Windows.
98
+ */
99
+ const normalizePath = (path) => {
100
+ if (typeof path !== 'string') {
101
+ throw new Error(`invalid path to normalize`);
102
+ }
103
+ path = normalizeSlashes(path.trim());
104
+ const components = pathComponents(path, getRootLength(path));
105
+ const reducedComponents = reducePathComponents(components);
106
+ const rootPart = reducedComponents[0];
107
+ const secondPart = reducedComponents[1];
108
+ const normalized = rootPart + reducedComponents.slice(1).join('/');
109
+ if (normalized === '') {
110
+ return '.';
111
+ }
112
+ if (rootPart === '' &&
113
+ secondPart &&
114
+ path.includes('/') &&
115
+ !secondPart.startsWith('.') &&
116
+ !secondPart.startsWith('@')) {
117
+ return './' + normalized;
118
+ }
119
+ return normalized;
120
+ };
121
+ const normalizeSlashes = (path) => path.replace(backslashRegExp, '/');
122
+ const altDirectorySeparator = '\\';
123
+ const urlSchemeSeparator = '://';
124
+ const backslashRegExp = /\\/g;
125
+ const reducePathComponents = (components) => {
126
+ if (!Array.isArray(components) || components.length === 0) {
127
+ return [];
128
+ }
129
+ const reduced = [components[0]];
130
+ for (let i = 1; i < components.length; i++) {
131
+ const component = components[i];
132
+ if (!component)
133
+ continue;
134
+ if (component === '.')
135
+ continue;
136
+ if (component === '..') {
137
+ if (reduced.length > 1) {
138
+ if (reduced[reduced.length - 1] !== '..') {
139
+ reduced.pop();
140
+ continue;
141
+ }
142
+ }
143
+ else if (reduced[0])
144
+ continue;
145
+ }
146
+ reduced.push(component);
147
+ }
148
+ return reduced;
149
+ };
150
+ const getRootLength = (path) => {
151
+ const rootLength = getEncodedRootLength(path);
152
+ return rootLength < 0 ? ~rootLength : rootLength;
153
+ };
154
+ const getEncodedRootLength = (path) => {
155
+ if (!path)
156
+ return 0;
157
+ const ch0 = path.charCodeAt(0);
158
+ // POSIX or UNC
159
+ if (ch0 === 47 /* slash */ || ch0 === 92 /* backslash */) {
160
+ if (path.charCodeAt(1) !== ch0)
161
+ return 1; // POSIX: "/" (or non-normalized "\")
162
+ const p1 = path.indexOf(ch0 === 47 /* slash */ ? '/' : altDirectorySeparator, 2);
163
+ if (p1 < 0)
164
+ return path.length; // UNC: "//server" or "\\server"
165
+ return p1 + 1; // UNC: "//server/" or "\\server\"
166
+ }
167
+ // DOS
168
+ if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* colon */) {
169
+ const ch2 = path.charCodeAt(2);
170
+ if (ch2 === 47 /* slash */ || ch2 === 92 /* backslash */)
171
+ return 3; // DOS: "c:/" or "c:\"
172
+ if (path.length === 2)
173
+ return 2; // DOS: "c:" (but not "c:d")
174
+ }
175
+ // URL
176
+ const schemeEnd = path.indexOf(urlSchemeSeparator);
177
+ if (schemeEnd !== -1) {
178
+ const authorityStart = schemeEnd + urlSchemeSeparator.length;
179
+ const authorityEnd = path.indexOf('/', authorityStart);
180
+ if (authorityEnd !== -1) {
181
+ // URL: "file:///", "file://server/", "file://server/path"
182
+ // For local "file" URLs, include the leading DOS volume (if present).
183
+ // Per https://www.ietf.org/rfc/rfc1738.txt, a host of "" or "localhost" is a
184
+ // special case interpreted as "the machine from which the URL is being interpreted".
185
+ const scheme = path.slice(0, schemeEnd);
186
+ const authority = path.slice(authorityStart, authorityEnd);
187
+ if (scheme === 'file' &&
188
+ (authority === '' || authority === 'localhost') &&
189
+ isVolumeCharacter(path.charCodeAt(authorityEnd + 1))) {
190
+ const volumeSeparatorEnd = getFileUrlVolumeSeparatorEnd(path, authorityEnd + 2);
191
+ if (volumeSeparatorEnd !== -1) {
192
+ if (path.charCodeAt(volumeSeparatorEnd) === 47 /* slash */) {
193
+ // URL: "file:///c:/", "file://localhost/c:/", "file:///c%3a/", "file://localhost/c%3a/"
194
+ return ~(volumeSeparatorEnd + 1);
195
+ }
196
+ if (volumeSeparatorEnd === path.length) {
197
+ // URL: "file:///c:", "file://localhost/c:", "file:///c$3a", "file://localhost/c%3a"
198
+ // but not "file:///c:d" or "file:///c%3ad"
199
+ return ~volumeSeparatorEnd;
200
+ }
201
+ }
202
+ }
203
+ return ~(authorityEnd + 1); // URL: "file://server/", "http://server/"
204
+ }
205
+ return ~path.length; // URL: "file://server", "http://server"
206
+ }
207
+ // relative
208
+ return 0;
209
+ };
210
+ const isVolumeCharacter = (charCode) => (charCode >= 97 /* a */ && charCode <= 122 /* z */) ||
211
+ (charCode >= 65 /* A */ && charCode <= 90 /* Z */);
212
+ const getFileUrlVolumeSeparatorEnd = (url, start) => {
213
+ const ch0 = url.charCodeAt(start);
214
+ if (ch0 === 58 /* colon */)
215
+ return start + 1;
216
+ if (ch0 === 37 /* percent */ && url.charCodeAt(start + 1) === 51 /* _3 */) {
217
+ const ch2 = url.charCodeAt(start + 2);
218
+ if (ch2 === 97 /* a */ || ch2 === 65 /* A */)
219
+ return start + 3;
220
+ }
221
+ return -1;
222
+ };
223
+ const pathComponents = (path, rootLength) => {
224
+ const root = path.substring(0, rootLength);
225
+ const rest = path.substring(rootLength).split('/');
226
+ const restLen = rest.length;
227
+ if (restLen > 0 && !rest[restLen - 1]) {
228
+ rest.pop();
229
+ }
230
+ return [root, ...rest];
231
+ };
232
+
233
+ const validateComponentTag = (tag) => {
234
+ if (tag !== tag.trim()) {
235
+ return `Tag can not contain white spaces`;
236
+ }
237
+ if (tag !== tag.toLowerCase()) {
238
+ return `Tag can not contain upper case characters`;
239
+ }
240
+ if (typeof tag !== 'string') {
241
+ return `Tag "${tag}" must be a string type`;
242
+ }
243
+ if (tag.length === 0) {
244
+ return `Received empty tag value`;
245
+ }
246
+ if (tag.indexOf(' ') > -1) {
247
+ return `"${tag}" tag cannot contain a space`;
248
+ }
249
+ if (tag.indexOf(',') > -1) {
250
+ return `"${tag}" tag cannot be used for multiple tags`;
251
+ }
252
+ const invalidChars = tag.replace(/\w|-/g, '');
253
+ if (invalidChars !== '') {
254
+ return `"${tag}" tag contains invalid characters: ${invalidChars}`;
255
+ }
256
+ if (tag.indexOf('-') === -1) {
257
+ return `"${tag}" tag must contain a dash (-) to work as a valid web component`;
258
+ }
259
+ if (tag.indexOf('--') > -1) {
260
+ return `"${tag}" tag cannot contain multiple dashes (--) next to each other`;
261
+ }
262
+ if (tag.indexOf('-') === 0) {
263
+ return `"${tag}" tag cannot start with a dash (-)`;
264
+ }
265
+ if (tag.lastIndexOf('-') === tag.length - 1) {
266
+ return `"${tag}" tag cannot end with a dash (-)`;
267
+ }
268
+ return undefined;
269
+ };
270
+
271
+ const parseFlags = (args, sys) => {
272
+ const flags = {
273
+ task: null,
274
+ args: [],
275
+ knownArgs: [],
276
+ unknownArgs: null,
277
+ };
278
+ // cmd line has more priority over npm scripts cmd
279
+ flags.args = args.slice();
280
+ if (flags.args.length > 0 && flags.args[0] && !flags.args[0].startsWith('-')) {
281
+ flags.task = flags.args[0];
282
+ }
283
+ parseArgs(flags, flags.args, flags.knownArgs);
284
+ if (sys && sys.name === 'node') {
285
+ const envArgs = getNpmConfigEnvArgs(sys);
286
+ parseArgs(flags, envArgs, flags.knownArgs);
287
+ envArgs.forEach(envArg => {
288
+ if (!flags.args.includes(envArg)) {
289
+ flags.args.push(envArg);
290
+ }
291
+ });
292
+ }
293
+ if (flags.task != null) {
294
+ const i = flags.args.indexOf(flags.task);
295
+ if (i > -1) {
296
+ flags.args.splice(i, 1);
297
+ }
298
+ }
299
+ flags.unknownArgs = flags.args.filter((arg) => {
300
+ return !flags.knownArgs.includes(arg);
301
+ });
302
+ return flags;
303
+ };
304
+ const parseArgs = (flags, args, knownArgs) => {
305
+ ARG_OPTS.boolean.forEach(booleanName => {
306
+ const alias = ARG_OPTS.alias[booleanName];
307
+ const flagKey = configCase(booleanName);
308
+ if (typeof flags[flagKey] !== 'boolean') {
309
+ flags[flagKey] = null;
310
+ }
311
+ args.forEach(cmdArg => {
312
+ if (cmdArg === `--${booleanName}`) {
313
+ flags[flagKey] = true;
314
+ knownArgs.push(cmdArg);
315
+ }
316
+ else if (cmdArg === `--${flagKey}`) {
317
+ flags[flagKey] = true;
318
+ knownArgs.push(cmdArg);
319
+ }
320
+ else if (cmdArg === `--no-${booleanName}`) {
321
+ flags[flagKey] = false;
322
+ knownArgs.push(cmdArg);
323
+ }
324
+ else if (cmdArg === `--no${dashToPascalCase(booleanName)}`) {
325
+ flags[flagKey] = false;
326
+ knownArgs.push(cmdArg);
327
+ }
328
+ else if (alias && cmdArg === `-${alias}`) {
329
+ flags[flagKey] = true;
330
+ knownArgs.push(cmdArg);
331
+ }
332
+ });
333
+ });
334
+ ARG_OPTS.string.forEach(stringName => {
335
+ const alias = ARG_OPTS.alias[stringName];
336
+ const flagKey = configCase(stringName);
337
+ if (typeof flags[flagKey] !== 'string') {
338
+ flags[flagKey] = null;
339
+ }
340
+ for (let i = 0; i < args.length; i++) {
341
+ const cmdArg = args[i];
342
+ if (cmdArg.startsWith(`--${stringName}=`)) {
343
+ const values = cmdArg.split('=');
344
+ values.shift();
345
+ flags[flagKey] = values.join('=');
346
+ knownArgs.push(cmdArg);
347
+ }
348
+ else if (cmdArg === `--${stringName}`) {
349
+ flags[flagKey] = args[i + 1];
350
+ knownArgs.push(cmdArg);
351
+ knownArgs.push(args[i + 1]);
352
+ }
353
+ else if (cmdArg === `--${flagKey}`) {
354
+ flags[flagKey] = args[i + 1];
355
+ knownArgs.push(cmdArg);
356
+ knownArgs.push(args[i + 1]);
357
+ }
358
+ else if (cmdArg.startsWith(`--${flagKey}=`)) {
359
+ const values = cmdArg.split('=');
360
+ values.shift();
361
+ flags[flagKey] = values.join('=');
362
+ knownArgs.push(cmdArg);
363
+ }
364
+ else if (alias) {
365
+ if (cmdArg.startsWith(`-${alias}=`)) {
366
+ const values = cmdArg.split('=');
367
+ values.shift();
368
+ flags[flagKey] = values.join('=');
369
+ knownArgs.push(cmdArg);
370
+ }
371
+ else if (cmdArg === `-${alias}`) {
372
+ flags[flagKey] = args[i + 1];
373
+ knownArgs.push(args[i + 1]);
374
+ }
375
+ }
376
+ }
377
+ });
378
+ ARG_OPTS.number.forEach(numberName => {
379
+ const alias = ARG_OPTS.alias[numberName];
380
+ const flagKey = configCase(numberName);
381
+ if (typeof flags[flagKey] !== 'number') {
382
+ flags[flagKey] = null;
383
+ }
384
+ for (let i = 0; i < args.length; i++) {
385
+ const cmdArg = args[i];
386
+ if (cmdArg.startsWith(`--${numberName}=`)) {
387
+ const values = cmdArg.split('=');
388
+ values.shift();
389
+ flags[flagKey] = parseInt(values.join(''), 10);
390
+ knownArgs.push(cmdArg);
391
+ }
392
+ else if (cmdArg === `--${numberName}`) {
393
+ flags[flagKey] = parseInt(args[i + 1], 10);
394
+ knownArgs.push(args[i + 1]);
395
+ }
396
+ else if (cmdArg.startsWith(`--${flagKey}=`)) {
397
+ const values = cmdArg.split('=');
398
+ values.shift();
399
+ flags[flagKey] = parseInt(values.join(''), 10);
400
+ knownArgs.push(cmdArg);
401
+ }
402
+ else if (cmdArg === `--${flagKey}`) {
403
+ flags[flagKey] = parseInt(args[i + 1], 10);
404
+ knownArgs.push(args[i + 1]);
405
+ }
406
+ else if (alias) {
407
+ if (cmdArg.startsWith(`-${alias}=`)) {
408
+ const values = cmdArg.split('=');
409
+ values.shift();
410
+ flags[flagKey] = parseInt(values.join(''), 10);
411
+ knownArgs.push(cmdArg);
412
+ }
413
+ else if (cmdArg === `-${alias}`) {
414
+ flags[flagKey] = parseInt(args[i + 1], 10);
415
+ knownArgs.push(args[i + 1]);
416
+ }
417
+ }
418
+ }
419
+ });
420
+ };
421
+ const configCase = (prop) => {
422
+ prop = dashToPascalCase(prop);
423
+ return prop.charAt(0).toLowerCase() + prop.substr(1);
424
+ };
425
+ const ARG_OPTS = {
426
+ boolean: [
427
+ 'build',
428
+ 'cache',
429
+ 'check-version',
430
+ 'ci',
431
+ 'compare',
432
+ 'debug',
433
+ 'dev',
434
+ 'devtools',
435
+ 'docs',
436
+ 'e2e',
437
+ 'es5',
438
+ 'esm',
439
+ 'headless',
440
+ 'help',
441
+ 'log',
442
+ 'open',
443
+ 'prerender',
444
+ 'prerender-external',
445
+ 'prod',
446
+ 'profile',
447
+ 'service-worker',
448
+ 'screenshot',
449
+ 'serve',
450
+ 'skip-node-check',
451
+ 'spec',
452
+ 'ssr',
453
+ 'stats',
454
+ 'update-screenshot',
455
+ 'verbose',
456
+ 'version',
457
+ 'watch',
458
+ ],
459
+ number: ['max-workers', 'port'],
460
+ string: ['address', 'config', 'docs-json', 'emulate', 'log-level', 'root', 'screenshot-connector'],
461
+ alias: {
462
+ config: 'c',
463
+ help: 'h',
464
+ port: 'p',
465
+ version: 'v',
466
+ },
467
+ };
468
+ const getNpmConfigEnvArgs = (sys) => {
469
+ // process.env.npm_config_argv
470
+ // {"remain":["4444"],"cooked":["run","serve","--port","4444"],"original":["run","serve","--port","4444"]}
471
+ let args = [];
472
+ try {
473
+ const npmConfigArgs = sys.getEnvironmentVar('npm_config_argv');
474
+ if (npmConfigArgs) {
475
+ args = JSON.parse(npmConfigArgs).original;
476
+ if (args[0] === 'run') {
477
+ args = args.slice(2);
478
+ }
479
+ }
480
+ }
481
+ catch (e) { }
482
+ return args;
483
+ };
484
+
485
+ const dependencies = [
486
+ {
487
+ name: "@rindo/core",
488
+ version: "2.5.2",
489
+ main: "compiler/rindo.js",
490
+ resources: [
491
+ "package.json",
492
+ "compiler/lib.d.ts",
493
+ "compiler/lib.dom.d.ts",
494
+ "compiler/lib.dom.iterable.d.ts",
495
+ "compiler/lib.es2015.collection.d.ts",
496
+ "compiler/lib.es2015.core.d.ts",
497
+ "compiler/lib.es2015.d.ts",
498
+ "compiler/lib.es2015.generator.d.ts",
499
+ "compiler/lib.es2015.iterable.d.ts",
500
+ "compiler/lib.es2015.promise.d.ts",
501
+ "compiler/lib.es2015.proxy.d.ts",
502
+ "compiler/lib.es2015.reflect.d.ts",
503
+ "compiler/lib.es2015.symbol.d.ts",
504
+ "compiler/lib.es2015.symbol.wellknown.d.ts",
505
+ "compiler/lib.es2016.array.include.d.ts",
506
+ "compiler/lib.es2016.d.ts",
507
+ "compiler/lib.es2016.full.d.ts",
508
+ "compiler/lib.es2017.d.ts",
509
+ "compiler/lib.es2017.full.d.ts",
510
+ "compiler/lib.es2017.intl.d.ts",
511
+ "compiler/lib.es2017.object.d.ts",
512
+ "compiler/lib.es2017.sharedmemory.d.ts",
513
+ "compiler/lib.es2017.string.d.ts",
514
+ "compiler/lib.es2017.typedarrays.d.ts",
515
+ "compiler/lib.es2018.asyncgenerator.d.ts",
516
+ "compiler/lib.es2018.asynciterable.d.ts",
517
+ "compiler/lib.es2018.d.ts",
518
+ "compiler/lib.es2018.full.d.ts",
519
+ "compiler/lib.es2018.intl.d.ts",
520
+ "compiler/lib.es2018.promise.d.ts",
521
+ "compiler/lib.es2018.regexp.d.ts",
522
+ "compiler/lib.es2019.array.d.ts",
523
+ "compiler/lib.es2019.d.ts",
524
+ "compiler/lib.es2019.full.d.ts",
525
+ "compiler/lib.es2019.object.d.ts",
526
+ "compiler/lib.es2019.string.d.ts",
527
+ "compiler/lib.es2019.symbol.d.ts",
528
+ "compiler/lib.es2020.bigint.d.ts",
529
+ "compiler/lib.es2020.d.ts",
530
+ "compiler/lib.es2020.full.d.ts",
531
+ "compiler/lib.es2020.intl.d.ts",
532
+ "compiler/lib.es2020.promise.d.ts",
533
+ "compiler/lib.es2020.sharedmemory.d.ts",
534
+ "compiler/lib.es2020.string.d.ts",
535
+ "compiler/lib.es2020.symbol.wellknown.d.ts",
536
+ "compiler/lib.es5.d.ts",
537
+ "compiler/lib.es6.d.ts",
538
+ "compiler/lib.esnext.d.ts",
539
+ "compiler/lib.esnext.full.d.ts",
540
+ "compiler/lib.esnext.intl.d.ts",
541
+ "compiler/lib.esnext.promise.d.ts",
542
+ "compiler/lib.esnext.string.d.ts",
543
+ "compiler/lib.esnext.weakref.d.ts",
544
+ "compiler/lib.scripthost.d.ts",
545
+ "compiler/lib.webworker.d.ts",
546
+ "compiler/lib.webworker.importscripts.d.ts",
547
+ "compiler/lib.webworker.iterable.d.ts",
548
+ "internal/index.d.ts",
549
+ "internal/index.js",
550
+ "internal/package.json",
551
+ "internal/rindo-ext-modules.d.ts",
552
+ "internal/rindo-private.d.ts",
553
+ "internal/rindo-public-compiler.d.ts",
554
+ "internal/rindo-public-docs.d.ts",
555
+ "internal/rindo-public-runtime.d.ts",
556
+ "mock-doc/index.js",
557
+ "mock-doc/package.json",
558
+ "internal/client/css-shim.js",
559
+ "internal/client/dom.js",
560
+ "internal/client/index.js",
561
+ "internal/client/package.json",
562
+ "internal/client/patch-browser.js",
563
+ "internal/client/patch-esm.js",
564
+ "internal/client/shadow-css.js",
565
+ "internal/hydrate/index.js",
566
+ "internal/hydrate/package.json",
567
+ "internal/hydrate/runner.js",
568
+ "internal/hydrate/shadow-css.js",
569
+ "internal/rindo-core/index.d.ts",
570
+ "internal/rindo-core/index.js"
571
+ ]
572
+ },
573
+ {
574
+ name: "rollup",
575
+ version: "2.42.3",
576
+ main: "dist/es/rollup.browser.js"
577
+ },
578
+ {
579
+ name: "terser",
580
+ version: "5.6.1",
581
+ main: "dist/bundle.min.js"
582
+ },
583
+ {
584
+ name: "typescript",
585
+ version: "4.2.3",
586
+ main: "lib/typescript.js"
587
+ }
588
+ ];
589
+
590
+ const findConfig = async (opts) => {
591
+ const sys = opts.sys;
592
+ const cwd = sys.getCurrentDirectory();
593
+ const results = {
594
+ configPath: null,
595
+ rootDir: normalizePath(cwd),
596
+ diagnostics: [],
597
+ };
598
+ let configPath = opts.configPath;
599
+ if (isString(configPath)) {
600
+ if (!sys.platformPath.isAbsolute(configPath)) {
601
+ // passed in a custom rindo config location
602
+ // but it's relative, so prefix the cwd
603
+ configPath = normalizePath(sys.platformPath.join(cwd, configPath));
604
+ }
605
+ else {
606
+ // config path already an absolute path, we're good here
607
+ configPath = normalizePath(opts.configPath);
608
+ }
609
+ }
610
+ else {
611
+ // nothing was passed in, use the current working directory
612
+ configPath = results.rootDir;
613
+ }
614
+ const stat = await sys.stat(configPath);
615
+ if (stat.error) {
616
+ const diagnostic = buildError(results.diagnostics);
617
+ diagnostic.absFilePath = configPath;
618
+ diagnostic.header = `Invalid config path`;
619
+ diagnostic.messageText = `Config path "${configPath}" not found`;
620
+ return results;
621
+ }
622
+ if (stat.isFile) {
623
+ results.configPath = configPath;
624
+ results.rootDir = sys.platformPath.dirname(configPath);
625
+ }
626
+ else if (stat.isDirectory) {
627
+ // this is only a directory, so let's make some assumptions
628
+ for (const configName of ['rindo.config.ts', 'rindo.config.js']) {
629
+ const testConfigFilePath = sys.platformPath.join(configPath, configName);
630
+ const stat = await sys.stat(testConfigFilePath);
631
+ if (stat.isFile) {
632
+ results.configPath = testConfigFilePath;
633
+ results.rootDir = sys.platformPath.dirname(testConfigFilePath);
634
+ break;
635
+ }
636
+ }
637
+ }
638
+ return results;
639
+ };
640
+
641
+ const loadCoreCompiler = async (sys) => {
642
+ await sys.dynamicImport(sys.getCompilerExecutingPath());
643
+ return globalThis.rindo;
644
+ };
645
+
646
+ const startupLog = (logger, task) => {
647
+ if (task === 'info' || task === 'serve' || task === 'version') {
648
+ return;
649
+ }
650
+ logger.info(logger.cyan(`@rindo/core`));
651
+ };
652
+ const startupLogVersion = (logger, task, coreCompiler) => {
653
+ if (task === 'info' || task === 'serve' || task === 'version') {
654
+ return;
655
+ }
656
+ const isDevBuild = coreCompiler.version.includes('-dev.');
657
+ let startupMsg;
658
+ if (isDevBuild) {
659
+ startupMsg = logger.yellow('[LOCAL DEV]');
660
+ }
661
+ else {
662
+ startupMsg = logger.cyan(`v${coreCompiler.version}`);
663
+ }
664
+ startupMsg += logger.emoji(' ' + coreCompiler.vermoji);
665
+ logger.info(startupMsg);
666
+ };
667
+ const loadedCompilerLog = (sys, logger, flags, coreCompiler) => {
668
+ const sysDetails = sys.details;
669
+ const runtimeInfo = `${sys.name} ${sys.version}`;
670
+ const platformInfo = `${sysDetails.platform}, ${sysDetails.cpuModel}`;
671
+ const statsInfo = `cpus: ${sys.hardwareConcurrency}, freemem: ${Math.round(sysDetails.freemem() / 1000000)}MB, totalmem: ${Math.round(sysDetails.totalmem / 1000000)}MB`;
672
+ if (logger.getLevel() === 'debug') {
673
+ logger.debug(runtimeInfo);
674
+ logger.debug(platformInfo);
675
+ logger.debug(statsInfo);
676
+ logger.debug(`compiler: ${sys.getCompilerExecutingPath()}`);
677
+ logger.debug(`build: ${coreCompiler.buildId}`);
678
+ }
679
+ else if (flags.ci) {
680
+ logger.info(runtimeInfo);
681
+ logger.info(platformInfo);
682
+ logger.info(statsInfo);
683
+ }
684
+ };
685
+ const startupCompilerLog = (coreCompiler, config) => {
686
+ if (config.suppressLogs === true) {
687
+ return;
688
+ }
689
+ const { logger } = config;
690
+ const isDebug = logger.getLevel() === 'debug';
691
+ const isPrerelease = coreCompiler.version.includes('-');
692
+ const isDevBuild = coreCompiler.version.includes('-dev.');
693
+ if (isPrerelease && !isDevBuild) {
694
+ logger.warn(logger.yellow(`This is a prerelease build, undocumented changes might happen at any time. Technical support is not available for prereleases, but any assistance testing is appreciated.`));
695
+ }
696
+ if (config.devMode && !isDebug) {
697
+ if (config.buildEs5) {
698
+ logger.warn(`Generating ES5 during development is a very task expensive, initial and incremental builds will be much slower. Drop the '--es5' flag and use a modern browser for development.`);
699
+ }
700
+ if (!config.enableCache) {
701
+ logger.warn(`Disabling cache during development will slow down incremental builds.`);
702
+ }
703
+ }
704
+ };
705
+
706
+ const taskPrerender = async (coreCompiler, config) => {
707
+ startupCompilerLog(coreCompiler, config);
708
+ const hydrateAppFilePath = config.flags.unknownArgs[0];
709
+ if (typeof hydrateAppFilePath !== 'string') {
710
+ config.logger.error(`Missing hydrate app script path`);
711
+ return config.sys.exit(1);
712
+ }
713
+ const srcIndexHtmlPath = config.srcIndexHtml;
714
+ const diagnostics = await runPrerenderTask(coreCompiler, config, hydrateAppFilePath, null, srcIndexHtmlPath);
715
+ config.logger.printDiagnostics(diagnostics);
716
+ if (diagnostics.some(d => d.level === 'error')) {
717
+ return config.sys.exit(1);
718
+ }
719
+ };
720
+ const runPrerenderTask = async (coreCompiler, config, hydrateAppFilePath, componentGraph, srcIndexHtmlPath) => {
721
+ const diagnostics = [];
722
+ try {
723
+ const prerenderer = await coreCompiler.createPrerenderer(config);
724
+ const results = await prerenderer.start({
725
+ hydrateAppFilePath,
726
+ componentGraph,
727
+ srcIndexHtmlPath,
728
+ });
729
+ diagnostics.push(...results.diagnostics);
730
+ }
731
+ catch (e) {
732
+ catchError(diagnostics, e);
733
+ }
734
+ return diagnostics;
735
+ };
736
+
737
+ const startCheckVersion = async (config, currentVersion) => {
738
+ if (config.devMode && !config.flags.ci && !currentVersion.includes('-dev.') && isFunction(config.sys.checkVersion)) {
739
+ return config.sys.checkVersion(config.logger, currentVersion);
740
+ }
741
+ return null;
742
+ };
743
+ const printCheckVersionResults = async (versionChecker) => {
744
+ if (versionChecker) {
745
+ const checkVersionResults = await versionChecker;
746
+ if (isFunction(checkVersionResults)) {
747
+ checkVersionResults();
748
+ }
749
+ }
750
+ };
751
+
752
+ const taskWatch = async (coreCompiler, config) => {
753
+ let devServer = null;
754
+ let exitCode = 0;
755
+ try {
756
+ startupCompilerLog(coreCompiler, config);
757
+ const versionChecker = startCheckVersion(config, coreCompiler.version);
758
+ const compiler = await coreCompiler.createCompiler(config);
759
+ const watcher = await compiler.createWatcher();
760
+ if (config.flags.serve) {
761
+ const devServerPath = config.sys.getDevServerExecutingPath();
762
+ const { start } = await config.sys.dynamicImport(devServerPath);
763
+ devServer = await start(config.devServer, config.logger, watcher);
764
+ }
765
+ config.sys.onProcessInterrupt(() => {
766
+ config.logger.debug(`close watch`);
767
+ compiler && compiler.destroy();
768
+ });
769
+ const rmVersionCheckerLog = watcher.on('buildFinish', async () => {
770
+ // log the version check one time
771
+ rmVersionCheckerLog();
772
+ printCheckVersionResults(versionChecker);
773
+ });
774
+ if (devServer) {
775
+ const rmDevServerLog = watcher.on('buildFinish', () => {
776
+ // log the dev server url one time
777
+ rmDevServerLog();
778
+ config.logger.info(`${config.logger.cyan(devServer.browserUrl)}\n`);
779
+ });
780
+ }
781
+ const closeResults = await watcher.start();
782
+ if (closeResults.exitCode > 0) {
783
+ exitCode = closeResults.exitCode;
784
+ }
785
+ }
786
+ catch (e) {
787
+ exitCode = 1;
788
+ config.logger.error(e);
789
+ }
790
+ if (devServer) {
791
+ await devServer.close();
792
+ }
793
+ if (exitCode > 0) {
794
+ return config.sys.exit(exitCode);
795
+ }
796
+ };
797
+
798
+ const taskBuild = async (coreCompiler, config) => {
799
+ if (config.flags.watch) {
800
+ // watch build
801
+ await taskWatch(coreCompiler, config);
802
+ return;
803
+ }
804
+ // one-time build
805
+ let exitCode = 0;
806
+ try {
807
+ startupCompilerLog(coreCompiler, config);
808
+ const versionChecker = startCheckVersion(config, coreCompiler.version);
809
+ const compiler = await coreCompiler.createCompiler(config);
810
+ const results = await compiler.build();
811
+ await compiler.destroy();
812
+ if (results.hasError) {
813
+ exitCode = 1;
814
+ }
815
+ else if (config.flags.prerender) {
816
+ const prerenderDiagnostics = await runPrerenderTask(coreCompiler, config, results.hydrateAppFilePath, results.componentGraph, null);
817
+ config.logger.printDiagnostics(prerenderDiagnostics);
818
+ if (prerenderDiagnostics.some(d => d.level === 'error')) {
819
+ exitCode = 1;
820
+ }
821
+ }
822
+ await printCheckVersionResults(versionChecker);
823
+ }
824
+ catch (e) {
825
+ exitCode = 1;
826
+ config.logger.error(e);
827
+ }
828
+ if (exitCode > 0) {
829
+ return config.sys.exit(exitCode);
830
+ }
831
+ };
832
+
833
+ const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
834
+ const DOCS_CUSTOM = 'docs-custom';
835
+ const DOCS_JSON = `docs-json`;
836
+ const DOCS_README = `docs-readme`;
837
+ const DOCS_VSCODE = `docs-vscode`;
838
+
839
+ const taskDocs = async (coreCompiler, config) => {
840
+ config.devServer = null;
841
+ config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
842
+ config.devMode = true;
843
+ startupCompilerLog(coreCompiler, config);
844
+ const compiler = await coreCompiler.createCompiler(config);
845
+ await compiler.build();
846
+ await compiler.destroy();
847
+ };
848
+
849
+ const IS_DENO_ENV = typeof Deno !== 'undefined';
850
+ const IS_NODE_ENV = !IS_DENO_ENV &&
851
+ typeof global !== 'undefined' &&
852
+ typeof require === 'function' &&
853
+ !!global.process &&
854
+ typeof __filename === 'string' &&
855
+ (!global.origin || typeof global.origin !== 'string');
856
+
857
+ /**
858
+ * Task to generate component boilerplate.
859
+ */
860
+ const taskGenerate = async (coreCompiler, config) => {
861
+ if (!IS_NODE_ENV) {
862
+ config.logger.error(`"generate" command is currently only implemented for a NodeJS environment`);
863
+ return config.sys.exit(1);
864
+ }
865
+ const path = coreCompiler.path;
866
+ if (!config.configPath) {
867
+ config.logger.error('Please run this command in your root directory (i. e. the one containing rindo.config.ts).');
868
+ return config.sys.exit(1);
869
+ }
870
+ const absoluteSrcDir = config.srcDir;
871
+ if (!absoluteSrcDir) {
872
+ config.logger.error(`Rindo's srcDir was not specified.`);
873
+ return config.sys.exit(1);
874
+ }
875
+ const { prompt } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('../sys/node/prompts.js')); });
876
+ const input = config.flags.unknownArgs.find(arg => !arg.startsWith('-')) ||
877
+ (await prompt({ name: 'tagName', type: 'text', message: 'Component tag name (dash-case):' })).tagName;
878
+ const { dir, base: componentName } = path.parse(input);
879
+ const tagError = validateComponentTag(componentName);
880
+ if (tagError) {
881
+ config.logger.error(tagError);
882
+ return config.sys.exit(1);
883
+ }
884
+ const extensionsToGenerate = ['tsx', ...(await chooseFilesToGenerate())];
885
+ const testFolder = extensionsToGenerate.some(isTest) ? 'test' : '';
886
+ const outDir = path.join(absoluteSrcDir, 'components', dir, componentName);
887
+ await config.sys.createDir(path.join(outDir, testFolder), { recursive: true });
888
+ const writtenFiles = await Promise.all(extensionsToGenerate.map(extension => writeFileByExtension(coreCompiler, config, outDir, componentName, extension, extensionsToGenerate.includes('css')))).catch(error => config.logger.error(error));
889
+ if (!writtenFiles) {
890
+ return config.sys.exit(1);
891
+ }
892
+ console.log();
893
+ console.log(`${config.logger.gray('$')} rindo generate ${input}`);
894
+ console.log();
895
+ console.log(config.logger.bold('The following files have been generated:'));
896
+ const absoluteRootDir = config.rootDir;
897
+ writtenFiles.map(file => console.log(` - ${path.relative(absoluteRootDir, file)}`));
898
+ };
899
+ /**
900
+ * Show a checkbox prompt to select the files to be generated.
901
+ */
902
+ const chooseFilesToGenerate = async () => {
903
+ const { prompt } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('../sys/node/prompts.js')); });
904
+ return (await prompt({
905
+ name: 'filesToGenerate',
906
+ type: 'multiselect',
907
+ message: 'Which additional files do you want to generate?',
908
+ choices: [
909
+ { value: 'css', title: 'Stylesheet (.css)', selected: true },
910
+ { value: 'spec.tsx', title: 'Spec Test (.spec.tsx)', selected: true },
911
+ { value: 'e2e.ts', title: 'E2E Test (.e2e.ts)', selected: true },
912
+ ],
913
+ })).filesToGenerate;
914
+ };
915
+ /**
916
+ * Get a file's boilerplate by its extension and write it to disk.
917
+ */
918
+ const writeFileByExtension = async (coreCompiler, config, path, name, extension, withCss) => {
919
+ if (isTest(extension)) {
920
+ path = coreCompiler.path.join(path, 'test');
921
+ }
922
+ const outFile = coreCompiler.path.join(path, `${name}.${extension}`);
923
+ const boilerplate = getBoilerplateByExtension(name, extension, withCss);
924
+ await config.sys.writeFile(outFile, boilerplate);
925
+ return outFile;
926
+ };
927
+ const isTest = (extension) => {
928
+ return extension === 'e2e.ts' || extension === 'spec.tsx';
929
+ };
930
+ /**
931
+ * Get the boilerplate for a file by its extension.
932
+ */
933
+ const getBoilerplateByExtension = (tagName, extension, withCss) => {
934
+ switch (extension) {
935
+ case 'tsx':
936
+ return getComponentBoilerplate(tagName, withCss);
937
+ case 'css':
938
+ return getStyleUrlBoilerplate();
939
+ case 'spec.tsx':
940
+ return getSpecTestBoilerplate(tagName);
941
+ case 'e2e.ts':
942
+ return getE2eTestBoilerplate(tagName);
943
+ default:
944
+ throw new Error(`Unkown extension "${extension}".`);
945
+ }
946
+ };
947
+ /**
948
+ * Get the boilerplate for a component.
949
+ */
950
+ const getComponentBoilerplate = (tagName, hasStyle) => {
951
+ const decorator = [`{`];
952
+ decorator.push(` tag: '${tagName}',`);
953
+ if (hasStyle) {
954
+ decorator.push(` styleUrl: '${tagName}.css',`);
955
+ }
956
+ decorator.push(` shadow: true,`);
957
+ decorator.push(`}`);
958
+ return `import { Component, Host, h } from '@rindo/core';
959
+
960
+ @Component(${decorator.join('\n')})
961
+ export class ${toPascalCase(tagName)} {
962
+
963
+ render() {
964
+ return (
965
+ <Host>
966
+ <slot></slot>
967
+ </Host>
968
+ );
969
+ }
970
+
971
+ }
972
+ `;
973
+ };
974
+ /**
975
+ * Get the boilerplate for style.
976
+ */
977
+ const getStyleUrlBoilerplate = () => `:host {
978
+ display: block;
979
+ }
980
+ `;
981
+ /**
982
+ * Get the boilerplate for a spec test.
983
+ */
984
+ const getSpecTestBoilerplate = (tagName) => `import { newSpecPage } from '@rindo/core/testing';
985
+ import { ${toPascalCase(tagName)} } from '../${tagName}';
986
+
987
+ describe('${tagName}', () => {
988
+ it('renders', async () => {
989
+ const page = await newSpecPage({
990
+ components: [${toPascalCase(tagName)}],
991
+ html: \`<${tagName}></${tagName}>\`,
992
+ });
993
+ expect(page.root).toEqualHtml(\`
994
+ <${tagName}>
995
+ <mock:shadow-root>
996
+ <slot></slot>
997
+ </mock:shadow-root>
998
+ </${tagName}>
999
+ \`);
1000
+ });
1001
+ });
1002
+ `;
1003
+ /**
1004
+ * Get the boilerplate for an E2E test.
1005
+ */
1006
+ const getE2eTestBoilerplate = (name) => `import { newE2EPage } from '@rindo/core/testing';
1007
+
1008
+ describe('${name}', () => {
1009
+ it('renders', async () => {
1010
+ const page = await newE2EPage();
1011
+ await page.setContent('<${name}></${name}>');
1012
+
1013
+ const element = await page.find('${name}');
1014
+ expect(element).toHaveClass('hydrated');
1015
+ });
1016
+ });
1017
+ `;
1018
+ /**
1019
+ * Convert a dash case string to pascal case.
1020
+ */
1021
+ const toPascalCase = (str) => str.split('-').reduce((res, part) => res + part[0].toUpperCase() + part.substr(1), '');
1022
+
1023
+ const taskHelp = (sys, logger) => {
1024
+ const p = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
1025
+ console.log(`
1026
+ ${logger.bold('Build:')} ${logger.dim('Build components for development or production.')}
1027
+
1028
+ ${p} ${logger.green('rindo build [--dev] [--watch] [--prerender] [--debug]')}
1029
+
1030
+ ${logger.cyan('--dev')} ${logger.dim('.............')} Development build
1031
+ ${logger.cyan('--watch')} ${logger.dim('...........')} Rebuild when files update
1032
+ ${logger.cyan('--serve')} ${logger.dim('...........')} Start the dev-server
1033
+ ${logger.cyan('--prerender')} ${logger.dim('.......')} Prerender the application
1034
+ ${logger.cyan('--docs')} ${logger.dim('............')} Generate component readme.md docs
1035
+ ${logger.cyan('--config')} ${logger.dim('..........')} Set rindo config file
1036
+ ${logger.cyan('--stats')} ${logger.dim('...........')} Write rindo-stats.json file
1037
+ ${logger.cyan('--log')} ${logger.dim('.............')} Write rindo-build.log file
1038
+ ${logger.cyan('--debug')} ${logger.dim('...........')} Set the log level to debug
1039
+
1040
+
1041
+ ${logger.bold('Test:')} ${logger.dim('Run unit and end-to-end tests.')}
1042
+
1043
+ ${p} ${logger.green('rindo test [--spec] [--e2e]')}
1044
+
1045
+ ${logger.cyan('--spec')} ${logger.dim('............')} Run unit tests with Jest
1046
+ ${logger.cyan('--e2e')} ${logger.dim('.............')} Run e2e tests with Puppeteer
1047
+
1048
+
1049
+ ${logger.bold('Generate:')} ${logger.dim('Bootstrap components.')}
1050
+
1051
+ ${p} ${logger.green('rindo generate')} or ${logger.green('rindo g')}
1052
+
1053
+
1054
+ ${logger.bold('Examples:')}
1055
+
1056
+ ${p} ${logger.green('rindo build --dev --watch --serve')}
1057
+ ${p} ${logger.green('rindo build --prerender')}
1058
+ ${p} ${logger.green('rindo test --spec --e2e')}
1059
+ ${p} ${logger.green('rindo generate')}
1060
+ ${p} ${logger.green('rindo g my-component')}
1061
+
1062
+ `);
1063
+ };
1064
+
1065
+ const taskInfo = (coreCompiler, sys, logger) => {
1066
+ const details = sys.details;
1067
+ const versions = coreCompiler.versions;
1068
+ console.log(``);
1069
+ console.log(`${logger.cyan(' System:')} ${sys.name} ${sys.version}`);
1070
+ console.log(`${logger.cyan(' Plaform:')} ${details.platform} (${details.release})`);
1071
+ console.log(`${logger.cyan(' CPU Model:')} ${details.cpuModel} (${sys.hardwareConcurrency} cpu${sys.hardwareConcurrency !== 1 ? 's' : ''})`);
1072
+ console.log(`${logger.cyan(' Compiler:')} ${sys.getCompilerExecutingPath()}`);
1073
+ console.log(`${logger.cyan(' Build:')} ${coreCompiler.buildId}`);
1074
+ console.log(`${logger.cyan(' Rindo:')} ${coreCompiler.version}${logger.emoji(' ' + coreCompiler.vermoji)}`);
1075
+ console.log(`${logger.cyan(' TypeScript:')} ${versions.typescript}`);
1076
+ console.log(`${logger.cyan(' Rollup:')} ${versions.rollup}`);
1077
+ console.log(`${logger.cyan(' Parse5:')} ${versions.parse5}`);
1078
+ console.log(`${logger.cyan(' Sizzle:')} ${versions.sizzle}`);
1079
+ console.log(`${logger.cyan(' Terser:')} ${versions.terser}`);
1080
+ console.log(``);
1081
+ };
1082
+
1083
+ const taskServe = async (config) => {
1084
+ config.suppressLogs = true;
1085
+ config.flags.serve = true;
1086
+ config.devServer.openBrowser = config.flags.open;
1087
+ config.devServer.reloadStrategy = null;
1088
+ config.devServer.initialLoadUrl = '/';
1089
+ config.devServer.websocket = false;
1090
+ config.maxConcurrentWorkers = 1;
1091
+ config.devServer.root = isString(config.flags.root) ? config.flags.root : config.sys.getCurrentDirectory();
1092
+ const devServerPath = config.sys.getDevServerExecutingPath();
1093
+ const { start } = await config.sys.dynamicImport(devServerPath);
1094
+ const devServer = await start(config.devServer, config.logger);
1095
+ console.log(`${config.logger.cyan(' Root:')} ${devServer.root}`);
1096
+ console.log(`${config.logger.cyan(' Address:')} ${devServer.address}`);
1097
+ console.log(`${config.logger.cyan(' Port:')} ${devServer.port}`);
1098
+ console.log(`${config.logger.cyan(' Server:')} ${devServer.browserUrl}`);
1099
+ console.log(``);
1100
+ config.sys.onProcessInterrupt(() => {
1101
+ if (devServer) {
1102
+ config.logger.debug(`dev server close: ${devServer.browserUrl}`);
1103
+ devServer.close();
1104
+ }
1105
+ });
1106
+ };
1107
+
1108
+ const taskTest = async (config) => {
1109
+ if (!IS_NODE_ENV) {
1110
+ config.logger.error(`"test" command is currently only implemented for a NodeJS environment`);
1111
+ return config.sys.exit(1);
1112
+ }
1113
+ try {
1114
+ config.buildDocs = false;
1115
+ const testingRunOpts = {
1116
+ e2e: !!config.flags.e2e,
1117
+ screenshot: !!config.flags.screenshot,
1118
+ spec: !!config.flags.spec,
1119
+ updateScreenshot: !!config.flags.updateScreenshot,
1120
+ };
1121
+ // always ensure we have jest modules installed
1122
+ const ensureModuleIds = ['@types/jest', 'jest', 'jest-cli'];
1123
+ if (testingRunOpts.e2e) {
1124
+ // if it's an e2e test, also make sure we're got
1125
+ // puppeteer modules installed and if browserExecutablePath is provided don't download Chromium use only puppeteer-core instead
1126
+ const puppeteer = config.testing.browserExecutablePath ? 'puppeteer-core' : 'puppeteer';
1127
+ ensureModuleIds.push('@types/puppeteer', puppeteer);
1128
+ if (testingRunOpts.screenshot) {
1129
+ // ensure we've got pixelmatch for screenshots
1130
+ config.logger.warn(config.logger.yellow(`EXPERIMENTAL: screenshot visual diff testing is currently under heavy development and has not reached a stable status. However, any assistance testing would be appreciated.`));
1131
+ }
1132
+ }
1133
+ // ensure we've got the required modules installed
1134
+ const diagnostics = await config.sys.lazyRequire.ensure(config.rootDir, ensureModuleIds);
1135
+ if (diagnostics.length > 0) {
1136
+ config.logger.printDiagnostics(diagnostics);
1137
+ return config.sys.exit(1);
1138
+ }
1139
+ // let's test!
1140
+ const { createTesting } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('../testing/index.js')); });
1141
+ const testing = await createTesting(config);
1142
+ const passed = await testing.run(testingRunOpts);
1143
+ await testing.destroy();
1144
+ if (!passed) {
1145
+ return config.sys.exit(1);
1146
+ }
1147
+ }
1148
+ catch (e) {
1149
+ config.logger.error(e);
1150
+ return config.sys.exit(1);
1151
+ }
1152
+ };
1153
+
1154
+ const run = async (init) => {
1155
+ const { args, logger, sys } = init;
1156
+ try {
1157
+ const flags = parseFlags(args, sys);
1158
+ const task = flags.task;
1159
+ if (flags.debug || flags.verbose) {
1160
+ logger.setLevel('debug');
1161
+ }
1162
+ if (flags.ci) {
1163
+ logger.enableColors(false);
1164
+ }
1165
+ if (isFunction(sys.applyGlobalPatch)) {
1166
+ sys.applyGlobalPatch(sys.getCurrentDirectory());
1167
+ }
1168
+ if (task === 'help' || flags.help) {
1169
+ taskHelp(sys, logger);
1170
+ return;
1171
+ }
1172
+ startupLog(logger, task);
1173
+ const findConfigResults = await findConfig({ sys, configPath: flags.config });
1174
+ if (hasError(findConfigResults.diagnostics)) {
1175
+ logger.printDiagnostics(findConfigResults.diagnostics);
1176
+ return sys.exit(1);
1177
+ }
1178
+ const ensureDepsResults = await sys.ensureDependencies({
1179
+ rootDir: findConfigResults.rootDir,
1180
+ logger,
1181
+ dependencies: dependencies,
1182
+ });
1183
+ if (hasError(ensureDepsResults.diagnostics)) {
1184
+ logger.printDiagnostics(ensureDepsResults.diagnostics);
1185
+ return sys.exit(1);
1186
+ }
1187
+ const coreCompiler = await loadCoreCompiler(sys);
1188
+ if (task === 'version' || flags.version) {
1189
+ console.log(coreCompiler.version);
1190
+ return;
1191
+ }
1192
+ startupLogVersion(logger, task, coreCompiler);
1193
+ loadedCompilerLog(sys, logger, flags, coreCompiler);
1194
+ if (task === 'info') {
1195
+ taskInfo(coreCompiler, sys, logger);
1196
+ return;
1197
+ }
1198
+ const validated = await coreCompiler.loadConfig({
1199
+ config: {
1200
+ flags,
1201
+ },
1202
+ configPath: findConfigResults.configPath,
1203
+ logger,
1204
+ sys,
1205
+ });
1206
+ if (validated.diagnostics.length > 0) {
1207
+ logger.printDiagnostics(validated.diagnostics);
1208
+ if (hasError(validated.diagnostics)) {
1209
+ return sys.exit(1);
1210
+ }
1211
+ }
1212
+ if (isFunction(sys.applyGlobalPatch)) {
1213
+ sys.applyGlobalPatch(validated.config.rootDir);
1214
+ }
1215
+ await sys.ensureResources({ rootDir: validated.config.rootDir, logger, dependencies: dependencies });
1216
+ await runTask(coreCompiler, validated.config, task);
1217
+ }
1218
+ catch (e) {
1219
+ if (!shouldIgnoreError(e)) {
1220
+ logger.error(`uncaught cli error: ${e}${logger.getLevel() === 'debug' ? e.stack : ''}`);
1221
+ return sys.exit(1);
1222
+ }
1223
+ }
1224
+ };
1225
+ const runTask = async (coreCompiler, config, task) => {
1226
+ config.flags = config.flags || {};
1227
+ config.outputTargets = config.outputTargets || [];
1228
+ switch (task) {
1229
+ case 'build':
1230
+ await taskBuild(coreCompiler, config);
1231
+ break;
1232
+ case 'docs':
1233
+ await taskDocs(coreCompiler, config);
1234
+ break;
1235
+ case 'help':
1236
+ taskHelp(config.sys, config.logger);
1237
+ break;
1238
+ case 'generate':
1239
+ case 'g':
1240
+ await taskGenerate(coreCompiler, config);
1241
+ break;
1242
+ case 'prerender':
1243
+ await taskPrerender(coreCompiler, config);
1244
+ break;
1245
+ case 'serve':
1246
+ await taskServe(config);
1247
+ break;
1248
+ case 'test':
1249
+ await taskTest(config);
1250
+ break;
1251
+ case 'version':
1252
+ console.log(coreCompiler.version);
1253
+ break;
1254
+ default:
1255
+ config.logger.error(`${config.logger.emoji('❌ ')}Invalid rindo command, please see the options below:`);
1256
+ taskHelp(config.sys, config.logger);
1257
+ return config.sys.exit(1);
1258
+ }
1259
+ };
1260
+
1261
+ exports.parseFlags = parseFlags;
1262
+ exports.run = run;
1263
+ exports.runTask = runTask;