@equinor/roma-nx-plugin 1.0.0-BETA.0 → 1.1.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.
Files changed (114) hide show
  1. package/.eslintrc.json +37 -0
  2. package/CHANGELOG.md +42 -0
  3. package/executors.json +5 -0
  4. package/generators.json +5 -0
  5. package/jest.config.ts +13 -0
  6. package/manifest-schema.json +80 -0
  7. package/package.json +12 -11
  8. package/project.json +65 -0
  9. package/src/executors/build/build.ts +100 -0
  10. package/src/executors/build/executor.spec.ts +13 -0
  11. package/src/executors/build/executor.ts +10 -0
  12. package/src/executors/build/minify.ts +20 -0
  13. package/src/executors/component-test/executor.spec.ts +18 -0
  14. package/src/executors/component-test/executor.ts +57 -0
  15. package/src/executors/component-test/schema.d.ts +5 -0
  16. package/src/executors/component-test/schema.json +25 -0
  17. package/src/executors/create-vite-config.ts +133 -0
  18. package/src/executors/executor-context.ts +102 -0
  19. package/src/executors/publish/executor.ts +29 -0
  20. package/src/executors/publish/manifest-model.ts +33 -0
  21. package/src/executors/publish/publish-script.spec.ts +118 -0
  22. package/src/executors/publish/publish-script.ts +210 -0
  23. package/src/executors/serve/executor.ts +19 -0
  24. package/src/executors/serve/get-manifest.ts +20 -0
  25. package/src/executors/serve/schema.d.ts +2 -0
  26. package/src/executors/serve/schema.json +7 -0
  27. package/src/executors/serve/server.ts +250 -0
  28. package/src/executors/utils/get-vite-config.ts +9 -0
  29. package/src/executors/utils/logger.ts +90 -0
  30. package/src/generators/app/data/modules.ts +19 -0
  31. package/src/generators/app/generator.spec.ts +86 -0
  32. package/src/generators/app/generator.ts +141 -0
  33. package/src/generators/component-test/files/cypress/fixtures/example.json +5 -0
  34. package/src/generators/component-test/files/cypress/screenshots/.gitkeep +0 -0
  35. package/src/generators/component-test/files/cypress/support/commands.ts +37 -0
  36. package/src/generators/component-test/files/cypress/support/component-index.html +12 -0
  37. package/src/generators/component-test/files/cypress/support/component.ts +39 -0
  38. package/src/generators/component-test/files/cypress/videos/.gitkeep +0 -0
  39. package/src/generators/component-test/files/cypress.config.ts.template +43 -0
  40. package/src/generators/component-test/generator.spec.ts +79 -0
  41. package/src/generators/component-test/generator.ts +67 -0
  42. package/src/generators/component-test/schema.d.ts +3 -0
  43. package/src/generators/component-test/schema.json +17 -0
  44. package/src/generators/preset/generator.spec.ts +38 -0
  45. package/src/generators/preset/generator.ts +18 -0
  46. package/src/index.ts +1 -0
  47. package/src/migrations/add-publish-target/add-publish-target.spec.ts +60 -0
  48. package/src/migrations/add-publish-target/add-publish-target.ts +28 -0
  49. package/src/migrations/move-fusion-manifest/move-fusion-manifest.ts +35 -0
  50. package/src/migrations/remove-fusion-cli/remove-fusion-cli.ts +70 -0
  51. package/tsconfig.json +17 -0
  52. package/tsconfig.lib.json +20 -0
  53. package/tsconfig.spec.json +26 -0
  54. package/vite.config.ts +31 -0
  55. package/src/executors/build/build.d.ts +0 -4
  56. package/src/executors/build/build.js +0 -76
  57. package/src/executors/build/build.js.map +0 -1
  58. package/src/executors/build/executor.d.ts +0 -5
  59. package/src/executors/build/executor.js +0 -8
  60. package/src/executors/build/executor.js.map +0 -1
  61. package/src/executors/build/minify.d.ts +0 -2
  62. package/src/executors/build/minify.js +0 -22
  63. package/src/executors/build/minify.js.map +0 -1
  64. package/src/executors/create-vite-config.d.ts +0 -3
  65. package/src/executors/create-vite-config.js +0 -73
  66. package/src/executors/create-vite-config.js.map +0 -1
  67. package/src/executors/executor-context.d.ts +0 -2
  68. package/src/executors/executor-context.js +0 -101
  69. package/src/executors/executor-context.js.map +0 -1
  70. package/src/executors/publish/executor.d.ts +0 -5
  71. package/src/executors/publish/executor.js +0 -24
  72. package/src/executors/publish/executor.js.map +0 -1
  73. package/src/executors/publish/manifest-model.d.ts +0 -30
  74. package/src/executors/publish/manifest-model.js +0 -3
  75. package/src/executors/publish/manifest-model.js.map +0 -1
  76. package/src/executors/publish/publish-script.d.ts +0 -9
  77. package/src/executors/publish/publish-script.js +0 -185
  78. package/src/executors/publish/publish-script.js.map +0 -1
  79. package/src/executors/serve/executor.d.ts +0 -3
  80. package/src/executors/serve/executor.js +0 -8
  81. package/src/executors/serve/executor.js.map +0 -1
  82. package/src/executors/serve/get-manifest.d.ts +0 -2
  83. package/src/executors/serve/get-manifest.js +0 -20
  84. package/src/executors/serve/get-manifest.js.map +0 -1
  85. package/src/executors/serve/server.d.ts +0 -3
  86. package/src/executors/serve/server.js +0 -166
  87. package/src/executors/serve/server.js.map +0 -1
  88. package/src/executors/utils/get-vite-config.d.ts +0 -1
  89. package/src/executors/utils/get-vite-config.js +0 -13
  90. package/src/executors/utils/get-vite-config.js.map +0 -1
  91. package/src/executors/utils/logger.d.ts +0 -24
  92. package/src/executors/utils/logger.js +0 -68
  93. package/src/executors/utils/logger.js.map +0 -1
  94. package/src/generators/app/data/modules.d.ts +0 -19
  95. package/src/generators/app/data/modules.js +0 -23
  96. package/src/generators/app/data/modules.js.map +0 -1
  97. package/src/generators/app/generator.d.ts +0 -5
  98. package/src/generators/app/generator.js +0 -101
  99. package/src/generators/app/generator.js.map +0 -1
  100. package/src/generators/preset/generator.d.ts +0 -4
  101. package/src/generators/preset/generator.js +0 -13
  102. package/src/generators/preset/generator.js.map +0 -1
  103. package/src/index.js +0 -1
  104. package/src/index.js.map +0 -1
  105. package/src/migrations/add-publish-target/add-publish-target.d.ts +0 -2
  106. package/src/migrations/add-publish-target/add-publish-target.js +0 -32
  107. package/src/migrations/add-publish-target/add-publish-target.js.map +0 -1
  108. package/src/migrations/move-fusion-manifest/move-fusion-manifest.d.ts +0 -2
  109. package/src/migrations/move-fusion-manifest/move-fusion-manifest.js +0 -30
  110. package/src/migrations/move-fusion-manifest/move-fusion-manifest.js.map +0 -1
  111. package/src/migrations/remove-fusion-cli/remove-fusion-cli.d.ts +0 -2
  112. package/src/migrations/remove-fusion-cli/remove-fusion-cli.js +0 -48
  113. package/src/migrations/remove-fusion-cli/remove-fusion-cli.js.map +0 -1
  114. /package/src/{index.d.ts → generators/component-test/files/cypress/downloads/.gitkeep} +0 -0
