@nrwl/remix 13.7.1 → 14.1.7

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 (71) hide show
  1. package/README.md +2 -2
  2. package/generators.json +25 -0
  3. package/package.json +1 -1
  4. package/src/generators/action/action.impl.d.ts +3 -0
  5. package/src/generators/action/action.impl.js +48 -0
  6. package/src/generators/action/action.impl.js.map +1 -0
  7. package/src/generators/action/schema.d.ts +4 -0
  8. package/src/generators/action/schema.json +27 -0
  9. package/src/generators/application/files/.gitignore__tmpl__ +4 -0
  10. package/src/generators/application/files/app/entry.client.tsx__tmpl__ +2 -2
  11. package/src/generators/application/files/app/entry.server.tsx__tmpl__ +4 -4
  12. package/src/generators/application/files/app/root.tsx__tmpl__ +10 -156
  13. package/src/generators/application/files/app/routes/index.tsx__tmpl__ +28 -96
  14. package/src/generators/application/files/package.json__tmpl__ +1 -1
  15. package/src/generators/application/files/remix.config.js__tmpl__ +7 -7
  16. package/src/generators/application/files/tsconfig.json__tmpl__ +6 -1
  17. package/src/generators/cypress/cypress.impl.js +3 -3
  18. package/src/generators/cypress/cypress.impl.js.map +1 -1
  19. package/src/generators/loader/loader.impl.d.ts +3 -0
  20. package/src/generators/loader/loader.impl.js +48 -0
  21. package/src/generators/loader/loader.impl.js.map +1 -0
  22. package/src/generators/loader/schema.d.ts +4 -0
  23. package/src/generators/loader/schema.json +27 -0
  24. package/src/generators/meta/meta.impl.d.ts +3 -0
  25. package/src/generators/meta/meta.impl.js +29 -0
  26. package/src/generators/meta/meta.impl.js.map +1 -0
  27. package/src/generators/meta/schema.d.ts +4 -0
  28. package/src/generators/meta/schema.json +27 -0
  29. package/src/generators/resource-route/resource-route.impl.d.ts +3 -0
  30. package/src/generators/resource-route/resource-route.impl.js +32 -0
  31. package/src/generators/resource-route/resource-route.impl.js.map +1 -0
  32. package/src/generators/resource-route/schema.d.ts +6 -0
  33. package/src/generators/resource-route/schema.json +44 -0
  34. package/src/generators/route/route.impl.js +37 -61
  35. package/src/generators/route/route.impl.js.map +1 -1
  36. package/src/generators/route/schema.d.ts +3 -0
  37. package/src/generators/route/schema.json +24 -9
  38. package/src/generators/style/schema.d.ts +4 -0
  39. package/src/generators/style/schema.json +34 -0
  40. package/src/generators/style/style.impl.d.ts +3 -0
  41. package/src/generators/style/style.impl.js +41 -0
  42. package/src/generators/style/style.impl.js.map +1 -0
  43. package/src/utils/get-default-export-name.d.ts +2 -0
  44. package/src/utils/get-default-export-name.js +10 -0
  45. package/src/utils/get-default-export-name.js.map +1 -0
  46. package/src/utils/get-default-export.d.ts +2 -0
  47. package/src/utils/get-default-export.js +16 -0
  48. package/src/utils/get-default-export.js.map +1 -0
  49. package/src/utils/insert-import.d.ts +4 -0
  50. package/src/utils/insert-import.js +55 -0
  51. package/src/utils/insert-import.js.map +1 -0
  52. package/src/utils/insert-statement-after-imports.d.ts +5 -0
  53. package/src/utils/insert-statement-after-imports.js +29 -0
  54. package/src/utils/insert-statement-after-imports.js.map +1 -0
  55. package/src/utils/insert-statement-in-default-function.d.ts +2 -0
  56. package/src/utils/insert-statement-in-default-function.js +24 -0
  57. package/src/utils/insert-statement-in-default-function.js.map +1 -0
  58. package/src/utils/remix-route-utils.d.ts +11 -0
  59. package/src/utils/remix-route-utils.js +53 -0
  60. package/src/utils/remix-route-utils.js.map +1 -0
  61. package/src/generators/application/files/app/routes/demos/about/index.tsx__tmpl__ +0 -17
  62. package/src/generators/application/files/app/routes/demos/about/whoa.tsx__tmpl__ +0 -20
  63. package/src/generators/application/files/app/routes/demos/about.tsx__tmpl__ +0 -44
  64. package/src/generators/application/files/app/routes/demos/actions.tsx__tmpl__ +0 -101
  65. package/src/generators/application/files/app/routes/demos/correct.tsx__tmpl__ +0 -3
  66. package/src/generators/application/files/app/routes/demos/params/$id.tsx__tmpl__ +0 -110
  67. package/src/generators/application/files/app/routes/demos/params/index.tsx__tmpl__ +0 -40
  68. package/src/generators/application/files/app/routes/demos/params.tsx__tmpl__ +0 -43
  69. package/src/generators/application/files/app/styles/dark.css +0 -7
  70. package/src/generators/application/files/app/styles/demos/about.css +0 -26
  71. package/src/generators/application/files/app/styles/global.css +0 -216
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "data-loader",
5
+ "type": "object",
6
+ "properties": {
7
+ "path": {
8
+ "type": "string",
9
+ "description": "The route path or path to the filename of the route.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What is the path of the route? (e.g. 'foo/bar')"
15
+ },
16
+ "project": {
17
+ "type": "string",
18
+ "description": "The name of the project.",
19
+ "$default": {
20
+ "$source": "projectName"
21
+ },
22
+ "x-prompt": "What project is this route for?",
23
+ "pattern": "^[a-zA-Z].*$"
24
+ }
25
+ },
26
+ "required": ["path", "project"]
27
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ import { LoaderSchema } from './schema';
3
+ export default function (tree: Tree, schema: LoaderSchema): Promise<void>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const devkit_1 = require("@nrwl/devkit");
5
+ const insert_import_1 = require("../../utils/insert-import");
6
+ const insert_statement_after_imports_1 = require("../../utils/insert-statement-after-imports");
7
+ const get_default_export_name_1 = require("../../utils/get-default-export-name");
8
+ const remix_route_utils_1 = require("../../utils/remix-route-utils");
9
+ function default_1(tree, schema) {
10
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
11
+ const routeFilePath = (0, remix_route_utils_1.resolveRemixRouteFile)(tree, schema.path, schema.project);
12
+ if (!tree.exists(routeFilePath)) {
13
+ throw new Error(`Route path does not exist: ${routeFilePath}. Please generate a Remix route first.`);
14
+ }
15
+ (0, insert_import_1.insertImport)(tree, routeFilePath, 'MetaFunction', '@remix-run/node', {
16
+ typeOnly: true,
17
+ });
18
+ const defaultExportName = (0, get_default_export_name_1.getDefaultExportName)(tree, routeFilePath);
19
+ (0, insert_statement_after_imports_1.insertStatementAfterImports)(tree, routeFilePath, `
20
+ export const meta: MetaFunction = () =>{
21
+ return { title: '${defaultExportName} Route' };
22
+ };
23
+
24
+ `);
25
+ yield (0, devkit_1.formatFiles)(tree);
26
+ });
27
+ }
28
+ exports.default = default_1;
29
+ //# sourceMappingURL=meta.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.impl.js","sourceRoot":"","sources":["../../../../../../packages/remix/src/generators/meta/meta.impl.ts"],"names":[],"mappings":";;;AAAA,yCAAiD;AAEjD,6DAAyD;AACzD,+FAAyF;AACzF,iFAA2E;AAC3E,qEAAsE;AAEtE,mBAA+B,IAAU,EAAE,MAAoB;;QAC7D,MAAM,aAAa,GAAG,IAAA,yCAAqB,EACzC,IAAI,EACJ,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,OAAO,CACf,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;YAC/B,MAAM,IAAI,KAAK,CACb,8BAA8B,aAAa,wCAAwC,CACpF,CAAC;SACH;QAED,IAAA,4BAAY,EAAC,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE;YACnE,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QAEH,MAAM,iBAAiB,GAAG,IAAA,8CAAoB,EAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACpE,IAAA,4DAA2B,EACzB,IAAI,EACJ,aAAa,EACb;;yBAEqB,iBAAiB;;;KAGrC,CACF,CAAC;QACF,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AA7BD,4BA6BC"}
@@ -0,0 +1,4 @@
1
+ export interface LoaderSchema {
2
+ path: string;
3
+ project: string;
4
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "meta",
5
+ "type": "object",
6
+ "properties": {
7
+ "path": {
8
+ "type": "string",
9
+ "description": "The route path or path to the filename of the route.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What is the path of the route? (e.g. 'foo/bar')"
15
+ },
16
+ "project": {
17
+ "type": "string",
18
+ "description": "The name of the project.",
19
+ "$default": {
20
+ "$source": "projectName"
21
+ },
22
+ "x-prompt": "What project is this route for?",
23
+ "pattern": "^[a-zA-Z].*$"
24
+ }
25
+ },
26
+ "required": ["path", "project"]
27
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ import { RemixRouteSchema } from './schema';
3
+ export default function (tree: Tree, options: RemixRouteSchema): Promise<void>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const devkit_1 = require("@nrwl/devkit");
5
+ const loader_impl_1 = require("../loader/loader.impl");
6
+ const action_impl_1 = require("../action/action.impl");
7
+ const remix_route_utils_1 = require("../../utils/remix-route-utils");
8
+ function default_1(tree, options) {
9
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
10
+ const routeFilePath = (0, remix_route_utils_1.resolveRemixRouteFile)(tree, options.path, options.project, '.ts');
11
+ if (tree.exists(routeFilePath))
12
+ throw new Error(`Path already exists: ${options.path}`);
13
+ if (!options.loader && !options.action)
14
+ throw new Error('The resource route generator requires either `loader` or `action` to be true');
15
+ tree.write(routeFilePath, '');
16
+ if (options.loader) {
17
+ yield (0, loader_impl_1.default)(tree, {
18
+ project: options.project,
19
+ path: routeFilePath,
20
+ });
21
+ }
22
+ if (options.action) {
23
+ yield (0, action_impl_1.default)(tree, {
24
+ path: routeFilePath,
25
+ project: options.project,
26
+ });
27
+ }
28
+ yield (0, devkit_1.formatFiles)(tree);
29
+ });
30
+ }
31
+ exports.default = default_1;
32
+ //# sourceMappingURL=resource-route.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-route.impl.js","sourceRoot":"","sources":["../../../../../../packages/remix/src/generators/resource-route/resource-route.impl.ts"],"names":[],"mappings":";;;AAAA,yCAAiD;AAEjD,uDAAoD;AACpD,uDAAoD;AACpD,qEAAsE;AAEtE,mBAA+B,IAAU,EAAE,OAAyB;;QAClE,MAAM,aAAa,GAAG,IAAA,yCAAqB,EACzC,IAAI,EACJ,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,EACf,KAAK,CACN,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAE1D,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM;YACpC,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;QAEJ,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAE9B,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,MAAM,IAAA,qBAAe,EAAC,IAAI,EAAE;gBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,aAAa;aACpB,CAAC,CAAC;SACJ;QAED,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,MAAM,IAAA,qBAAe,EAAC,IAAI,EAAE;gBAC1B,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;SACJ;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AAjCD,4BAiCC"}
@@ -0,0 +1,6 @@
1
+ export interface RemixRouteSchema {
2
+ project: string;
3
+ path: string;
4
+ action: boolean;
5
+ loader: boolean;
6
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "NxRemixResourceRoute",
4
+ "cli": "nx",
5
+ "title": "Create a Resource Route",
6
+ "type": "object",
7
+ "examples": [
8
+ {
9
+ "command": "g resource-route 'path/to/page'",
10
+ "description": "Generate resource route at /path/to/page"
11
+ }
12
+ ],
13
+ "properties": {
14
+ "path": {
15
+ "type": "string",
16
+ "description": "The route path or path to the filename of the route.",
17
+ "$default": {
18
+ "$source": "argv",
19
+ "index": 0
20
+ },
21
+ "x-prompt": "What is the path of the route? (e.g. 'foo/bar')"
22
+ },
23
+ "project": {
24
+ "type": "string",
25
+ "description": "The name of the project.",
26
+ "$default": {
27
+ "$source": "projectName"
28
+ },
29
+ "x-prompt": "What project is this route for?",
30
+ "pattern": "^[a-zA-Z].*$"
31
+ },
32
+ "action": {
33
+ "type": "boolean",
34
+ "description": "Generate an action function",
35
+ "default": false
36
+ },
37
+ "loader": {
38
+ "type": "boolean",
39
+ "description": "Generate a loader function",
40
+ "default": true
41
+ }
42
+ },
43
+ "required": ["project", "path"]
44
+ }
@@ -2,85 +2,61 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const devkit_1 = require("@nrwl/devkit");
5
+ const loader_impl_1 = require("../loader/loader.impl");
6
+ const meta_impl_1 = require("../meta/meta.impl");
7
+ const action_impl_1 = require("../action/action.impl");
8
+ const style_impl_1 = require("../style/style.impl");
9
+ const remix_route_utils_1 = require("../../utils/remix-route-utils");
5
10
  function default_1(tree, options) {
6
11
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
7
- const { fileName: routePath, className: componentName } = (0, devkit_1.names)(options.path.replace(/^\//, '').replace(/\/$/, ''));
8
- const projects = (0, devkit_1.getProjects)(tree);
9
- const project = projects.get(options.project);
10
- const normalizedRoutePath = normalizeRoutePath(routePath, project.root);
12
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
11
13
  if (!project)
12
14
  throw new Error(`Project does not exist: ${options.project}`);
13
- const componentPath = (0, devkit_1.joinPathFragments)(project.root, 'app/routes', `${normalizedRoutePath}.tsx`);
14
- if (tree.exists(componentPath))
15
- throw new Error(`Path already exists: ${options.path}`);
16
- tree.write(componentPath, (0, devkit_1.stripIndents) `
17
- import { useEffect, useRef } from 'react';
18
- ${options.style === 'css'
19
- ? `import type { LinksFunction, LoaderFunction, MetaFunction } from 'remix';
20
- `
21
- : `import type { LoaderFunction, MetaFunction } from 'remix';`}
22
- import { useActionData, useLoaderData, redirect } from 'remix';
15
+ const routeFilePath = (0, remix_route_utils_1.resolveRemixRouteFile)(tree, options.path, options.project, '.tsx');
16
+ const { className: componentName } = (0, devkit_1.names)(options.path.replace(/^\//, '').replace(/\/$/, '').replace('.tsx', ''));
17
+ if (tree.exists(routeFilePath))
18
+ throw new Error(`Path already exists: ${routeFilePath}`);
19
+ tree.write(routeFilePath, (0, devkit_1.stripIndents) `
23
20
 
24
- ${options.style === 'css'
25
- ? `import stylesUrl from '~/styles/${normalizedRoutePath}.css';`
26
- : ''}
27
-
28
-
29
- // Provide meta tags for this page.
30
- // - https://remix.run/api/conventions#meta
31
- export const meta: MetaFunction = () =>{
32
- return { title: '${componentName}' };
33
- }
34
-
35
- ${options.style === 'css'
36
- ? (0, devkit_1.stripIndents) `
37
- // Provide stylesheet for this page.
38
- // - https://remix.run/api/conventions#links
39
- export const links: LinksFunction = () => {
40
- return [{ rel: 'stylesheet', href: stylesUrl }];
41
- };
42
- `
43
- : ''}
44
-
45
- // Use this function to provide data for the route.
46
- // - https://remix.run/api/conventions#loader
47
- export const loader: LoaderFunction = async () => {
48
- return {
49
- message: 'Hello, world!',
50
- }
51
- }
52
21
 
53
22
  export default function ${componentName}() {
54
- const data = useLoaderData();
23
+ ${options.loader
24
+ ? `
55
25
  return (
56
26
  <p>
57
27
  Message: {data.message}
58
28
  </p>
59
29
  );
30
+ `
31
+ : `return (<p>${componentName} works!</p>)`}
60
32
  }
61
33
  `);
34
+ if (options.loader) {
35
+ yield (0, loader_impl_1.default)(tree, {
36
+ project: options.project,
37
+ path: routeFilePath,
38
+ });
39
+ }
40
+ if (options.meta) {
41
+ yield (0, meta_impl_1.default)(tree, {
42
+ path: routeFilePath,
43
+ project: options.project,
44
+ });
45
+ }
46
+ if (options.action) {
47
+ yield (0, action_impl_1.default)(tree, {
48
+ path: routeFilePath,
49
+ project: options.project,
50
+ });
51
+ }
62
52
  if (options.style === 'css') {
63
- const stylesheetPath = (0, devkit_1.joinPathFragments)(project.root, 'app/styles', `${normalizedRoutePath}.css`);
64
- tree.write(stylesheetPath, (0, devkit_1.stripIndents) `
65
- :root {
66
- --color-foreground: #fff;
67
- --color-background: #143157;
68
- --color-links: hsl(214, 73%, 69%);
69
- --color-border: #275da8;
70
- --font-body: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
71
- Liberation Mono, Courier New, monospace;
72
- }
73
- `);
53
+ yield (0, style_impl_1.default)(tree, {
54
+ project: options.project,
55
+ path: options.path,
56
+ });
74
57
  }
75
58
  yield (0, devkit_1.formatFiles)(tree);
76
59
  });
77
60
  }
78
61
  exports.default = default_1;
79
- function normalizeRoutePath(path, projectRoot) {
80
- if (path.indexOf(projectRoot) === -1)
81
- return path;
82
- if (path.indexOf('/routes/') > -1)
83
- return path.substring(path.indexOf('/routes/') + 8);
84
- return path.substring(projectRoot.length + 1);
85
- }
86
62
  //# sourceMappingURL=route.impl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.impl.js","sourceRoot":"","sources":["../../../../../../packages/remix/src/generators/route/route.impl.ts"],"names":[],"mappings":";;;AAAA,yCAOsB;AAGtB,mBAA+B,IAAU,EAAE,OAAyB;;QAClE,MAAM,EAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAC,GAAG,IAAA,cAAK,EAC3D,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CACnD,CAAC;QAGF,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE9C,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAEvE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAE5E,MAAM,aAAa,GAAG,IAAA,0BAAiB,EACrC,OAAO,CAAC,IAAI,EACZ,YAAY,EACZ,GAAG,mBAAmB,MAAM,CAC7B,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAE1D,IAAI,CAAC,KAAK,CACR,aAAa,EACb,IAAA,qBAAY,EAAA;;MAGV,OAAO,CAAC,KAAK,KAAK,KAAK;YACrB,CAAC,CAAC;OACH;YACC,CAAC,CAAC,4DACN;;;MAIE,OAAO,CAAC,KAAK,KAAK,KAAK;YACrB,CAAC,CAAC,mCAAmC,mBAAmB,QAAQ;YAChE,CAAC,CAAC,EACN;;;;;;yBAMqB,aAAa;;;MAIhC,OAAO,CAAC,KAAK,KAAK,KAAK;YACrB,CAAC,CAAC,IAAA,qBAAY,EAAA;;;;;;SAMb;YACD,CAAC,CAAC,EACN;;;;;;;;;;8BAU0B,aAAa;;;;;;;;GAQxC,CACA,CAAC;QAEF,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE;YAC3B,MAAM,cAAc,GAAG,IAAA,0BAAiB,EACtC,OAAO,CAAC,IAAI,EACZ,YAAY,EACZ,GAAG,mBAAmB,MAAM,CAC7B,CAAC;YACF,IAAI,CAAC,KAAK,CACR,cAAc,EACd,IAAA,qBAAY,EAAA;;;;;;;;;KASb,CACA,CAAC;SACH;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AApGD,4BAoGC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,WAAmB;IAC3D,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IACjD,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;IACtF,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC/C,CAAC"}
1
+ {"version":3,"file":"route.impl.js","sourceRoot":"","sources":["../../../../../../packages/remix/src/generators/route/route.impl.ts"],"names":[],"mappings":";;;AAAA,yCAOsB;AAEtB,uDAAoD;AACpD,iDAA8C;AAC9C,uDAAoD;AACpD,oDAAiD;AACjD,qEAAsE;AAEtE,mBAA+B,IAAU,EAAE,OAAyB;;QAClE,MAAM,OAAO,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAChE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAE5E,MAAM,aAAa,GAAG,IAAA,yCAAqB,EACzC,IAAI,EACJ,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,EACf,MAAM,CACP,CAAC;QAEF,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,IAAA,cAAK,EACxC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACvE,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,aAAa,EAAE,CAAC,CAAC;QAE3D,IAAI,CAAC,KAAK,CACR,aAAa,EACb,IAAA,qBAAY,EAAA;;;8BAGc,aAAa;MAErC,OAAO,CAAC,MAAM;YACZ,CAAC,CAAC;;;;;;KAML;YACG,CAAC,CAAC,cAAc,aAAa,cACjC;;GAED,CACA,CAAC;QAEF,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,MAAM,IAAA,qBAAe,EAAC,IAAI,EAAE;gBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,aAAa;aACpB,CAAC,CAAC;SACJ;QAED,IAAI,OAAO,CAAC,IAAI,EAAE;YAChB,MAAM,IAAA,mBAAa,EAAC,IAAI,EAAE;gBACxB,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;SACJ;QAED,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,MAAM,IAAA,qBAAe,EAAC,IAAI,EAAE;gBAC1B,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;SACJ;QAED,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE;YAC3B,MAAM,IAAA,oBAAc,EAAC,IAAI,EAAE;gBACzB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB,CAAC,CAAC;SACJ;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AApED,4BAoEC"}
@@ -2,4 +2,7 @@ export interface RemixRouteSchema {
2
2
  project: string;
3
3
  path: string;
4
4
  style: 'css' | 'none';
5
+ action: boolean;
6
+ meta: boolean;
7
+ loader: boolean;
5
8
  }
@@ -11,6 +11,15 @@
11
11
  }
12
12
  ],
13
13
  "properties": {
14
+ "path": {
15
+ "type": "string",
16
+ "description": "The route path or path to the filename of the route.",
17
+ "$default": {
18
+ "$source": "argv",
19
+ "index": 0
20
+ },
21
+ "x-prompt": "What is the path of the route? (e.g. 'foo/bar')"
22
+ },
14
23
  "project": {
15
24
  "type": "string",
16
25
  "description": "The name of the project.",
@@ -20,20 +29,26 @@
20
29
  "x-prompt": "What project is this route for?",
21
30
  "pattern": "^[a-zA-Z].*$"
22
31
  },
23
- "path": {
24
- "type": "string",
25
- "description": "Route path",
26
- "$default": {
27
- "$source": "argv",
28
- "index": 0
29
- },
30
- "x-prompt": "What is the path of the route? (e.g. 'foo/bar')"
31
- },
32
32
  "style": {
33
33
  "type": "string",
34
34
  "description": "Generate a stylesheet",
35
35
  "enum": ["none", "css"],
36
36
  "default": "css"
37
+ },
38
+ "meta": {
39
+ "type": "boolean",
40
+ "description": "Generate a meta function",
41
+ "default": false
42
+ },
43
+ "action": {
44
+ "type": "boolean",
45
+ "description": "Generate an action function",
46
+ "default": false
47
+ },
48
+ "loader": {
49
+ "type": "boolean",
50
+ "description": "Generate a loader function",
51
+ "default": false
37
52
  }
38
53
  },
39
54
  "required": ["project", "path"]
@@ -0,0 +1,4 @@
1
+ export interface RemixStyleSchema {
2
+ project: string;
3
+ path: string;
4
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "NxRemixRouteStyle",
4
+ "cli": "nx",
5
+ "title": "Add style import to a route",
6
+ "type": "object",
7
+ "examples": [
8
+ {
9
+ "command": "g style --project=webapp --path='path/to/page'",
10
+ "description": "Generate route at /path/to/page"
11
+ }
12
+ ],
13
+ "properties": {
14
+ "path": {
15
+ "type": "string",
16
+ "description": "Route path",
17
+ "$default": {
18
+ "$source": "argv",
19
+ "index": 0
20
+ },
21
+ "x-prompt": "What is the path of the route? (e.g. 'foo/bar')"
22
+ },
23
+ "project": {
24
+ "type": "string",
25
+ "description": "The name of the project.",
26
+ "$default": {
27
+ "$source": "projectName"
28
+ },
29
+ "x-prompt": "What project is this route in?",
30
+ "pattern": "^[a-zA-Z].*$"
31
+ }
32
+ },
33
+ "required": ["project", "path"]
34
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ import { RemixStyleSchema } from './schema';
3
+ export default function (tree: Tree, options: RemixStyleSchema): Promise<void>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const devkit_1 = require("@nrwl/devkit");
5
+ const insert_import_1 = require("../../utils/insert-import");
6
+ const insert_statement_after_imports_1 = require("../../utils/insert-statement-after-imports");
7
+ const remix_route_utils_1 = require("../../utils/remix-route-utils");
8
+ function default_1(tree, options) {
9
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
10
+ const { fileName: routePath, className: componentName } = (0, devkit_1.names)(options.path.replace(/^\//, '').replace(/\/$/, '').replace('.tsx', ''));
11
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
12
+ if (!project)
13
+ throw new Error(`Project does not exist: ${options.project}`);
14
+ const normalizedRoutePath = (0, remix_route_utils_1.normalizeRoutePath)(routePath, project.root);
15
+ const stylesheetPath = (0, devkit_1.joinPathFragments)(project.root, 'app/styles', `${normalizedRoutePath}.css`);
16
+ tree.write(stylesheetPath, (0, devkit_1.stripIndents) `
17
+ :root {
18
+ --color-foreground: #fff;
19
+ --color-background: #143157;
20
+ --color-links: hsl(214, 73%, 69%);
21
+ --color-border: #275da8;
22
+ --font-body: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
23
+ Liberation Mono, Courier New, monospace;
24
+ }
25
+ `);
26
+ const routeFilePath = (0, remix_route_utils_1.resolveRemixRouteFile)(tree, options.path, options.project, '.tsx');
27
+ (0, insert_import_1.insertImport)(tree, routeFilePath, 'LinksFunction', '@remix-run/node', {
28
+ typeOnly: true,
29
+ });
30
+ (0, insert_statement_after_imports_1.insertStatementAfterImports)(tree, routeFilePath, `
31
+ import stylesUrl from '~/styles/${normalizedRoutePath}.css'
32
+
33
+ export const links: LinksFunction = () => {
34
+ return [{ rel: 'stylesheet', href: stylesUrl }];
35
+ };
36
+ `);
37
+ yield (0, devkit_1.formatFiles)(tree);
38
+ });
39
+ }
40
+ exports.default = default_1;
41
+ //# sourceMappingURL=style.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.impl.js","sourceRoot":"","sources":["../../../../../../packages/remix/src/generators/style/style.impl.ts"],"names":[],"mappings":";;;AAAA,yCAOsB;AAGtB,6DAAyD;AACzD,+FAAyF;AACzF,qEAGuC;AAEvC,mBAA+B,IAAU,EAAE,OAAyB;;QAClE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,IAAA,cAAK,EAC7D,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACvE,CAAC;QAEF,MAAM,OAAO,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAChE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAE5E,MAAM,mBAAmB,GAAG,IAAA,sCAAkB,EAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAExE,MAAM,cAAc,GAAG,IAAA,0BAAiB,EACtC,OAAO,CAAC,IAAI,EACZ,YAAY,EACZ,GAAG,mBAAmB,MAAM,CAC7B,CAAC;QAEF,IAAI,CAAC,KAAK,CACR,cAAc,EACd,IAAA,qBAAY,EAAA;;;;;;;;;KASX,CACF,CAAC;QAEF,MAAM,aAAa,GAAG,IAAA,yCAAqB,EACzC,IAAI,EACJ,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,EACf,MAAM,CACP,CAAC;QAEF,IAAA,4BAAY,EAAC,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE;YACpE,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QAEH,IAAA,4DAA2B,EACzB,IAAI,EACJ,aAAa,EACb;sCACkC,mBAAmB;;;;;GAKtD,CACA,CAAC;QAEF,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AAtDD,4BAsDC"}
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ export declare function getDefaultExportName(tree: Tree, path: string): string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultExportName = void 0;
4
+ const get_default_export_1 = require("./get-default-export");
5
+ function getDefaultExportName(tree, path) {
6
+ var _a, _b;
7
+ return (_b = (_a = (0, get_default_export_1.getDefaultExport)(tree, path)) === null || _a === void 0 ? void 0 : _a.name.text) !== null && _b !== void 0 ? _b : 'Unknown';
8
+ }
9
+ exports.getDefaultExportName = getDefaultExportName;
10
+ //# sourceMappingURL=get-default-export-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-default-export-name.js","sourceRoot":"","sources":["../../../../../packages/remix/src/utils/get-default-export-name.ts"],"names":[],"mappings":";;;AACA,6DAAwD;AAExD,SAAgB,oBAAoB,CAAC,IAAU,EAAE,IAAY;;IAC3D,OAAO,MAAA,MAAA,IAAA,qCAAgB,EAAC,IAAI,EAAE,IAAI,CAAC,0CAAE,IAAI,CAAC,IAAI,mCAAI,SAAS,CAAC;AAC9D,CAAC;AAFD,oDAEC"}
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ export declare function getDefaultExport(tree: Tree, path: string): import("typescript").FunctionDeclaration;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultExport = void 0;
4
+ const typescript_1 = require("typescript");
5
+ function getDefaultExport(tree, path) {
6
+ const contents = tree.read(path, 'utf-8');
7
+ const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext);
8
+ const functionDeclarations = sourceFile.statements.filter(typescript_1.isFunctionDeclaration);
9
+ return functionDeclarations.find((functionDeclaration) => {
10
+ const isDefault = functionDeclaration.modifiers.find((mod) => mod.kind === typescript_1.SyntaxKind.DefaultKeyword);
11
+ const isExport = functionDeclaration.modifiers.find((mod) => mod.kind === typescript_1.SyntaxKind.ExportKeyword);
12
+ return isDefault && isExport;
13
+ });
14
+ }
15
+ exports.getDefaultExport = getDefaultExport;
16
+ //# sourceMappingURL=get-default-export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-default-export.js","sourceRoot":"","sources":["../../../../../packages/remix/src/utils/get-default-export.ts"],"names":[],"mappings":";;;AACA,2CAKoB;AAEpB,SAAgB,gBAAgB,CAAC,IAAU,EAAE,IAAY;IACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE1C,MAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,IAAI,EAAE,QAAQ,EAAE,yBAAY,CAAC,MAAM,CAAC,CAAC;IAEzE,MAAM,oBAAoB,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CACvD,kCAAqB,CACtB,CAAC;IAEF,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,mBAAmB,EAAE,EAAE;QACvD,MAAM,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAClD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,uBAAU,CAAC,cAAc,CAChD,CAAC;QAEF,MAAM,QAAQ,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,CACjD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,uBAAU,CAAC,aAAa,CAC/C,CAAC;QAEF,OAAO,SAAS,IAAI,QAAQ,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,4CAoBC"}
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ export declare function insertImport(tree: Tree, path: string, name: string, modulePath: string, options?: {
3
+ typeOnly: boolean;
4
+ }): void;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.insertImport = void 0;
4
+ const insert_statement_after_imports_1 = require("./insert-statement-after-imports");
5
+ const devkit_1 = require("@nrwl/devkit");
6
+ const typescript_1 = require("typescript");
7
+ function insertImport(tree, path, name, modulePath, options = { typeOnly: false }) {
8
+ if (!tree.exists(path))
9
+ throw Error(`Could not insert import ${name} from ${modulePath} in ${path}: path not found`);
10
+ const contents = tree.read(path, 'utf-8');
11
+ const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext);
12
+ let importStatements = sourceFile.statements.filter(typescript_1.isImportDeclaration);
13
+ if (options.typeOnly) {
14
+ importStatements = importStatements.filter((node) => node.importClause.isTypeOnly);
15
+ }
16
+ else {
17
+ importStatements = importStatements.filter((node) => !node.importClause.isTypeOnly);
18
+ }
19
+ const existingImport = importStatements.find((statement) => (0, typescript_1.isStringLiteral)(statement.moduleSpecifier) &&
20
+ statement.moduleSpecifier
21
+ .getText(sourceFile)
22
+ .replace(/['"`]/g, '')
23
+ .trim() === modulePath &&
24
+ statement.importClause.namedBindings &&
25
+ (0, typescript_1.isNamedImports)(statement.importClause.namedBindings));
26
+ if (!existingImport) {
27
+ (0, insert_statement_after_imports_1.insertStatementAfterImports)(tree, path, options.typeOnly
28
+ ? `import type { ${name} } from '${modulePath}';`
29
+ : `import { ${name} } from '${modulePath}';`);
30
+ return;
31
+ }
32
+ const namedImports = existingImport.importClause
33
+ .namedBindings;
34
+ const alreadyImported = namedImports.elements.find((element) => element.name.escapedText === name) !== undefined;
35
+ if (!alreadyImported) {
36
+ const index = namedImports.getEnd() - 1;
37
+ let text;
38
+ if (namedImports.elements.hasTrailingComma) {
39
+ text = `${name},`;
40
+ }
41
+ else {
42
+ text = `,${name}`;
43
+ }
44
+ const newContents = (0, devkit_1.applyChangesToString)(contents, [
45
+ {
46
+ type: devkit_1.ChangeType.Insert,
47
+ index,
48
+ text,
49
+ },
50
+ ]);
51
+ tree.write(path, newContents);
52
+ }
53
+ }
54
+ exports.insertImport = insertImport;
55
+ //# sourceMappingURL=insert-import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert-import.js","sourceRoot":"","sources":["../../../../../packages/remix/src/utils/insert-import.ts"],"names":[],"mappings":";;;AAAA,qFAA+E;AAC/E,yCAAsE;AACtE,2CAOoB;AAEpB,SAAgB,YAAY,CAC1B,IAAU,EACV,IAAY,EACZ,IAAY,EACZ,UAAkB,EAClB,UAAiC,EAAE,QAAQ,EAAE,KAAK,EAAE;IAEpD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACpB,MAAM,KAAK,CACT,2BAA2B,IAAI,SAAS,UAAU,OAAO,IAAI,kBAAkB,CAChF,CAAC;IAEJ,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE1C,MAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,IAAI,EAAE,QAAQ,EAAE,yBAAY,CAAC,MAAM,CAAC,CAAC;IAEzE,IAAI,gBAAgB,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,gCAAmB,CAAC,CAAC;IAEzE,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CACvC,CAAC;KACH;SAAM;QACL,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CACxC,CAAC;KACH;IAED,MAAM,cAAc,GAAG,gBAAgB,CAAC,IAAI,CAC1C,CAAC,SAAS,EAAE,EAAE,CACZ,IAAA,4BAAe,EAAC,SAAS,CAAC,eAAe,CAAC;QAC1C,SAAS,CAAC,eAAe;aACtB,OAAO,CAAC,UAAU,CAAC;aACnB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;aACrB,IAAI,EAAE,KAAK,UAAU;QACxB,SAAS,CAAC,YAAY,CAAC,aAAa;QACpC,IAAA,2BAAc,EAAC,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC,CACvD,CAAC;IAEF,IAAI,CAAC,cAAc,EAAE;QACnB,IAAA,4DAA2B,EACzB,IAAI,EACJ,IAAI,EACJ,OAAO,CAAC,QAAQ;YACd,CAAC,CAAC,iBAAiB,IAAI,YAAY,UAAU,IAAI;YACjD,CAAC,CAAC,YAAY,IAAI,YAAY,UAAU,IAAI,CAC/C,CAAC;QACF,OAAO;KACR;IAED,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY;SAC7C,aAA6B,CAAC;IAEjC,MAAM,eAAe,GACnB,YAAY,CAAC,QAAQ,CAAC,IAAI,CACxB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,CAC/C,KAAK,SAAS,CAAC;IAElB,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAExC,IAAI,IAAY,CAAC;QACjB,IAAI,YAAY,CAAC,QAAQ,CAAC,gBAAgB,EAAE;YAC1C,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC;SACnB;aAAM;YACL,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;SACnB;QAED,MAAM,WAAW,GAAG,IAAA,6BAAoB,EAAC,QAAQ,EAAE;YACjD;gBACE,IAAI,EAAE,mBAAU,CAAC,MAAM;gBACvB,KAAK;gBACL,IAAI;aACL;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;KAC/B;AACH,CAAC;AA9ED,oCA8EC"}
@@ -0,0 +1,5 @@
1
+ import { Tree } from '@nrwl/devkit';
2
+ /**
3
+ * Insert a statement after the last import statement in a file
4
+ */
5
+ export declare function insertStatementAfterImports(tree: Tree, path: string, statement: string): void;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.insertStatementAfterImports = void 0;
4
+ const devkit_1 = require("@nrwl/devkit");
5
+ const typescript_1 = require("typescript");
6
+ /**
7
+ * Insert a statement after the last import statement in a file
8
+ */
9
+ function insertStatementAfterImports(tree, path, statement) {
10
+ const contents = tree.read(path, 'utf-8');
11
+ const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext);
12
+ const importStatements = sourceFile.statements.filter(typescript_1.isImportDeclaration);
13
+ const index = importStatements.length > 0
14
+ ? importStatements[importStatements.length - 1].getEnd()
15
+ : 0;
16
+ if (importStatements.length > 0) {
17
+ statement = `\n${statement}`;
18
+ }
19
+ const newContents = (0, devkit_1.applyChangesToString)(contents, [
20
+ {
21
+ type: devkit_1.ChangeType.Insert,
22
+ index,
23
+ text: statement,
24
+ },
25
+ ]);
26
+ tree.write(path, newContents);
27
+ }
28
+ exports.insertStatementAfterImports = insertStatementAfterImports;
29
+ //# sourceMappingURL=insert-statement-after-imports.js.map