piral-cli 1.0.0-pre.2217 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +30 -7
- package/lib/api.js +23 -23
- package/lib/api.js.map +1 -1
- package/lib/apps/add-piral-instance-pilet.d.ts +26 -0
- package/lib/apps/add-piral-instance-pilet.js +53 -0
- package/lib/apps/add-piral-instance-pilet.js.map +1 -0
- package/lib/apps/build-pilet.d.ts +33 -2
- package/lib/apps/build-pilet.js +159 -32
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.d.ts +18 -1
- package/lib/apps/build-piral.js +68 -52
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.d.ts +38 -2
- package/lib/apps/debug-pilet.js +150 -108
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.d.ts +23 -0
- package/lib/apps/debug-piral.js +63 -52
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/declaration-piral.js +5 -3
- package/lib/apps/declaration-piral.js.map +1 -1
- package/lib/apps/index.d.ts +3 -0
- package/lib/apps/index.js +8 -1
- package/lib/apps/index.js.map +1 -1
- package/lib/apps/new-pilet.d.ts +7 -3
- package/lib/apps/new-pilet.js +47 -52
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.d.ts +7 -3
- package/lib/apps/new-piral.js +33 -23
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.d.ts +9 -0
- package/lib/apps/pack-pilet.js +6 -13
- package/lib/apps/pack-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +23 -3
- package/lib/apps/publish-pilet.js +112 -62
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.d.ts +6 -2
- package/lib/apps/publish-piral.js +30 -26
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/remove-piral-instance-pilet.d.ts +22 -0
- package/lib/apps/remove-piral-instance-pilet.js +52 -0
- package/lib/apps/remove-piral-instance-pilet.js.map +1 -0
- package/lib/apps/run-emulator-piral.d.ts +34 -0
- package/lib/apps/run-emulator-piral.js +91 -0
- package/lib/apps/run-emulator-piral.js.map +1 -0
- package/lib/apps/upgrade-pilet.d.ts +6 -2
- package/lib/apps/upgrade-pilet.js +41 -43
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.d.ts +2 -2
- package/lib/apps/upgrade-piral.js +21 -20
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/apps/validate-pilet.js +30 -36
- package/lib/apps/validate-pilet.js.map +1 -1
- package/lib/apps/validate-piral.js +13 -10
- package/lib/apps/validate-piral.js.map +1 -1
- package/lib/build/bundler-calls.d.ts +3 -0
- package/lib/build/bundler-calls.js +117 -0
- package/lib/build/bundler-calls.js.map +1 -0
- package/lib/build/run-build-pilet.d.ts +1 -0
- package/lib/build/run-build-pilet.js +65 -0
- package/lib/build/run-build-pilet.js.map +1 -0
- package/lib/build/run-build-piral.d.ts +1 -0
- package/lib/build/run-build-piral.js +67 -0
- package/lib/build/run-build-piral.js.map +1 -0
- package/lib/build/run-debug-mono-piral.d.ts +1 -0
- package/lib/build/run-debug-mono-piral.js +70 -0
- package/lib/build/run-debug-mono-piral.js.map +1 -0
- package/lib/build/run-debug-pilet.d.ts +1 -0
- package/lib/build/run-debug-pilet.js +89 -0
- package/lib/build/run-debug-pilet.js.map +1 -0
- package/lib/build/run-debug-piral.d.ts +1 -0
- package/lib/build/run-debug-piral.js +85 -0
- package/lib/build/run-debug-piral.js.map +1 -0
- package/lib/bundler.js +75 -26
- package/lib/bundler.js.map +1 -1
- package/lib/cli.js +7 -4
- package/lib/cli.js.map +1 -1
- package/lib/commands.js +266 -46
- package/lib/commands.js.map +1 -1
- package/lib/common/archive.d.ts +4 -0
- package/lib/common/archive.js +31 -10
- package/lib/common/archive.js.map +1 -1
- package/lib/common/browser.d.ts +2 -1
- package/lib/common/browser.js +17 -8
- package/lib/common/browser.js.map +1 -1
- package/lib/common/clients/index.d.ts +21 -0
- package/lib/common/clients/index.js +48 -0
- package/lib/common/clients/index.js.map +1 -0
- package/lib/common/clients/lerna.d.ts +7 -1
- package/lib/common/clients/lerna.js +93 -7
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +6 -1
- package/lib/common/clients/npm.js +66 -18
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnp.d.ts +7 -0
- package/lib/common/clients/pnp.js +104 -0
- package/lib/common/clients/pnp.js.map +1 -0
- package/lib/common/clients/pnpm.d.ts +5 -0
- package/lib/common/clients/pnpm.js +55 -6
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +7 -0
- package/lib/common/clients/rush.js +127 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +5 -0
- package/lib/common/clients/yarn.js +57 -6
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/compatibility.js +14 -9
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/config.d.ts +52 -1
- package/lib/common/config.js +10 -30
- package/lib/common/config.js.map +1 -1
- package/lib/common/constants.d.ts +10 -2
- package/lib/common/constants.js +22 -4
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.d.ts +2 -1
- package/lib/common/declaration.js +113 -56
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emoji.d.ts +8 -0
- package/lib/common/emoji.js +10 -1
- package/lib/common/emoji.js.map +1 -1
- package/lib/common/emulator.d.ts +2 -2
- package/lib/common/emulator.js +45 -32
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/enums.d.ts +0 -4
- package/lib/common/enums.js +1 -6
- package/lib/common/enums.js.map +1 -1
- package/lib/common/envs.js +16 -5
- package/lib/common/envs.js.map +1 -1
- package/lib/common/hash.d.ts +1 -0
- package/lib/common/hash.js +8 -3
- package/lib/common/hash.js.map +1 -1
- package/lib/common/http.d.ts +5 -2
- package/lib/common/http.js +65 -23
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.d.ts +2 -0
- package/lib/common/importmap.js +202 -0
- package/lib/common/importmap.js.map +1 -0
- package/lib/common/index.d.ts +10 -0
- package/lib/common/index.js +15 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/info.d.ts +5 -0
- package/lib/common/info.js +9 -2
- package/lib/common/info.js.map +1 -1
- package/lib/common/injectors.d.ts +36 -8
- package/lib/common/injectors.js +46 -19
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.d.ts +5 -3
- package/lib/common/inspect.js +15 -15
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.d.ts +9 -0
- package/lib/common/interactive.js +60 -1
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.d.ts +9 -3
- package/lib/common/io.js +219 -116
- package/lib/common/io.js.map +1 -1
- package/lib/common/language.d.ts +9 -6
- package/lib/common/language.js +68 -12
- package/lib/common/language.js.map +1 -1
- package/lib/common/log.d.ts +5 -3
- package/lib/common/log.js +34 -48
- package/lib/common/log.js.map +1 -1
- package/lib/common/npm.d.ts +17 -16
- package/lib/common/npm.js +262 -158
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +47 -26
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +43 -20
- package/lib/common/package.js +377 -213
- package/lib/common/package.js.map +1 -1
- package/lib/common/parallel.d.ts +1 -0
- package/lib/common/parallel.js +29 -0
- package/lib/common/parallel.js.map +1 -0
- package/lib/common/patcher.js +20 -20
- package/lib/common/patcher.js.map +1 -1
- package/lib/common/platform.d.ts +13 -0
- package/lib/common/platform.js +29 -0
- package/lib/common/platform.js.map +1 -0
- package/lib/common/port.d.ts +1 -0
- package/lib/common/port.js +14 -4
- package/lib/common/port.js.map +1 -1
- package/lib/common/rules.js +4 -4
- package/lib/common/rules.js.map +1 -1
- package/lib/common/scaffold.d.ts +18 -4
- package/lib/common/scaffold.js +59 -36
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/scripts.js +8 -8
- package/lib/common/scripts.js.map +1 -1
- package/lib/common/shell.d.ts +2 -0
- package/lib/common/shell.js +33 -0
- package/lib/common/shell.js.map +1 -0
- package/lib/common/spec.d.ts +29 -0
- package/lib/common/spec.js +69 -0
- package/lib/common/spec.js.map +1 -0
- package/lib/common/template.d.ts +1 -2
- package/lib/common/template.js +23 -22
- package/lib/common/template.js.map +1 -1
- package/lib/common/url.d.ts +1 -0
- package/lib/common/url.js +17 -0
- package/lib/common/url.js.map +1 -0
- package/lib/common/utils.d.ts +1 -0
- package/lib/common/utils.js +8 -0
- package/lib/common/utils.js.map +1 -0
- package/lib/common/version.d.ts +2 -0
- package/lib/common/version.js +130 -0
- package/lib/common/version.js.map +1 -0
- package/lib/common/watcher.d.ts +13 -0
- package/lib/common/watcher.js +78 -0
- package/lib/common/watcher.js.map +1 -0
- package/lib/external/index.js +59413 -57862
- package/lib/helpers.d.ts +6 -6
- package/lib/helpers.js +10 -25
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/inject.js +2 -2
- package/lib/inject.js.map +1 -1
- package/lib/injectors/pilet-injector.d.ts +75 -0
- package/lib/injectors/pilet-injector.js +246 -0
- package/lib/injectors/pilet-injector.js.map +1 -0
- package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +10 -2
- package/lib/injectors/piral-injector.js +97 -0
- package/lib/injectors/piral-injector.js.map +1 -0
- package/lib/messages.d.ts +567 -47
- package/lib/messages.js +638 -51
- package/lib/messages.js.map +1 -1
- package/lib/pb-cli.js +1 -1
- package/lib/pb-cli.js.map +1 -1
- package/lib/pilet-cli.js +1 -1
- package/lib/pilet-cli.js.map +1 -1
- package/lib/piral-cli.js +1 -1
- package/lib/piral-cli.js.map +1 -1
- package/lib/platforms/node.d.ts +8 -0
- package/lib/platforms/node.js +30 -0
- package/lib/platforms/node.js.map +1 -0
- package/lib/platforms/web.d.ts +8 -0
- package/lib/platforms/web.js +120 -0
- package/lib/platforms/web.js.map +1 -0
- package/lib/plugin.js +36 -11
- package/lib/plugin.js.map +1 -1
- package/lib/questionnaire.d.ts +1 -1
- package/lib/questionnaire.js +9 -4
- package/lib/questionnaire.js.map +1 -1
- package/lib/release.d.ts +1 -1
- package/lib/release.js +38 -6
- package/lib/release.js.map +1 -1
- package/lib/resolvers.js +13 -13
- package/lib/resolvers.js.map +1 -1
- package/lib/rules/index.js +8 -8
- package/lib/rules/index.js.map +1 -1
- package/lib/rules/pilet-has-externals-as-peers.d.ts +1 -1
- package/lib/rules/pilet-has-externals-as-peers.js +9 -7
- package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
- package/lib/rules/pilet-has-no-self-reference.d.ts +1 -1
- package/lib/rules/pilet-has-no-self-reference.js +2 -2
- package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
- package/lib/rules/pilet-has-no-third-party-dependency.d.ts +1 -1
- package/lib/rules/pilet-stays-small.d.ts +1 -1
- package/lib/rules/pilet-stays-small.js +4 -4
- package/lib/rules/pilet-stays-small.js.map +1 -1
- package/lib/rules/pilet-uses-latest-piral.d.ts +1 -1
- package/lib/rules/pilet-uses-latest-piral.js +18 -9
- package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
- package/lib/rules/piral-depends-on-piral.d.ts +1 -1
- package/lib/rules/piral-entry-ends-with-html.d.ts +1 -1
- package/lib/rules/piral-entry-ends-with-html.js +1 -1
- package/lib/rules/piral-entry-ends-with-html.js.map +1 -1
- package/lib/rules/piral-has-valid-devDependencies.d.ts +1 -1
- package/lib/rules/piral-has-valid-externals.d.ts +1 -1
- package/lib/rules/piral-has-valid-externals.js +10 -24
- package/lib/rules/piral-has-valid-externals.js.map +1 -1
- package/lib/rules/piral-has-valid-files.d.ts +1 -1
- package/lib/rules/piral-has-valid-files.js +5 -5
- package/lib/rules/piral-has-valid-files.js.map +1 -1
- package/lib/rules/piral-has-valid-scripts.d.ts +1 -1
- package/lib/runner.js +1 -1
- package/lib/runner.js.map +1 -1
- package/lib/select.js +6 -6
- package/lib/select.js.map +1 -1
- package/lib/types/common.d.ts +88 -8
- package/lib/types/common.js.map +1 -1
- package/lib/types/index.js +5 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/internal.d.ts +12 -13
- package/lib/types/public.d.ts +89 -23
- package/package.json +19 -16
- package/src/apps/add-piral-instance-pilet.ts +98 -0
- package/src/apps/build-pilet.ts +286 -38
- package/src/apps/build-piral.test.ts +20 -7
- package/src/apps/build-piral.ts +90 -39
- package/src/apps/debug-pilet.ts +229 -123
- package/src/apps/debug-piral.ts +121 -68
- package/src/apps/declaration-piral.ts +4 -2
- package/src/apps/index.ts +3 -0
- package/src/apps/new-pilet.test.ts +28 -11
- package/src/apps/new-pilet.ts +60 -48
- package/src/apps/new-piral.test.ts +25 -13
- package/src/apps/new-piral.ts +43 -19
- package/src/apps/pack-pilet.test.ts +2 -2
- package/src/apps/pack-pilet.ts +12 -10
- package/src/apps/publish-pilet.ts +148 -43
- package/src/apps/publish-piral.ts +38 -11
- package/src/apps/remove-piral-instance-pilet.ts +92 -0
- package/src/apps/run-emulator-piral.ts +154 -0
- package/src/apps/upgrade-pilet.ts +37 -31
- package/src/apps/upgrade-piral.ts +9 -7
- package/src/apps/validate-pilet.ts +30 -22
- package/src/apps/validate-piral.ts +5 -2
- package/src/build/bundler-calls.ts +133 -0
- package/src/build/run-build-pilet.ts +91 -0
- package/src/build/run-build-piral.ts +93 -0
- package/src/build/run-debug-mono-piral.ts +86 -0
- package/src/build/run-debug-pilet.ts +116 -0
- package/src/build/run-debug-piral.ts +105 -0
- package/src/bundler.test.ts +86 -68
- package/src/bundler.ts +74 -19
- package/src/cli.ts +6 -2
- package/src/commands.ts +273 -44
- package/src/common/archive.test.ts +51 -45
- package/src/common/archive.ts +28 -1
- package/src/common/browser.test.ts +20 -10
- package/src/common/browser.ts +13 -6
- package/src/common/clients/index.ts +41 -0
- package/src/common/clients/lerna.ts +85 -1
- package/src/common/clients/npm.ts +56 -14
- package/src/common/clients/pnp.ts +84 -0
- package/src/common/clients/pnpm.ts +45 -1
- package/src/common/clients/rush.ts +118 -0
- package/src/common/clients/yarn.ts +49 -3
- package/src/common/compatibility.ts +8 -1
- package/src/common/config.ts +57 -22
- package/src/common/constants.ts +21 -3
- package/src/common/declaration.ts +124 -50
- package/src/common/emoji.ts +9 -0
- package/src/common/emulator.ts +43 -23
- package/src/common/enums.ts +0 -5
- package/src/common/envs.ts +15 -3
- package/src/common/hash.ts +5 -0
- package/src/common/http.test.ts +76 -64
- package/src/common/http.ts +88 -24
- package/src/common/importmap.ts +242 -0
- package/src/common/index.ts +10 -0
- package/src/common/info.ts +9 -1
- package/src/common/injectors.ts +49 -22
- package/src/common/inspect.ts +13 -14
- package/src/common/interactive.test.ts +6 -0
- package/src/common/interactive.ts +69 -1
- package/src/common/io.ts +199 -82
- package/src/common/language.ts +87 -10
- package/src/common/log.ts +32 -46
- package/src/common/npm.test.ts +187 -166
- package/src/common/npm.ts +263 -119
- package/src/common/pack.test.ts +11 -13
- package/src/common/pack.ts +60 -21
- package/src/common/package.test.ts +59 -49
- package/src/common/package.ts +406 -167
- package/src/common/parallel.test.ts +28 -0
- package/src/common/parallel.ts +21 -0
- package/src/common/platform.ts +31 -0
- package/src/common/port.test.ts +4 -1
- package/src/common/port.ts +10 -0
- package/src/common/rules.test.ts +3 -3
- package/src/common/scaffold.ts +69 -41
- package/src/common/scripts.ts +5 -4
- package/src/common/shell.ts +34 -0
- package/src/common/spec.ts +69 -0
- package/src/common/template.ts +20 -18
- package/src/common/url.test.ts +28 -0
- package/src/common/url.ts +15 -0
- package/src/common/utils.ts +3 -0
- package/src/common/version.test.ts +233 -0
- package/src/common/version.ts +142 -0
- package/src/common/watcher.ts +89 -0
- package/src/external/index.test.ts +2 -2
- package/src/external/index.ts +7 -3
- package/src/external/resolve.ts +29 -0
- package/src/helpers.test.ts +2 -22
- package/src/helpers.ts +21 -30
- package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +13 -4
- package/src/injectors/pilet-injector.ts +346 -0
- package/src/injectors/{piral.test.ts → piral-injector.test.ts} +14 -5
- package/src/injectors/piral-injector.ts +130 -0
- package/src/messages.ts +649 -63
- package/src/platforms/node.ts +16 -0
- package/src/platforms/web.ts +148 -0
- package/src/plugin.ts +34 -5
- package/src/questionnaire.ts +17 -3
- package/src/release.ts +47 -5
- package/src/rules/index.ts +1 -1
- package/src/rules/pilet-has-externals-as-peers.test.ts +3 -2
- package/src/rules/pilet-has-externals-as-peers.ts +9 -7
- package/src/rules/pilet-has-no-self-reference.ts +1 -1
- package/src/rules/pilet-stays-small.ts +1 -1
- package/src/rules/pilet-uses-latest-piral.ts +22 -12
- package/src/rules/piral-has-valid-externals.ts +10 -29
- package/src/types/common.ts +99 -9
- package/src/types/internal.ts +14 -14
- package/src/types/public.ts +93 -27
- package/lib/external/child.js +0 -144
- package/lib/external/classes.trie +0 -0
- package/lib/external/xdg-open +0 -1066
- package/lib/injectors/pilet.d.ts +0 -47
- package/lib/injectors/pilet.js +0 -187
- package/lib/injectors/pilet.js.map +0 -1
- package/lib/injectors/piral.js +0 -62
- package/lib/injectors/piral.js.map +0 -1
- package/src/injectors/pilet.ts +0 -219
- package/src/injectors/piral.ts +0 -76
- package/templates/piral-index.js.ejs +0 -16
package/lib/helpers.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { ForceOverwrite
|
|
2
|
-
import { Framework, NpmClientType, PiletSchemaVersion, PiletPublishSource, PiralBuildType } from './types';
|
|
1
|
+
import { ForceOverwrite } from './common/enums';
|
|
2
|
+
import type { Framework, NpmClientType, PiletSchemaVersion, PiletPublishSource, PiralBuildType, PiletBuildType, PiletPublishScheme, SourceLanguage } from './types';
|
|
3
3
|
export declare const schemaKeys: Array<PiletSchemaVersion>;
|
|
4
|
+
export declare const publishModeKeys: Array<PiletPublishScheme>;
|
|
4
5
|
export declare const fromKeys: Array<PiletPublishSource>;
|
|
5
|
-
export declare const
|
|
6
|
+
export declare const piralBuildTypeKeys: Array<PiralBuildType>;
|
|
7
|
+
export declare const piletBuildTypeKeys: Array<PiletBuildType>;
|
|
6
8
|
export declare const clientTypeKeys: Array<NpmClientType>;
|
|
9
|
+
export declare const sourceLanguageKeys: Array<SourceLanguage>;
|
|
7
10
|
export declare const bundlerKeys: Array<string>;
|
|
8
11
|
export declare const availableBundlers: Array<string>;
|
|
9
12
|
export declare const availableReleaseProviders: Array<string>;
|
|
@@ -11,6 +14,3 @@ export declare const frameworkKeys: Array<Framework>;
|
|
|
11
14
|
export declare const forceOverwriteKeys: string[];
|
|
12
15
|
export declare function valueOfForceOverwrite(key: string): ForceOverwrite;
|
|
13
16
|
export declare function keyOfForceOverwrite(value: ForceOverwrite): string;
|
|
14
|
-
export declare const piletLanguageKeys: string[];
|
|
15
|
-
export declare function valueOfPiletLanguage(key: string): SourceLanguage;
|
|
16
|
-
export declare function keyOfPiletLanguage(value: SourceLanguage): string;
|
package/lib/helpers.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.keyOfForceOverwrite = exports.valueOfForceOverwrite = exports.forceOverwriteKeys = exports.frameworkKeys = exports.availableReleaseProviders = exports.availableBundlers = exports.bundlerKeys = exports.sourceLanguageKeys = exports.clientTypeKeys = exports.piletBuildTypeKeys = exports.piralBuildTypeKeys = exports.fromKeys = exports.publishModeKeys = exports.schemaKeys = void 0;
|
|
4
4
|
const enums_1 = require("./common/enums");
|
|
5
|
-
|
|
5
|
+
const constants_1 = require("./common/constants");
|
|
6
|
+
exports.schemaKeys = ['v0', 'v1', 'v2', 'none'];
|
|
7
|
+
exports.publishModeKeys = ['none', 'basic', 'bearer', 'digest'];
|
|
6
8
|
exports.fromKeys = ['local', 'remote', 'npm'];
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
9
|
+
exports.piralBuildTypeKeys = ['all', 'release', 'emulator', 'emulator-sources'];
|
|
10
|
+
exports.piletBuildTypeKeys = ['default', 'standalone', 'manifest'];
|
|
11
|
+
exports.clientTypeKeys = ['npm', 'pnpm', 'pnp', 'yarn', 'lerna', 'rush'];
|
|
12
|
+
exports.sourceLanguageKeys = ['ts', 'js'];
|
|
13
|
+
exports.bundlerKeys = ['none', ...constants_1.bundlerNames];
|
|
10
14
|
exports.availableBundlers = [];
|
|
11
15
|
exports.availableReleaseProviders = [];
|
|
12
|
-
exports.frameworkKeys = [
|
|
16
|
+
exports.frameworkKeys = [...constants_1.frameworkLibs];
|
|
13
17
|
exports.forceOverwriteKeys = Object.keys(enums_1.ForceOverwrite).filter((m) => typeof enums_1.ForceOverwrite[m] === 'number');
|
|
14
18
|
function valueOfForceOverwrite(key) {
|
|
15
19
|
for (const forceOverwriteKey of exports.forceOverwriteKeys) {
|
|
@@ -29,23 +33,4 @@ function keyOfForceOverwrite(value) {
|
|
|
29
33
|
return exports.forceOverwriteKeys[0];
|
|
30
34
|
}
|
|
31
35
|
exports.keyOfForceOverwrite = keyOfForceOverwrite;
|
|
32
|
-
exports.piletLanguageKeys = Object.keys(enums_1.SourceLanguage).filter((m) => typeof enums_1.SourceLanguage[m] === 'number');
|
|
33
|
-
function valueOfPiletLanguage(key) {
|
|
34
|
-
for (const piletLanguageKey of exports.piletLanguageKeys) {
|
|
35
|
-
if (piletLanguageKey === key) {
|
|
36
|
-
return enums_1.SourceLanguage[piletLanguageKey];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return enums_1.SourceLanguage.ts;
|
|
40
|
-
}
|
|
41
|
-
exports.valueOfPiletLanguage = valueOfPiletLanguage;
|
|
42
|
-
function keyOfPiletLanguage(value) {
|
|
43
|
-
for (const piletLanguageKey of exports.piletLanguageKeys) {
|
|
44
|
-
if (enums_1.SourceLanguage[piletLanguageKey] === value) {
|
|
45
|
-
return piletLanguageKey;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return exports.piletLanguageKeys[0];
|
|
49
|
-
}
|
|
50
|
-
exports.keyOfPiletLanguage = keyOfPiletLanguage;
|
|
51
36
|
//# sourceMappingURL=helpers.js.map
|
package/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,0CAAgD;AAChD,kDAAiE;AAYpD,QAAA,UAAU,GAA8B,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACnE,QAAA,eAAe,GAA8B,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACnF,QAAA,QAAQ,GAA8B,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AACjE,QAAA,kBAAkB,GAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC;AAC/F,QAAA,kBAAkB,GAA0B,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AAClF,QAAA,cAAc,GAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AACvF,QAAA,kBAAkB,GAA0B,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACzD,QAAA,WAAW,GAAkB,CAAC,MAAM,EAAE,GAAG,wBAAY,CAAC,CAAC;AACvD,QAAA,iBAAiB,GAAkB,EAAE,CAAC;AACtC,QAAA,yBAAyB,GAAkB,EAAE,CAAC;AAC9C,QAAA,aAAa,GAAqB,CAAC,GAAG,yBAAa,CAAC,CAAC;AACrD,QAAA,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,sBAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,sBAAc,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;AAEnH,SAAgB,qBAAqB,CAAC,GAAW;IAC/C,KAAK,MAAM,iBAAiB,IAAI,0BAAkB,EAAE;QAClD,IAAI,iBAAiB,KAAK,GAAG,EAAE;YAC7B,OAAO,sBAAc,CAAC,iBAAiB,CAAC,CAAC;SAC1C;KACF;IAED,OAAO,sBAAc,CAAC,EAAE,CAAC;AAC3B,CAAC;AARD,sDAQC;AAED,SAAgB,mBAAmB,CAAC,KAAqB;IACvD,KAAK,MAAM,iBAAiB,IAAI,0BAAkB,EAAE;QAClD,IAAI,sBAAc,CAAC,iBAAiB,CAAC,KAAK,KAAK,EAAE;YAC/C,OAAO,iBAAiB,CAAC;SAC1B;KACF;IAED,OAAO,0BAAkB,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC;AARD,kDAQC"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,kDAAgC;AAChC,iDAA+B;AAC/B,iDAA+B"}
|
package/lib/inject.js
CHANGED
|
@@ -10,11 +10,11 @@ function inject(pluginPath) {
|
|
|
10
10
|
plugin(api);
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
common_1.log('generalDebug_0003', `Skipping plugin from "${pluginPath}". Did not export a function.`);
|
|
13
|
+
(0, common_1.log)('generalDebug_0003', `Skipping plugin from "${pluginPath}". Did not export a function.`);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
catch (ex) {
|
|
17
|
-
common_1.log('pluginCouldNotBeLoaded_0205', pluginPath, ex);
|
|
17
|
+
(0, common_1.log)('pluginCouldNotBeLoaded_0205', pluginPath, ex);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.inject = inject;
|
package/lib/inject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,qCAA+B;AAG/B,SAAgB,MAAM,CAAC,UAAkB;IACvC,IAAI;QACF,MAAM,MAAM,GAAc,OAAO,CAAC,UAAU,CAAC,CAAC;QAE9C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;YAChC,MAAM,CAAC,GAAG,CAAC,CAAC;SACb;aAAM;YACL,YAAG,
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,qCAA+B;AAG/B,SAAgB,MAAM,CAAC,UAAkB;IACvC,IAAI;QACF,MAAM,MAAM,GAAc,OAAO,CAAC,UAAU,CAAC,CAAC;QAE9C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;YAChC,MAAM,CAAC,GAAG,CAAC,CAAC;SACb;aAAM;YACL,IAAA,YAAG,EAAC,mBAAmB,EAAE,yBAAyB,UAAU,+BAA+B,CAAC,CAAC;SAC9F;KACF;IAAC,OAAO,EAAE,EAAE;QACX,IAAA,YAAG,EAAC,6BAA6B,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;KACpD;AACH,CAAC;AAZD,wBAYC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
|
|
5
|
+
import { Bundler } from '../types';
|
|
6
|
+
interface Pilet {
|
|
7
|
+
bundler: Bundler;
|
|
8
|
+
root: string;
|
|
9
|
+
getMeta(basePath: string): PiletMetadata;
|
|
10
|
+
}
|
|
11
|
+
export interface PiletInjectorConfig extends KrasInjectorConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The pilets to serve.
|
|
14
|
+
*/
|
|
15
|
+
pilets: Array<Pilet>;
|
|
16
|
+
/**
|
|
17
|
+
* The base URL for the app shell / portal to be used.
|
|
18
|
+
*/
|
|
19
|
+
publicUrl: string;
|
|
20
|
+
/**
|
|
21
|
+
* The base URL for the pilet assets to be used.
|
|
22
|
+
*/
|
|
23
|
+
assetUrl?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Defines if properties from the feed (if given) meta response should be taken over to local pilets.
|
|
26
|
+
*/
|
|
27
|
+
mergeConfig?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The additional metadata file to consider for the pilets.
|
|
30
|
+
*/
|
|
31
|
+
meta: string;
|
|
32
|
+
/**
|
|
33
|
+
* The API path - usually somethin like `/$pilet-api`.
|
|
34
|
+
*/
|
|
35
|
+
api: string;
|
|
36
|
+
/**
|
|
37
|
+
* The directory of the app (usually Piral instance emulator) to serve.
|
|
38
|
+
*/
|
|
39
|
+
app?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The remote feed to merge into.
|
|
42
|
+
*/
|
|
43
|
+
feed?: string;
|
|
44
|
+
/**
|
|
45
|
+
* The additional headers to include.
|
|
46
|
+
*/
|
|
47
|
+
headers?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
interface PiletMetadata {
|
|
50
|
+
name?: string;
|
|
51
|
+
config?: Record<string, any>;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
export default class PiletInjector implements KrasInjector {
|
|
55
|
+
config: PiletInjectorConfig;
|
|
56
|
+
private serverConfig;
|
|
57
|
+
private indexPath;
|
|
58
|
+
constructor(config: PiletInjectorConfig, serverConfig: KrasConfiguration, core: EventEmitter);
|
|
59
|
+
get active(): boolean;
|
|
60
|
+
set active(value: boolean);
|
|
61
|
+
get name(): string;
|
|
62
|
+
getOptions(): {};
|
|
63
|
+
setOptions(): void;
|
|
64
|
+
getPiletApi(baseUrl: string): string;
|
|
65
|
+
getPiletMeta(baseUrl: string, pilet: Pilet): string;
|
|
66
|
+
getIndexMeta(baseUrl: string): Promise<string>;
|
|
67
|
+
loadRemoteFeed(feed?: string | Array<string>): Promise<Array<Array<PiletMetadata>>>;
|
|
68
|
+
mergePilets(localPilets: Array<PiletMetadata>, remoteFeeds: Array<Array<PiletMetadata>>): PiletMetadata[];
|
|
69
|
+
sendContent(content: Buffer | string, type: string, url: string): KrasResponse;
|
|
70
|
+
sendFile(target: string, url: string): KrasResponse;
|
|
71
|
+
sendResponse(path: string, url: string, baseUrl: string): Promise<KrasResult>;
|
|
72
|
+
sendIndexFile(target: string, url: string, baseUrl: string): KrasResponse;
|
|
73
|
+
handle(req: KrasRequest): KrasResponse;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const url_1 = require("url");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const log_1 = require("../common/log");
|
|
16
|
+
const spec_1 = require("../common/spec");
|
|
17
|
+
const config_1 = require("../common/config");
|
|
18
|
+
const external_1 = require("../external");
|
|
19
|
+
function getMetaOverride(root, metaFile) {
|
|
20
|
+
if (metaFile) {
|
|
21
|
+
const metaPath = (0, path_1.join)(root, metaFile);
|
|
22
|
+
if ((0, fs_1.existsSync)(metaPath)) {
|
|
23
|
+
return external_1.jju.parse((0, fs_1.readFileSync)(metaPath, 'utf8'));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function fillPiletMeta(pilet, metaFile, subPath) {
|
|
29
|
+
const { root, bundler } = pilet;
|
|
30
|
+
const packagePath = (0, path_1.join)(root, 'package.json');
|
|
31
|
+
const def = external_1.jju.parse((0, fs_1.readFileSync)(packagePath, 'utf8'));
|
|
32
|
+
const file = bundler.bundle.name.replace(/^[\/\\]/, '');
|
|
33
|
+
const target = (0, path_1.join)(bundler.bundle.dir, file);
|
|
34
|
+
const metaOverride = getMetaOverride(root, metaFile);
|
|
35
|
+
pilet.getMeta = (parentPath) => {
|
|
36
|
+
const basePath = `${parentPath}${subPath}`;
|
|
37
|
+
const url = new url_1.URL(file, basePath);
|
|
38
|
+
return Object.assign(Object.assign(Object.assign({ custom: def.custom, config: def.piletConfig }, metaOverride), { name: def.name, version: def.version, link: `${url.href}?updated=${Date.now()}` }), (0, spec_1.getPiletSpecMeta)(target, basePath));
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function loadFeed(feed) {
|
|
42
|
+
var _a;
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
const response = yield external_1.axios.default.get(feed);
|
|
46
|
+
if (Array.isArray(response.data)) {
|
|
47
|
+
return response.data;
|
|
48
|
+
}
|
|
49
|
+
else if (Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.items)) {
|
|
50
|
+
return response.data.items;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return [response.data];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
(0, log_1.log)('generalWarning_0001', `Couldn't load feed at ${feed}.`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
class PiletInjector {
|
|
62
|
+
constructor(config, serverConfig, core) {
|
|
63
|
+
this.config = config;
|
|
64
|
+
this.serverConfig = serverConfig;
|
|
65
|
+
if (this.config.active) {
|
|
66
|
+
const { pilets, api, publicUrl, assetUrl } = config;
|
|
67
|
+
this.indexPath = `${publicUrl}index.html`;
|
|
68
|
+
const cbs = {};
|
|
69
|
+
core.on('user-connected', (e) => {
|
|
70
|
+
const baseUrl = assetUrl || e.req.headers.origin;
|
|
71
|
+
if (e.target === '*' && e.url === api.substring(1)) {
|
|
72
|
+
cbs[e.id] = {
|
|
73
|
+
baseUrl,
|
|
74
|
+
notify: (msg) => e.ws.send(msg),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
core.on('user-disconnected', (e) => {
|
|
79
|
+
delete cbs[e.id];
|
|
80
|
+
});
|
|
81
|
+
pilets.forEach((p, i) => p.bundler.on(() => {
|
|
82
|
+
fillPiletMeta(p, config.meta, `/${i}/`);
|
|
83
|
+
for (const id of Object.keys(cbs)) {
|
|
84
|
+
const { baseUrl, notify } = cbs[id];
|
|
85
|
+
const meta = this.getPiletMeta(baseUrl, p);
|
|
86
|
+
notify(meta);
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
get active() {
|
|
92
|
+
return this.config.active;
|
|
93
|
+
}
|
|
94
|
+
set active(value) {
|
|
95
|
+
this.config.active = value;
|
|
96
|
+
}
|
|
97
|
+
get name() {
|
|
98
|
+
return 'pilet-injector';
|
|
99
|
+
}
|
|
100
|
+
getOptions() {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
setOptions() { }
|
|
104
|
+
getPiletApi(baseUrl) {
|
|
105
|
+
const { api } = this.config;
|
|
106
|
+
if (/^https?:/.test(api)) {
|
|
107
|
+
return api;
|
|
108
|
+
}
|
|
109
|
+
else if (baseUrl) {
|
|
110
|
+
return `${baseUrl}${api}`;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const { ssl, port } = this.serverConfig;
|
|
114
|
+
const { host } = config_1.config;
|
|
115
|
+
return `${ssl ? 'https' : 'http'}://${host}:${port}${api}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getPiletMeta(baseUrl, pilet) {
|
|
119
|
+
const basePath = this.getPiletApi(baseUrl);
|
|
120
|
+
return JSON.stringify(pilet.getMeta(basePath));
|
|
121
|
+
}
|
|
122
|
+
getIndexMeta(baseUrl) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const { pilets, feed } = this.config;
|
|
125
|
+
const basePath = this.getPiletApi(baseUrl);
|
|
126
|
+
const localPilets = pilets.map((pilet) => { var _a; return (_a = pilet.getMeta) === null || _a === void 0 ? void 0 : _a.call(pilet, basePath); }).filter(Boolean);
|
|
127
|
+
const mergedPilets = this.mergePilets(localPilets, yield this.loadRemoteFeed(feed));
|
|
128
|
+
return JSON.stringify(mergedPilets);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
loadRemoteFeed(feed) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (feed) {
|
|
134
|
+
const feeds = Array.isArray(feed) ? feed : [feed];
|
|
135
|
+
return yield Promise.all(feeds.map(loadFeed));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
mergePilets(localPilets, remoteFeeds) {
|
|
140
|
+
if (!remoteFeeds || !Array.isArray(remoteFeeds)) {
|
|
141
|
+
return localPilets;
|
|
142
|
+
}
|
|
143
|
+
const { mergeConfig = false } = this.config;
|
|
144
|
+
const names = localPilets.map((pilet) => pilet.name);
|
|
145
|
+
const merged = [...localPilets];
|
|
146
|
+
for (const remotePilets of remoteFeeds) {
|
|
147
|
+
if (!Array.isArray(remotePilets)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const newPilets = remotePilets.filter((pilet) => {
|
|
151
|
+
if (!pilet || typeof pilet !== 'object') {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const name = pilet.name;
|
|
155
|
+
const isNew = name !== undefined && !names.includes(name);
|
|
156
|
+
if (!isNew && mergeConfig) {
|
|
157
|
+
const existing = merged.find((m) => m.name === name);
|
|
158
|
+
if (existing.config === undefined) {
|
|
159
|
+
existing.config = pilet.config;
|
|
160
|
+
}
|
|
161
|
+
else if (pilet.config !== undefined) {
|
|
162
|
+
Object.assign(existing.config, pilet.config);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return isNew;
|
|
166
|
+
});
|
|
167
|
+
names.push(...newPilets.map((p) => p.name));
|
|
168
|
+
merged.push(...newPilets);
|
|
169
|
+
}
|
|
170
|
+
return merged;
|
|
171
|
+
}
|
|
172
|
+
sendContent(content, type, url) {
|
|
173
|
+
const { headers } = this.config;
|
|
174
|
+
return {
|
|
175
|
+
injector: { name: this.name },
|
|
176
|
+
headers: Object.assign(Object.assign({}, headers), { 'content-type': type, 'cache-control': 'no-cache, no-store, must-revalidate', pragma: 'no-cache', expires: '0' }),
|
|
177
|
+
status: { code: 200 },
|
|
178
|
+
url,
|
|
179
|
+
content,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
sendFile(target, url) {
|
|
183
|
+
var _a;
|
|
184
|
+
const content = (0, fs_1.readFileSync)(target);
|
|
185
|
+
const type = (_a = external_1.mime.getType(target)) !== null && _a !== void 0 ? _a : 'application/octet-stream';
|
|
186
|
+
return this.sendContent(content, type, url);
|
|
187
|
+
}
|
|
188
|
+
sendResponse(path, url, baseUrl) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
const { pilets } = this.config;
|
|
191
|
+
const [index, ...rest] = path.split('/');
|
|
192
|
+
const pilet = pilets[+index];
|
|
193
|
+
const bundler = pilet === null || pilet === void 0 ? void 0 : pilet.bundler;
|
|
194
|
+
if (!path) {
|
|
195
|
+
yield (bundler === null || bundler === void 0 ? void 0 : bundler.ready());
|
|
196
|
+
const content = yield this.getIndexMeta(baseUrl);
|
|
197
|
+
return this.sendContent(content, 'application/json', url);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return bundler === null || bundler === void 0 ? void 0 : bundler.ready().then(() => {
|
|
201
|
+
const target = (0, path_1.join)(bundler.bundle.dir, rest.join('/'));
|
|
202
|
+
if ((0, fs_1.existsSync)(target) && (0, fs_1.statSync)(target).isFile()) {
|
|
203
|
+
return this.sendFile(target, url);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
sendIndexFile(target, url, baseUrl) {
|
|
210
|
+
const indexHtml = (0, fs_1.readFileSync)(target, 'utf8');
|
|
211
|
+
// mechanism to inject server side debug piletApi config into piral emulator
|
|
212
|
+
const windowInjectionScript = `window['dbg:pilet-api'] = '${this.getPiletApi(baseUrl)}';`;
|
|
213
|
+
const findStr = `<script`;
|
|
214
|
+
const replaceStr = `<script>/* Pilet Debugging Emulator Config Injection */${windowInjectionScript}</script><script`;
|
|
215
|
+
const content = indexHtml.replace(`${findStr}`, `${replaceStr}`);
|
|
216
|
+
return this.sendContent(content, external_1.mime.getType(target), url);
|
|
217
|
+
}
|
|
218
|
+
handle(req) {
|
|
219
|
+
const { app, api, publicUrl, assetUrl } = this.config;
|
|
220
|
+
const baseUrl = assetUrl || (req.headers.host ? `${req.encrypted ? 'https' : 'http'}://${req.headers.host}` : undefined);
|
|
221
|
+
if (!req.target) {
|
|
222
|
+
if (req.url.startsWith(publicUrl)) {
|
|
223
|
+
const path = req.url.substring(publicUrl.length).split('?')[0];
|
|
224
|
+
if (app) {
|
|
225
|
+
const target = (0, path_1.join)(app, path);
|
|
226
|
+
if ((0, fs_1.existsSync)(target) && (0, fs_1.statSync)(target).isFile()) {
|
|
227
|
+
if (req.url === this.indexPath) {
|
|
228
|
+
return this.sendIndexFile(target, req.url, baseUrl);
|
|
229
|
+
}
|
|
230
|
+
return this.sendFile(target, req.url);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (req.url !== this.indexPath) {
|
|
234
|
+
return this.handle(Object.assign(Object.assign({}, req), { url: this.indexPath }));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
else if (req.target === api) {
|
|
240
|
+
const path = req.url.substring(1).split('?')[0];
|
|
241
|
+
return this.sendResponse(path, req.url, baseUrl);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.default = PiletInjector;
|
|
246
|
+
//# sourceMappingURL=pilet-injector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pilet-injector.js","sourceRoot":"","sources":["../../src/injectors/pilet-injector.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA0B;AAC1B,+BAA4B;AAE5B,2BAAwD;AAExD,uCAAoC;AACpC,yCAAkD;AAClD,6CAA0D;AAC1D,0CAA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B,IAAI,IAAA,eAAU,EAAC,MAAM,CAAC,IAAI,IAAA,aAAQ,EAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;wBACnD,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,EAAE;4BAC9B,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;yBACrD;wBAED,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;qBACvC;iBACF;gBAED,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,EAAE;oBAC9B,OAAO,IAAI,CAAC,MAAM,iCACb,GAAG,KACN,GAAG,EAAE,IAAI,CAAC,SAAS,IACnB,CAAC;iBACJ;aACF;YAED,OAAO,SAAS,CAAC;SAClB;aAAM,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;YAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SAClD;IACH,CAAC;CACF;AArOD,gCAqOC"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration } from 'kras';
|
|
2
5
|
import { Bundler } from '../types';
|
|
3
6
|
export interface PiralInjectorConfig extends KrasInjectorConfig {
|
|
4
7
|
bundler: Bundler;
|
|
8
|
+
publicUrl: string;
|
|
9
|
+
feed?: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
5
11
|
}
|
|
6
12
|
export default class PiralInjector implements KrasInjector {
|
|
7
13
|
config: PiralInjectorConfig;
|
|
8
|
-
constructor(options: PiralInjectorConfig);
|
|
14
|
+
constructor(options: PiralInjectorConfig, _config: KrasConfiguration, core: EventEmitter);
|
|
9
15
|
get active(): boolean;
|
|
10
16
|
set active(value: boolean);
|
|
11
17
|
get name(): string;
|
|
12
18
|
getOptions(): {};
|
|
13
19
|
setOptions(): void;
|
|
20
|
+
sendContent(content: Buffer | string, type: string, url: string): KrasResponse;
|
|
21
|
+
sendIndexFile(target: string, url: string): KrasResponse;
|
|
14
22
|
sendResponse(path: string, target: string, dir: string, url: string, recursionDepth?: number): KrasResponse;
|
|
15
23
|
handle(req: KrasRequest): KrasResponse;
|
|
16
24
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const external_1 = require("../external");
|
|
6
|
+
/**
|
|
7
|
+
* The maximum amount of retries when sending a response
|
|
8
|
+
*/
|
|
9
|
+
const maxRetrySendResponse = 4;
|
|
10
|
+
class PiralInjector {
|
|
11
|
+
constructor(options, _config, core) {
|
|
12
|
+
this.config = options;
|
|
13
|
+
if (this.config.active) {
|
|
14
|
+
const api = '/$events';
|
|
15
|
+
const cbs = {};
|
|
16
|
+
core.on('user-connected', (e) => {
|
|
17
|
+
if (e.target === '*' && e.url === api.substring(1)) {
|
|
18
|
+
cbs[e.id] = (msg) => e.ws.send(msg);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
core.on('user-disconnected', (e) => {
|
|
22
|
+
delete cbs[e.id];
|
|
23
|
+
});
|
|
24
|
+
this.config.bundler.on((args) => {
|
|
25
|
+
for (const id of Object.keys(cbs)) {
|
|
26
|
+
cbs[id](JSON.stringify(args));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
get active() {
|
|
32
|
+
return this.config.active;
|
|
33
|
+
}
|
|
34
|
+
set active(value) {
|
|
35
|
+
this.config.active = value;
|
|
36
|
+
}
|
|
37
|
+
get name() {
|
|
38
|
+
return 'piral-injector';
|
|
39
|
+
}
|
|
40
|
+
getOptions() {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
setOptions() { }
|
|
44
|
+
sendContent(content, type, url) {
|
|
45
|
+
const { headers } = this.config;
|
|
46
|
+
return {
|
|
47
|
+
injector: { name: this.name },
|
|
48
|
+
headers: Object.assign(Object.assign({}, headers), { 'content-type': type, 'cache-control': 'no-cache, no-store, must-revalidate', pragma: 'no-cache', expires: '0' }),
|
|
49
|
+
status: { code: 200 },
|
|
50
|
+
url,
|
|
51
|
+
content,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
sendIndexFile(target, url) {
|
|
55
|
+
const indexHtml = (0, fs_1.readFileSync)(target, 'utf8');
|
|
56
|
+
const { feed } = this.config;
|
|
57
|
+
if (feed) {
|
|
58
|
+
// mechanism to inject server side debug piletApi config into piral emulator
|
|
59
|
+
const windowInjectionScript = `window['dbg:pilet-api'] = '${feed}';`;
|
|
60
|
+
const findStr = `<script`;
|
|
61
|
+
const replaceStr = `<script>/* Pilet Debugging Emulator Config Injection */${windowInjectionScript}</script><script`;
|
|
62
|
+
const content = indexHtml.replace(`${findStr}`, `${replaceStr}`);
|
|
63
|
+
return this.sendContent(content, external_1.mime.getType(target), url);
|
|
64
|
+
}
|
|
65
|
+
return this.sendContent(indexHtml, external_1.mime.getType(target), url);
|
|
66
|
+
}
|
|
67
|
+
sendResponse(path, target, dir, url, recursionDepth = 0) {
|
|
68
|
+
var _a;
|
|
69
|
+
if (recursionDepth > maxRetrySendResponse) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const { bundler } = this.config;
|
|
73
|
+
const newTarget = (0, path_1.join)(bundler.bundle.dir, bundler.bundle.name);
|
|
74
|
+
if (!path || !(0, fs_1.existsSync)(target) || !(0, fs_1.statSync)(target).isFile()) {
|
|
75
|
+
return this.sendResponse(bundler.bundle.name, newTarget, dir, url, recursionDepth + 1);
|
|
76
|
+
}
|
|
77
|
+
else if (target === newTarget) {
|
|
78
|
+
return this.sendIndexFile(target, url);
|
|
79
|
+
}
|
|
80
|
+
const type = (_a = external_1.mime.getType(target)) !== null && _a !== void 0 ? _a : 'application/octet-stream';
|
|
81
|
+
return this.sendContent((0, fs_1.readFileSync)(target), type, url);
|
|
82
|
+
}
|
|
83
|
+
handle(req) {
|
|
84
|
+
if (!req.target) {
|
|
85
|
+
const { bundler, publicUrl } = this.config;
|
|
86
|
+
if (req.url.startsWith(publicUrl) || `${req.url}/` === publicUrl) {
|
|
87
|
+
const pathLength = publicUrl.length || 1;
|
|
88
|
+
const path = req.url.substring(pathLength);
|
|
89
|
+
const dir = bundler.bundle.dir;
|
|
90
|
+
const target = (0, path_1.join)(dir, path.split('?')[0]);
|
|
91
|
+
return bundler.ready().then(() => this.sendResponse(path, target, dir, req.url));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.default = PiralInjector;
|
|
97
|
+
//# sourceMappingURL=piral-injector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"piral-injector.js","sourceRoot":"","sources":["../../src/injectors/piral-injector.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAE5B,2BAAwD;AAExD,0CAAmC;AAGnC;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAS/B,MAAqB,aAAa;IAGhC,YAAY,OAA4B,EAAE,OAA0B,EAAE,IAAkB;QACtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QAEtB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACtB,MAAM,GAAG,GAAG,UAAU,CAAC;YACvB,MAAM,GAAG,GAAG,EAAE,CAAC;YAEf,IAAI,CAAC,E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