@@ -0,0 +1,250 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ import { ServeExecutorSchema } from './schema';
3
+
4
+ const openBrowser = require('open');
5
+ const express = require('express');
6
+ const chalk = require('chalk');
7
+ const getPort = require('get-port-cjs');
8
+ import {
9
+ createServer as createViteServer,
10
+ LibraryOptions,
11
+ loadConfigFromFile,
12
+ } from 'vite';
13
+ import { resolve, join } from 'path';
14
+ import { readFileSync } from 'node:fs';
15
+ import { createProxyMiddleware } from 'http-proxy-middleware';
16
+ import { EnvironmentResponse } from '@equinor/fusion-framework-module-service-discovery';
17
+ import { AppManifest } from '@equinor/fusion-framework-module-app';
18
+ import { createRomaViteConfig } from '../create-vite-config';
19
+ import type { ExecutorContext } from '@nx/devkit';
20
+ import { getViteConfig } from '../utils/get-vite-config';
21
+ import { getManifest } from './get-manifest';
22
+
23
+ async function loadServices(portalTarget: string) {
24
+ try {
25
+ const req = await fetch(`${portalTarget}/_discovery/environments/current`);
26
+ const res = (await req.json()) as EnvironmentResponse;
27
+ return res.services
28
+ .filter((s) => s.uri.startsWith(portalTarget))
29
+ .map((s) => new URL(s.uri).pathname)
30
+ .filter((path) => path.length >= 3 && !path.startsWith('/apim/'));
31
+ } catch (ex) {
32
+ console.error(ex);
33
+ process.exit();
34
+ }
35
+ }
36
+
37
+ export async function createServer(
38
+ {
39
+ port: requestedPort = 3000,
40
+ devPortal = 'node_modules/@equinor/roma-framework/dev-portal',
41
+ portal: portalTarget = 'https://romadev.equinor.com',
42
+ open,
43
+ }: ServeExecutorSchema,
44
+ context: ExecutorContext,
45
+ additionalProjects?: Array<ServeExecutorSchema>
46
+ ) {
47
+ // Get path to dev-portal, this would be a flag from executor.
48
+ const devPortalPath = resolve(process.cwd(), devPortal);
49
+
50
+ // Get available port, prefers requestedPort but falls back to another free port
51
+ const ports = Array.from(
52
+ new Set([requestedPort, ...getPort.portNumbers(3000, 30009)])
53
+ );
54
+ const port = (await getPort({ port: ports })) as number;
55
+ if (!ports.includes(port)) {
56
+ throw new Error(`All valid ports (3000-3009) are closed`);
57
+ }
58
+ console.clear();
59
+
60
+ if (port !== requestedPort) {
61
+ console.log(chalk.yellow(`Port ${requestedPort} is taken, using ${port}`));
62
+ }
63
+
64
+ const projectName = context.projectName;
65
+ const project = context.workspace.projects[projectName];
66
+ const base = resolve(context.root, project.root);
67
+
68
+ // Load user-defined viteConfig
69
+ const viteConfigPath = getViteConfig(base);
70
+ const userConfig = await loadConfigFromFile(
71
+ {
72
+ command: 'build',
73
+ mode: 'production',
74
+ },
75
+ viteConfigPath
76
+ );
77
+
78
+ // Create express application
79
+ const app = express();
80
+ app.set('x-powered-by', false);
81
+ app.use(express.static(devPortalPath));
82
+
83
+ // Load Roma services
84
+ const services = await loadServices(portalTarget);
85
+ // Add proxy middleware for all roma-services
86
+ services.forEach((p) =>
87
+ app.use(
88
+ p,
89
+ createProxyMiddleware(p, { target: portalTarget, changeOrigin: true })
90
+ )
91
+ );
92
+
93
+ // Range of port numbers for hmr, otherwise HMR won't work for multiple apps at the same time
94
+ const hmrPorts = getPort.portNumbers(40000, 45000);
95
+ const hmrPort = await getPort(hmrPorts);
96
+
97
+ const viteConfig = createRomaViteConfig(
98
+ userConfig.config,
99
+ context,
100
+ false,
101
+ hmrPort
102
+ );
103
+ // Create Vite server in middleware mode
104
+ const vite = await createViteServer(viteConfig);
105
+
106
+ // Apply vite-middleware to the express app
107
+ app.use(vite.middlewares);
108
+
109
+ app.use(
110
+ '/apim*',
111
+ createProxyMiddleware('/apim', { target: portalTarget, changeOrigin: true })
112
+ );
113
+
114
+ app.use(
115
+ // Custom proxy-setup for service discovery endpoint
116
+ '/_discovery*',
117
+ createProxyMiddleware('/_discovery', {
118
+ target: portalTarget,
119
+ changeOrigin: true, // Avoid API errors due to origin-conflicts
120
+ secure: false,
121
+ selfHandleResponse: true, // Tell the proxy we want to override the response
122
+ onProxyRes: (proxyRes, req, res) => {
123
+ const body: Array<Uint8Array> = [];
124
+ proxyRes.on('data', function (chunk: Uint8Array) {
125
+ body.push(chunk);
126
+ });
127
+ proxyRes.on('end', function () {
128
+ const bodyStr = Buffer.concat(body).toString();
129
+ const environment = JSON.parse(bodyStr) as EnvironmentResponse;
130
+ // Override the services, and direct all api's from <target> to go via this proxy.
131
+ environment.services.forEach((s) => {
132
+ if (s.uri.includes(portalTarget)) {
133
+ s.uri = s.uri.replace(portalTarget, `http://localhost:${port}`);
134
+ }
135
+ });
136
+ res.end(JSON.stringify(environment));
137
+ });
138
+ },
139
+ })
140
+ );
141
+
142
+ // Extract entrypoint-url
143
+ const libConfig = vite.config.build.lib as LibraryOptions;
144
+ const entry = libConfig.entry as Record<string, string>;
145
+
146
+ // Custom proxy for app-list to add the current application
147
+ app.get(
148
+ '/api/apps',
149
+ createProxyMiddleware('/api/apps', {
150
+ target: portalTarget,
151
+ changeOrigin: true,
152
+ selfHandleResponse: true,
153
+ onProxyRes: (proxyRes, req, res) => {
154
+ const body: Array<Uint8Array> = [];
155
+ proxyRes.on('data', function (chunk: Uint8Array) {
156
+ body.push(chunk);
157
+ });
158
+ proxyRes.on('end', function () {
159
+ const bodyStr = Buffer.concat(body).toString();
160
+ const data = JSON.parse(bodyStr) as Array<AppManifest>;
161
+ const atIndex =
162
+ data?.findIndex((manifest) => manifest.key === projectName) ?? -1;
163
+ // If existing app, we need to change the entry-point.
164
+ if (atIndex > -1) {
165
+ data[atIndex].entry = `/${entry.self}`;
166
+ } else {
167
+ // New app, so adding it to the app-list
168
+ try {
169
+ // Read and parse fusion-manifest
170
+ const manifest = getManifest(vite.config.root);
171
+ manifest.entry = `/${entry.self}`;
172
+ data.push(manifest);
173
+ } catch (ex) {
174
+ throw new Error(
175
+ chalk.red(
176
+ `Fatal error: Failed to read fusion-manifest.json in ${vite.config.root}
177
+ Application will now exit.`
178
+ )
179
+ );
180
+ }
181
+ }
182
+ if (additionalProjects) {
183
+ additionalProjects.forEach((project) => {
184
+ const atIndex =
185
+ data?.findIndex((manifest) => manifest.key === project.name) ??
186
+ -1;
187
+ if (atIndex >= 0) {
188
+ data[atIndex] = {
189
+ ...data[atIndex],
190
+ entry: `/${entry[project.name]}`,
191
+ };
192
+ }
193
+ });
194
+ }
195
+ res.json(data);
196
+ });
197
+ },
198
+ })
199
+ );
200
+
201
+ // Roma portal api
202
+ app.use(
203
+ '/api/*',
204
+ createProxyMiddleware('/api', {
205
+ target: portalTarget,
206
+ changeOrigin: true,
207
+ })
208
+ );
209
+
210
+ // Roma SSE api
211
+ app.use(
212
+ '/eventstream/*',
213
+ createProxyMiddleware('/eventstream', {
214
+ target: portalTarget,
215
+ changeOrigin: true,
216
+ proxyTimeout: 1000 * 60 * 30,
217
+ })
218
+ );
219
+
220
+ // SPA-style routing
221
+ app.use('*', async (req, res) => {
222
+ const htmlRaw = readFileSync(join(devPortalPath + '/index.html'), 'utf-8');
223
+ const html = await vite.transformIndexHtml(req.url, htmlRaw);
224
+ res.send(html);
225
+ });
226
+
227
+ return new Promise((resolve) => {
228
+ // listen to requested port
229
+ app.listen(port, () => {
230
+ console.log(chalk.green('Roma dev server listening on port ' + port));
231
+ if (open) {
232
+ console.log(
233
+ chalk.green(
234
+ `Opening the application at http://localhost:${port}/apps/${projectName}`
235
+ )
236
+ );
237
+ openBrowser(`http://localhost:${port}/apps/${projectName}`);
238
+ } else {
239
+ console.log(
240
+ chalk.green(
241
+ `Open the application at http://localhost:${port}/apps/${projectName}`
242
+ )
243
+ );
244
+ }
245
+ });
246
+ app.on('close', () => {
247
+ resolve({ success: true });
248
+ });
249
+ });
250
+ }
@@ -0,0 +1,9 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { resolve } from 'path';
3
+
4
+ export function getViteConfig(root: string) {
5
+ const files = readdirSync(root);
6
+ const file = files.find((f) => f.startsWith('vite.config'));
7
+ if (!file) throw new Error(`No vite config found!`);
8
+ return resolve(root, file);
9
+ }
@@ -0,0 +1,90 @@
1
+ import { LogErrorOptions, LogOptions, LogType } from 'vite';
2
+ import { RollupError } from 'rollup';
3
+
4
+ type ILogger = {
5
+ info(msg: string, options?: LogOptions): void;
6
+ warn(msg: string, options?: LogOptions): void;
7
+ warnOnce(msg: string, options?: LogOptions): void;
8
+ error(msg: string, options?: LogErrorOptions): void;
9
+ clearScreen(type: LogType): void;
10
+ hasErrorLogged(error: Error | RollupError): boolean;
11
+ hasWarned: boolean;
12
+ };
13
+
14
+ const timestamp = () => {
15
+ const date = new Date();
16
+ const year = date.getFullYear();
17
+ const month = date.getUTCMonth() + 1;
18
+ const day = date.getDate();
19
+ const hour = date.getHours();
20
+ const minutes = date.getMinutes();
21
+ const seconds = date.getSeconds();
22
+ return `[${year}-${String(month).padStart(
23
+ 2,
24
+ '0'
25
+ )}-${day} ${hour}:${minutes}:${seconds}]`;
26
+ };
27
+
28
+ const logModes = {
29
+ error: () => {
30
+ return `${timestamp()}: [roma]:`;
31
+ },
32
+ warning: () => {
33
+ return `${timestamp()}: [roma]:`;
34
+ },
35
+ info: () => {
36
+ return `${timestamp()}: [roma]:`;
37
+ },
38
+ };
39
+
40
+ // Custom logger, for now ignores error on roma-framework.umd.js, but can be improved on further.
41
+ export class Logger implements ILogger {
42
+ private warnings: Set<string>;
43
+ private errors: Set<Error | RollupError>;
44
+ public hasWarned: boolean;
45
+
46
+ constructor() {
47
+ this.warnings = new Set();
48
+ this.errors = new Set();
49
+ this.hasWarned = false;
50
+ }
51
+
52
+ info(msg: string, options?: LogOptions): void {
53
+ if (options?.clear) this.clearScreen('info');
54
+ console.info(logModes.info(), msg);
55
+ // Additional logic can be added here to handle options
56
+ }
57
+
58
+ warn(msg: string, options?: LogOptions): void {
59
+ console.warn(logModes.warning(), msg);
60
+ if (options?.clear) this.clearScreen('warn');
61
+ this.hasWarned = true;
62
+ // Additional logic can be added here to handle options
63
+ }
64
+
65
+ warnOnce(msg: string, options?: LogOptions): void {
66
+ if (!this.warnings.has(msg)) {
67
+ this.warnings.add(msg);
68
+ this.warn(msg, options);
69
+ }
70
+ }
71
+
72
+ error(msg: string, options?: LogErrorOptions): void {
73
+ if (
74
+ typeof msg === 'string' &&
75
+ msg.includes('resolved id: /roma-framework.umd.js')
76
+ )
77
+ return;
78
+ if (options?.clear) this.clearScreen('error');
79
+ console.error(logModes.error(), msg);
80
+ }
81
+
82
+ clearScreen(type: LogType): void {
83
+ console.clear();
84
+ if (type === 'error') console.log(`Console cleared: ${type}`);
85
+ }
86
+
87
+ hasErrorLogged(error: Error | RollupError): boolean {
88
+ return this.errors.has(error);
89
+ }
90
+ }
@@ -0,0 +1,19 @@
1
+ export const modules = {
2
+ "fusion-framework-module-msal": "^4.0.5",
3
+ "fusion-framework-module-navigation": "^3.0.5",
4
+ "fusion-framework-module-context": "^4.0.13",
5
+ "fusion-framework-module-ag-grid": "^30.1.0",
6
+ "fusion-framework-module-bookmark": "1.0.10",
7
+ "fusion-framework-module-event": "^4.0.5",
8
+ "fusion-framework-module-http": "^5.0.6",
9
+ "fusion-framework-module-service-discovery": "^5.0.6",
10
+ "fusion-framework-module-services": "^3.1.5",
11
+ "fusion-framework-module-signalr": "^2.0.7",
12
+ "fusion-framework-module-telemetry": "^4.0.2",
13
+ "fusion-framework-module-widget": "^1.0.9",
14
+ "fusion-framework-react-module-bookmark": "^2.0.17",
15
+ "fusion-framework-react-module-http": "^3.0.5",
16
+ "fusion-framework-react-module-context": " ^6.0.12",
17
+ "fusion-framework-react-module-signalr": "^2.0.7",
18
+ "fusion-framework-react-module-event": "^3.1.2"
19
+ }
@@ -0,0 +1,86 @@
1
+ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2
+ import { readProjectConfiguration, Tree } from '@nx/devkit';
3
+
4
+ import { appGenerator } from './generator';
5
+
6
+ describe('app generator', () => {
7
+ let tree: Tree;
8
+
9
+ beforeEach(() => {
10
+ tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
11
+ });
12
+
13
+ it('should run successfully when rootFormat is derived', async () => {
14
+ expect(() => readProjectConfiguration(tree, 'test')).toThrow();
15
+ await appGenerator(tree, {
16
+ name: 'test',
17
+ fusionModules: [],
18
+ projectName: 'test',
19
+ appProjectRoot: '',
20
+ e2eProjectName: '',
21
+ e2eProjectRoot: '',
22
+ parsedTags: [],
23
+ fileName: '',
24
+ styledModule: 'css',
25
+ minimal: false,
26
+ routing: false,
27
+ hasStyles: false,
28
+ unitTestRunner: 'none',
29
+ style: 'css',
30
+ e2eTestRunner: 'none',
31
+ linter: null,
32
+ projectNameAndRootFormat: 'derived',
33
+ });
34
+ const config = readProjectConfiguration(tree, 'test');
35
+ expect(config).toBeDefined();
36
+ });
37
+
38
+ it('should run successfully when rootFormat is as-provided', async () => {
39
+ expect(() => readProjectConfiguration(tree, 'test')).toThrow();
40
+ await appGenerator(tree, {
41
+ name: 'test',
42
+ fusionModules: [],
43
+ projectName: 'test',
44
+ appProjectRoot: '',
45
+ e2eProjectName: '',
46
+ e2eProjectRoot: '',
47
+ parsedTags: [],
48
+ fileName: '',
49
+ styledModule: 'css',
50
+ minimal: false,
51
+ routing: false,
52
+ hasStyles: false,
53
+ unitTestRunner: 'none',
54
+ style: 'css',
55
+ e2eTestRunner: 'none',
56
+ linter: null,
57
+ projectNameAndRootFormat: 'as-provided',
58
+ });
59
+ const config = readProjectConfiguration(tree, 'test');
60
+ expect(config).toBeDefined();
61
+ });
62
+
63
+ it('should run successfully when rootFormat is not set', async () => {
64
+ expect(() => readProjectConfiguration(tree, 'test')).toThrow();
65
+ await appGenerator(tree, {
66
+ name: 'test',
67
+ fusionModules: [],
68
+ projectName: 'test',
69
+ appProjectRoot: '',
70
+ e2eProjectName: '',
71
+ e2eProjectRoot: '',
72
+ parsedTags: [],
73
+ fileName: '',
74
+ styledModule: 'css',
75
+ minimal: false,
76
+ routing: false,
77
+ hasStyles: false,
78
+ unitTestRunner: 'none',
79
+ style: 'css',
80
+ e2eTestRunner: 'none',
81
+ linter: null,
82
+ });
83
+ const config = readProjectConfiguration(tree, 'test');
84
+ expect(config).toBeDefined();
85
+ });
86
+ });
@@ -0,0 +1,141 @@
1
+ import {
2
+ addDependenciesToPackageJson,
3
+ formatFiles,
4
+ generateFiles,
5
+ getWorkspaceLayout,
6
+ installPackagesTask,
7
+ runTasksInSerial,
8
+ Tree,
9
+ updateProjectConfiguration,
10
+ readProjectConfiguration,
11
+ } from '@nx/devkit';
12
+ import * as path from 'path';
13
+ import { AppGeneratorSchema } from './schema';
14
+ import { applicationGenerator } from '@nx/react';
15
+ import { NormalizedSchema } from '@nx/react/src/generators/application/schema';
16
+ import { modules } from './data/modules';
17
+ import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
18
+
19
+ async function addDependencies(
20
+ tree: Tree,
21
+ options: AppGeneratorSchema & Omit<NormalizedSchema, 'bundler' | 'minimal'>
22
+ ) {
23
+ const dependencies: Record<string, string> = {
24
+ '@equinor/roma-framework': '^0.0.12',
25
+ '@equinor/fusion-framework': '7.0.30',
26
+ '@equinor/fusion-framework-module-app': '5.2.13',
27
+ '@equinor/eds-core-react': '^0.39.0',
28
+ '@equinor/eds-data-grid-react': '^0.6.1',
29
+ '@equinor/eds-icons': '^0.21.0',
30
+ '@equinor/eds-tokens': '^0.9.2',
31
+ '@equinor/fusion-framework-react': '6.0.2',
32
+ '@equinor/fusion-framework-react-app': '4.3.3',
33
+ '@equinor/fusion-framework-react-module': '3.0.8',
34
+ '@equinor/fusion-framework-module-navigation': '3.1.4',
35
+ 'styled-components': '^6.0.8',
36
+ };
37
+ options.fusionModules
38
+ .flatMap((module) => module.split(','))
39
+ .forEach((module) => {
40
+ dependencies[`@equinor/${module}`] = modules[module];
41
+ });
42
+ const devDependencies = {};
43
+ return runTasksInSerial(
44
+ ...[
45
+ addDependenciesToPackageJson(
46
+ tree,
47
+ dependencies,
48
+ devDependencies,
49
+ undefined,
50
+ true
51
+ ),
52
+ ]
53
+ );
54
+ }
55
+
56
+ function updateTargets(
57
+ tree: Tree,
58
+ options: AppGeneratorSchema & Omit<NormalizedSchema, 'bundler'>
59
+ ) {
60
+ const existing = readProjectConfiguration(tree, options.name);
61
+ updateProjectConfiguration(tree, options.name, {
62
+ ...existing,
63
+ targets: {
64
+ build: {
65
+ executor: '@equinor/roma-nx-plugin:build',
66
+ options: {},
67
+ },
68
+ serve: {
69
+ executor: '@equinor/roma-nx-plugin:serve',
70
+ options: {
71
+ port: options.devServerPort ?? 3000,
72
+ },
73
+ },
74
+ portal: {
75
+ executor: '@equinor/roma-nx-plugin:portal',
76
+ options: {},
77
+ },
78
+ publish: {
79
+ executor: '@equinor/roma-nx-plugin:publish',
80
+ dependsOn: ['build'],
81
+ configurations: {
82
+ production: {
83
+ environment: 'production',
84
+ },
85
+ qa: {
86
+ environment: 'qa',
87
+ },
88
+ dev: {
89
+ environment: 'dev',
90
+ },
91
+ },
92
+ defaultConfiguration: 'dev',
93
+ },
94
+ },
95
+ });
96
+ }
97
+
98
+ export async function appGenerator(
99
+ tree: Tree,
100
+ options: AppGeneratorSchema & Omit<NormalizedSchema, 'bundler'>
101
+ ) {
102
+ const derived = options.projectNameAndRootFormat !== 'as-provided';
103
+ if (derived && options.directory) {
104
+ throw new Error(
105
+ 'You cannot provide a directory when using projectNameAndRootFormat = derived '
106
+ );
107
+ }
108
+ const config = getWorkspaceLayout(tree);
109
+ const outputDir = derived
110
+ ? `${config.appsDir}/${options.name}`
111
+ : path.join(getRelativeCwd(), options.directory ?? options.name);
112
+
113
+ await applicationGenerator(tree, {
114
+ ...options,
115
+ tags: [options.tags ?? '', 'roma-application'].join(','),
116
+ rootProject: false,
117
+ bundler: 'vite',
118
+ });
119
+ tree.delete(`${outputDir}/vite.config.ts`);
120
+ tree.delete(`${outputDir}/index.html`);
121
+ updateTargets(tree, options);
122
+ generateFiles(tree, path.join(__dirname, 'files'), outputDir, options);
123
+ await addDependencies(tree, options);
124
+ await formatFiles(tree);
125
+ tree.delete(`${outputDir}/src/app`);
126
+ tree.delete(`${outputDir}/src/assets`);
127
+ tree.delete(`${outputDir}/src/main.tsx`);
128
+ tree.delete(`${outputDir}/src/styles.css`);
129
+ tree.delete(`${outputDir}/index.html`);
130
+ tree.delete(`${outputDir}/public`);
131
+
132
+ if (options.skipPackageJson) {
133
+ return () => true;
134
+ }
135
+
136
+ return () => {
137
+ installPackagesTask(tree);
138
+ };
139
+ }
140
+
141
+ export default appGenerator;
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference types="cypress" />
2
+ // ***********************************************
3
+ // This example commands.ts shows you how to
4
+ // create various custom commands and overwrite
5
+ // existing commands.
6
+ //
7
+ // For more comprehensive examples of custom
8
+ // commands please read more here:
9
+ // https://on.cypress.io/custom-commands
10
+ // ***********************************************
11
+ //
12
+ //
13
+ // -- This is a parent command --
14
+ // Cypress.Commands.add('login', (email, password) => { ... })
15
+ //
16
+ //
17
+ // -- This is a child command --
18
+ // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19
+ //
20
+ //
21
+ // -- This is a dual command --
22
+ // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23
+ //
24
+ //
25
+ // -- This will overwrite an existing command --
26
+ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27
+ //
28
+ // declare global {
29
+ // namespace Cypress {
30
+ // interface Chainable {
31
+ // login(email: string, password: string): Chainable<void>
32
+ // drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33
+ // dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34
+ // visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35
+ // }
36
+ // }
37
+ // }
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
+ <title>Components App</title>
8
+ </head>
9
+ <body>
10
+ <div data-cy-root></div>
11
+ </body>
12
+ </html>