piral-cli 0.15.9-beta.5387 → 0.15.9-beta.5415

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.
@@ -25,6 +25,7 @@ export * from './package';
25
25
  export * from './parallel';
26
26
  export * from './patcher';
27
27
  export * from './patches';
28
+ export * from './platform';
28
29
  export * from './port';
29
30
  export * from './rules';
30
31
  export * from './scaffold';
@@ -611,12 +611,12 @@ export async function retrievePiletsInfo(entryFile: string) {
611
611
  };
612
612
  }
613
613
 
614
- export function validateSharedDependencies(externals: Array<SharedDependency | string>) {
614
+ export function validateSharedDependencies(externals: Array<SharedDependency>) {
615
615
  // See #591 - we should warn in case somebody shared piral packages
616
616
  for (const external of externals) {
617
- const name = typeof external === 'string' ? external : external.name;
617
+ const name = external.name;
618
618
 
619
- if (name.startsWith('piral-') && name.indexOf('/') === -1) {
619
+ if (external.type === 'local' && name.startsWith('piral-') && name.indexOf('/') === -1) {
620
620
  log('invalidSharedDependency_0029', name);
621
621
  }
622
622
  }
@@ -0,0 +1,31 @@
1
+ import { fail } from './log';
2
+ import { PlatformStartShellOptions, PlatformStartModuleOptions } from '../types';
3
+
4
+ export interface WebPlatformSettings {
5
+ platform: 'web';
6
+ }
7
+
8
+ export interface NodePlatformSettings {
9
+ platform: 'node';
10
+ }
11
+
12
+ export type PlatformSettings = WebPlatformSettings | NodePlatformSettings;
13
+
14
+ export interface PlatformTarget {
15
+ startShell(options: PlatformStartShellOptions): Promise<void>;
16
+ startModule(options: PlatformStartModuleOptions): Promise<void>;
17
+ }
18
+
19
+ export function configurePlatform(target: Partial<PlatformSettings> = {}): PlatformTarget {
20
+ const { platform = 'web', ...options } = target;
21
+
22
+ if (platform === 'web') {
23
+ const { setup } = require('../platforms/web');
24
+ return setup(options);
25
+ } else if (platform === 'node') {
26
+ const { setup } = require('../platforms/node');
27
+ return setup(options);
28
+ }
29
+
30
+ return fail('platformNotSupported_0190', platform);
31
+ }
package/src/messages.ts CHANGED
@@ -2555,6 +2555,7 @@ export function invalidSchemaVersion_0171(schemaVersion: string, schemas: Array<
2555
2555
  * - [Webpack](https://webpack.js.org)
2556
2556
  * - [Parcel](https://parceljs.org)
2557
2557
  * - [esbuild](https://esbuild.github.io)
2558
+ * - [rspack](https://www.rspack.dev/)
2558
2559
  * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2559
2560
  *
2560
2561
  * @example
@@ -2587,6 +2588,7 @@ export function bundlerMissing_0172(bundlerName: string, installed: Array<string
2587
2588
  * - [Webpack](https://webpack.js.org)
2588
2589
  * - [Parcel](https://parceljs.org)
2589
2590
  * - [esbuild](https://esbuild.github.io)
2591
+ * - [rspack](https://www.rspack.dev/)
2590
2592
  * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2591
2593
  *
2592
2594
  * @example
@@ -2619,6 +2621,7 @@ export function defaultBundlerMissing_0173(): QuickMessage {
2619
2621
  * - [Webpack](https://webpack.js.org)
2620
2622
  * - [Parcel](https://parceljs.org)
2621
2623
  * - [esbuild](https://esbuild.github.io)
2624
+ * - [rspack](https://www.rspack.dev/)
2622
2625
  * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2623
2626
  *
2624
2627
  * @example
@@ -2727,6 +2730,26 @@ export function piletJsonNotAvailable_0180(root: string): QuickMessage {
2727
2730
  return [LogLevels.warning, '0180', `No "pilet.json" was found for the pilet at "${root}".`];
2728
2731
  }
2729
2732
 
2733
+ /**
2734
+ * @kind Error
2735
+ *
2736
+ * @summary
2737
+ * Using the given platform is not supported.
2738
+ *
2739
+ * @abstract
2740
+ * The Piral instance can run on multiple platforms. The platform is specified via
2741
+ * the piral.json file.
2742
+ *
2743
+ * The standard platform is "web", which starts a web server using the server
2744
+ * proxy kras.
2745
+ *
2746
+ * @example
2747
+ * (tbd)
2748
+ */
2749
+ export function platformNotSupported_0190(platform: string): QuickMessage {
2750
+ return [LogLevels.error, '0190', `The given platform "${platform}" is not supported.`];
2751
+ }
2752
+
2730
2753
  /**
2731
2754
  * @kind Warning
2732
2755
  *
@@ -0,0 +1,16 @@
1
+ import { PlatformStartShellOptions, PlatformStartModuleOptions } from '../types';
2
+
3
+ async function startModule(options: PlatformStartModuleOptions) {
4
+ //TODO
5
+ }
6
+
7
+ async function startShell(options: PlatformStartShellOptions) {
8
+ //TODO
9
+ }
10
+
11
+ export function setup() {
12
+ return {
13
+ startModule,
14
+ startShell,
15
+ };
16
+ }
@@ -0,0 +1,142 @@
1
+ import { readKrasConfig, krasrc, buildKrasWithCli } from 'kras';
2
+ import { join, resolve } from 'path';
3
+ import { createInitialKrasConfig, notifyServerOnline } from '../common/injectors';
4
+ import { log } from '../common/log';
5
+ import { config } from '../common/config';
6
+ import { openBrowser } from '../common/browser';
7
+ import { checkExistingDirectory } from '../common/io';
8
+ import { getAvailablePort } from '../common/port';
9
+ import { PlatformStartShellOptions, PlatformStartModuleOptions } from '../types';
10
+
11
+ async function startModule(options: PlatformStartModuleOptions) {
12
+ const {
13
+ appDir,
14
+ appRoot,
15
+ fullBase,
16
+ open,
17
+ feed,
18
+ publicUrl,
19
+ customkrasrc,
20
+ originalPort,
21
+ hooks,
22
+ registerWatcher,
23
+ registerEnd,
24
+ pilets,
25
+ maxListeners,
26
+ } = options;
27
+
28
+ const sources = pilets.map((m) => m.mocks).filter(Boolean);
29
+ const api = `${publicUrl}${config.piletApi.replace(/^\/+/, '')}`;
30
+ const baseMocks = resolve(fullBase, 'mocks');
31
+ const krasBaseConfig = resolve(fullBase, krasrc);
32
+ const krasRootConfig = resolve(appRoot, krasrc);
33
+ const initial = createInitialKrasConfig(baseMocks, sources, { [api]: '' }, feed);
34
+ const configs = [krasBaseConfig, ...pilets.map((p) => resolve(p.root, krasrc)), krasRootConfig];
35
+ const required = {
36
+ injectors: {
37
+ piral: {
38
+ active: false,
39
+ },
40
+ pilet: {
41
+ active: true,
42
+ pilets,
43
+ app: appDir,
44
+ publicUrl,
45
+ handle: ['/', api],
46
+ api,
47
+ },
48
+ },
49
+ };
50
+
51
+ if (customkrasrc) {
52
+ configs.push(resolve(fullBase, customkrasrc));
53
+ }
54
+
55
+ configs.forEach(registerWatcher);
56
+
57
+ const port = await getAvailablePort(originalPort);
58
+ const krasConfig = readKrasConfig({ port, initial, required }, ...configs);
59
+
60
+ log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
61
+
62
+ const krasServer = buildKrasWithCli(krasConfig);
63
+ krasServer.setMaxListeners(maxListeners);
64
+ krasServer.removeAllListeners('open');
65
+ krasServer.on('open', notifyServerOnline(publicUrl, krasConfig.api));
66
+
67
+ await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
68
+ await krasServer.start();
69
+ openBrowser(open, port, publicUrl, !!krasConfig.ssl);
70
+ await hooks.afterOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
71
+
72
+ registerEnd(() => krasServer.stop());
73
+ }
74
+
75
+ async function startShell(options: PlatformStartShellOptions) {
76
+ const {
77
+ fullBase,
78
+ open,
79
+ root,
80
+ targetDir,
81
+ feed,
82
+ publicUrl,
83
+ bundler,
84
+ customkrasrc,
85
+ originalPort,
86
+ hooks,
87
+ registerWatcher,
88
+ registerEnd,
89
+ } = options;
90
+ const krasBaseConfig = resolve(fullBase, krasrc);
91
+ const krasRootConfig = resolve(root, krasrc);
92
+
93
+ const mocks = join(targetDir, 'mocks');
94
+ const baseMocks = resolve(fullBase, 'mocks');
95
+ const mocksExist = await checkExistingDirectory(mocks);
96
+ const sources = [mocksExist ? mocks : undefined].filter(Boolean);
97
+ const initial = createInitialKrasConfig(baseMocks, sources);
98
+ const configs = [krasBaseConfig, krasRootConfig];
99
+ const required = {
100
+ injectors: {
101
+ piral: {
102
+ active: true,
103
+ handle: ['/'],
104
+ feed,
105
+ publicUrl,
106
+ bundler,
107
+ },
108
+ pilet: {
109
+ active: false,
110
+ },
111
+ },
112
+ };
113
+
114
+ if (customkrasrc) {
115
+ configs.push(resolve(fullBase, customkrasrc));
116
+ }
117
+
118
+ configs.forEach(registerWatcher);
119
+
120
+ const port = await getAvailablePort(originalPort);
121
+ const krasConfig = readKrasConfig({ port, initial, required }, ...configs);
122
+ log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
123
+
124
+ const krasServer = buildKrasWithCli(krasConfig);
125
+ krasServer.setMaxListeners(16);
126
+ krasServer.removeAllListeners('open');
127
+ krasServer.on('open', notifyServerOnline(publicUrl, krasConfig.api));
128
+
129
+ await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, publicUrl });
130
+ await krasServer.start();
131
+ openBrowser(open, port, publicUrl, !!krasConfig.ssl);
132
+ await hooks.afterOnline?.({ krasServer, krasConfig, open, port, publicUrl });
133
+
134
+ registerEnd(() => krasServer.stop());
135
+ }
136
+
137
+ export function setup() {
138
+ return {
139
+ startModule,
140
+ startShell,
141
+ };
142
+ }
@@ -92,6 +92,38 @@ export interface Bundler {
92
92
  ready(): Promise<void>;
93
93
  }
94
94
 
95
+ export interface PlatformStartModuleOptions {
96
+ appRoot: string;
97
+ appDir: string;
98
+ open: boolean;
99
+ fullBase: string;
100
+ feed: string | Array<string>;
101
+ publicUrl: string;
102
+ customkrasrc: string;
103
+ originalPort: number;
104
+ hooks: Record<string, Function>;
105
+ registerWatcher(file: string): void;
106
+ registerEnd(cb: () => void): void;
107
+
108
+ maxListeners: number;
109
+ pilets: Array<any>;
110
+ }
111
+
112
+ export interface PlatformStartShellOptions {
113
+ open: boolean;
114
+ fullBase: string;
115
+ root: string;
116
+ feed: string | Array<string>;
117
+ targetDir: string;
118
+ publicUrl: string;
119
+ bundler: Bundler;
120
+ customkrasrc: string;
121
+ originalPort: number;
122
+ hooks: Record<string, Function>;
123
+ registerWatcher(file: string): void;
124
+ registerEnd(cb: () => void): void;
125
+ }
126
+
95
127
  export interface ReleaseProvider {
96
128
  (directory: string, files: Array<string>, args: Record<string, string>, interactive: boolean): Promise<void>;
97
129
  }