@ronas-it/nx-generators 0.3.8 → 0.4.1

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/README.md CHANGED
@@ -7,7 +7,11 @@ NX generators for Ronas IT projects.
7
7
  1. Create monorepo with Expo app using [NX Expo preset](https://nx.dev/nx-api/expo) or with Next.js app using [NX Next preset](https://nx.dev/nx-api/next):
8
8
 
9
9
  ```sh
10
+ # For Expo app:
10
11
  npx create-nx-workspace@latest my-project --preset=expo --appName=my-app --e2eTestRunner=none --ci=skip
12
+
13
+ # For Next.js app:
14
+ npx create-nx-workspace@latest my-project --preset=next --appName=my-app --nextAppDir=true --nextSrcDir=false --style=scss --e2eTestRunner=none --ci=skip
11
15
  ```
12
16
 
13
17
  2. Install this package:
@@ -21,13 +25,22 @@ npm i @ronas-it/nx-generators --save-dev
21
25
  ```sh
22
26
  npx nx g repo-config
23
27
  npx nx g code-checks
24
- npx nx g expo-app // for Expo app
28
+
29
+ # For Expo app:
30
+ npx nx g expo-app
31
+
32
+ # For Next.js app:
33
+ npx nx g next-app
25
34
  ```
26
35
 
27
36
  Or run all generators at once:
28
37
 
29
38
  ```sh
39
+ # For Expo app:
30
40
  npx nx g repo-config && npx nx g code-checks && npx nx g expo-app
41
+
42
+ # For Next.js app:
43
+ npx nx g repo-config && npx nx g code-checks && npx nx g next-app
31
44
  ```
32
45
 
33
46
  4. Start the app:
@@ -55,15 +68,15 @@ Configures code checks and formatting with pre-commit hook.
55
68
 
56
69
  ### 3. `expo-app`
57
70
 
58
- Generates and configures Expo React Native app.
71
+ Generates and configures an Expo React Native app.
59
72
 
60
- ### Options
73
+ #### Options
61
74
 
62
- 1. `name` (optional) - name of the app for `app.config.ts` (e.g: my-app)
75
+ 1. `name` (optional) - name of the app for `app.config.ts` (e.g: `my-app`)
63
76
 
64
- 2. `directory` (optional) - name of the directory in the `apps/` folder (e.g: mobile)
77
+ 2. `directory` (optional) - name of the directory in the `apps/` folder (e.g: `mobile`)
65
78
 
66
- ### Example
79
+ #### Example
67
80
 
68
81
  ```sh
69
82
  npx nx g expo-app --name=my-app --directory=mobile
@@ -73,11 +86,31 @@ or
73
86
  npx nx g expo-app my-app mobile
74
87
  ```
75
88
 
76
- ### 4. `react-lib`
89
+ ### 4. `next-app`
90
+
91
+ Generates and configures a Next.js app.
92
+
93
+ #### Options
94
+
95
+ 1. `name` (optional) - name of the app (e.g: `my-app`)
96
+
97
+ 2. `directory` (optional) - name of the directory in the `apps/` folder (e.g: `web`)
98
+
99
+ #### Example
100
+
101
+ ```sh
102
+ npx nx g next-app --name=my-app --directory=web
103
+ ```
104
+ or
105
+ ```sh
106
+ npx nx g next-app my-app web
107
+ ```
108
+
109
+ ### 5. `react-lib`
77
110
 
78
111
  Generates a library according to [NX notation](https://nx.dev/concepts/more-concepts/applications-and-libraries).
79
112
 
80
- ### Options
113
+ #### Options
81
114
 
82
115
  1. `directory` (optional) - directory for the library (e.g. mobile/account/features/profile-settings)
83
116
 
@@ -85,7 +118,7 @@ Generates a library according to [NX notation](https://nx.dev/concepts/more-conc
85
118
 
86
119
  3. `dryRun` (optional) - generate the library without creating files
87
120
 
88
- ### Example
121
+ #### Example
89
122
 
90
123
  ```sh
91
124
  npx nx g react-lib --directory=mobile/account/features/profile-settings --withComponent --dryRun
@@ -95,17 +128,17 @@ or
95
128
  npx nx g react-lib mobile/account/features/profile-settings --withComponent --dryRun
96
129
  ```
97
130
 
98
- ### 5. `react-component`
131
+ ### 6. `react-component`
99
132
 
100
133
  Creates a React component in particular library.
101
134
 
102
- ### Options
135
+ #### Options
103
136
 
104
137
  1. `name` (optional) - name of the component (e.g. AppButton)
105
138
 
106
139
  2. `subcomponent` (optional) - generate a folder for components
107
140
 
108
- ### Example
141
+ #### Example
109
142
 
110
143
  ```sh
111
144
  npx nx g react-component --name=AppButton --subcomponent
package/generators.json CHANGED
@@ -10,6 +10,11 @@
10
10
  "schema": "./src/generators/expo-app/schema.json",
11
11
  "description": "expo-app generator"
12
12
  },
13
+ "next-app": {
14
+ "factory": "./src/generators/next-app/generator",
15
+ "schema": "./src/generators/next-app/schema.json",
16
+ "description": "next-app generator"
17
+ },
13
18
  "repo-config": {
14
19
  "factory": "./src/generators/repo-config/generator",
15
20
  "schema": "./src/generators/repo-config/schema.json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronas-it/nx-generators",
3
- "version": "0.3.8",
3
+ "version": "0.4.1",
4
4
  "description": "NX generators for Ronas IT projects",
5
5
  "license": "MIT",
6
6
  "author": "Ronas IT",
@@ -0,0 +1 @@
1
+ NEXT_PUBLIC_APP_ENV=development
@@ -0,0 +1 @@
1
+ NEXT_PUBLIC_APP_ENV=production
@@ -0,0 +1 @@
1
+ NEXT_PUBLIC_APP_ENV=development
@@ -0,0 +1,39 @@
1
+ # <%= formatName(name) %> - Next.js app
2
+
3
+ This is a web app built with Next.js.
4
+
5
+ ## Tasks overview
6
+
7
+ You can run tasks for this project with:
8
+
9
+ ```sh
10
+ npx nx <task-name> <%= name %>
11
+ ```
12
+
13
+ To view the list of available tasks, run:
14
+
15
+ ```sh
16
+ npx nx show project <%= name %> --web
17
+ ```
18
+
19
+ The following tasks are included by default:
20
+
21
+ - `dev` – Start the local development server.
22
+ - `build` – Create a production build.
23
+ - `start` – Create and start a production build.
24
+ - `lint` – Check the source code with `eslint`.
25
+
26
+ ## Development
27
+
28
+ To run this application locally, follow these steps:
29
+
30
+ ```sh
31
+ # 1. Navigate to Nx workspace directory containing this app
32
+ cd <path-to-nx-workspace>
33
+
34
+ # 2. Install dependencies
35
+ npm install
36
+
37
+ # 3. Start the local development server
38
+ npx nx dev <%= name %>
39
+ ```
@@ -0,0 +1,48 @@
1
+ import { constants, Locale } from '../../constants';
2
+ import { notFound } from 'next/navigation';
3
+ import { unstable_setRequestLocale } from 'next-intl/server';
4
+ import { ReactElement, ReactNode } from 'react';
5
+ import { Providers } from './providers';
6
+
7
+ export const metadata = {
8
+ title: '<%= formatName(name) %>',
9
+ };
10
+
11
+ export interface RootLayoutProps {
12
+ children: ReactNode;
13
+ params: { locale: Locale };
14
+ }
15
+
16
+ const locales = constants.locales;
17
+
18
+ export const generateStaticParams = (): Array<{ locale: Locale }> =>
19
+ locales.map((locale) => ({ locale }));
20
+
21
+ export default function RootLayout({
22
+ children,
23
+ params: { locale },
24
+ }: RootLayoutProps): ReactElement {
25
+ if (!locales.includes(locale)) {
26
+ notFound();
27
+ }
28
+
29
+ unstable_setRequestLocale(locale);
30
+
31
+ return (
32
+ <html lang={locale}>
33
+ <head>
34
+ <meta
35
+ name="robots"
36
+ content={
37
+ process.env.NEXT_PUBLIC_APP_ENV === 'production'
38
+ ? 'index'
39
+ : 'noindex'
40
+ }
41
+ />
42
+ </head>
43
+ <body>
44
+ <Providers>{children}</Providers>
45
+ </body>
46
+ </html>
47
+ );
48
+ }
@@ -0,0 +1,18 @@
1
+ import { ReactElement } from 'react';
2
+ import { Locale } from '../../constants';
3
+ import { unstable_setRequestLocale } from 'next-intl/server';
4
+ import { useTranslations } from 'next-intl';
5
+
6
+ export interface IndexPageProps {
7
+ params: { locale: Locale };
8
+ }
9
+
10
+ export default function Index({
11
+ params: { locale },
12
+ }: IndexPageProps): ReactElement {
13
+ unstable_setRequestLocale(locale);
14
+
15
+ const t = useTranslations('HOME_PAGE');
16
+
17
+ return <div>{t('HOME_PAGE_TEXT')}</div>;
18
+ }
@@ -0,0 +1,16 @@
1
+ import { ReactElement } from 'react';
2
+ import { NextIntlClientProvider, useMessages } from 'next-intl';
3
+
4
+ export function Providers({
5
+ children,
6
+ }: {
7
+ children: React.ReactNode;
8
+ }): ReactElement {
9
+ const messages = useMessages();
10
+
11
+ return (
12
+ <NextIntlClientProvider messages={messages}>
13
+ {children}
14
+ </NextIntlClientProvider>
15
+ );
16
+ }
@@ -0,0 +1,11 @@
1
+ export type Locale = 'en';
2
+
3
+ interface Constants {
4
+ defaultLocale: Locale;
5
+ locales: Array<Locale>;
6
+ }
7
+
8
+ export const constants: Constants = {
9
+ defaultLocale: 'en',
10
+ locales: ['en'],
11
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "HOME_PAGE": {
3
+ "HOME_PAGE_TEXT": "<%= formatName(name) %> home page"
4
+ }
5
+ }
@@ -0,0 +1,13 @@
1
+ import { notFound } from 'next/navigation';
2
+ import { getRequestConfig } from 'next-intl/server';
3
+ import { constants, Locale } from './constants';
4
+
5
+ export default getRequestConfig(async ({ locale }) => {
6
+ if (!constants.locales.includes(locale as Locale)) {
7
+ notFound();
8
+ }
9
+
10
+ return {
11
+ messages: (await import(`./i18n/${locale}.json`)).default,
12
+ };
13
+ });
@@ -0,0 +1,12 @@
1
+ import { constants } from './constants';
2
+ import createMiddleware from 'next-intl/middleware';
3
+
4
+ export default createMiddleware({
5
+ locales: constants.locales,
6
+ defaultLocale: constants.defaultLocale,
7
+ localePrefix: 'never',
8
+ });
9
+
10
+ export const config = {
11
+ matcher: ['/((?!api|_next|.*\\..*).*)'],
12
+ };
@@ -0,0 +1,19 @@
1
+ const { withNx } = require('@nrwl/next/plugins/with-nx');
2
+ const withNextIntl = require('next-intl/plugin')();
3
+
4
+ /**
5
+ * @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
6
+ **/
7
+ const nextConfig = {
8
+ nx: {
9
+ // Set this to true if you would like to use SVGR
10
+ // See: https://github.com/gregberge/svgr
11
+ svgr: false,
12
+ },
13
+ output: 'standalone',
14
+ async redirects() {
15
+ return [];
16
+ },
17
+ };
18
+
19
+ module.exports = withNx(withNextIntl(nextConfig));
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NextAppGeneratorSchema } from './schema';
3
+ export declare function nextAppGenerator(tree: Tree, options: NextAppGeneratorSchema): Promise<() => void>;
4
+ export default nextAppGenerator;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nextAppGenerator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const child_process_1 = require("child_process");
6
+ const devkit_1 = require("@nx/devkit");
7
+ const fs_1 = require("fs");
8
+ const utils_1 = require("../../shared/utils");
9
+ const path = require("path");
10
+ const dependencies = {
11
+ 'next-intl': '^3.17.2',
12
+ };
13
+ function nextAppGenerator(tree, options) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ const appRoot = `apps/${options.directory}`;
16
+ // Install @nx/next plugin
17
+ (0, child_process_1.execSync)('npx nx add @nx/next', { stdio: 'inherit' });
18
+ if (!(0, fs_1.existsSync)(appRoot)) {
19
+ (0, child_process_1.execSync)(`npx nx g @nx/next:app ${options.name} --directory=apps/${options.directory} --projectNameAndRootFormat=as-provided --appDir=true --style=scss --src=false --unitTestRunner=none --e2eTestRunner=none`, { stdio: 'inherit' });
20
+ }
21
+ // Remove unnecessary files and files that will be replaced
22
+ tree.delete(`${appRoot}/public/.gitkeep`);
23
+ tree.delete(`${appRoot}/app/api`);
24
+ tree.delete(`${appRoot}/app/page.tsx`);
25
+ tree.delete(`${appRoot}/app/page.module.scss`);
26
+ tree.delete(`${appRoot}/app/global.css`);
27
+ tree.delete(`${appRoot}/app/layout.tsx`);
28
+ tree.delete(`${appRoot}/.eslintrc.json`);
29
+ // Update app tsconfig.json to skip automatic reconfiguration during the first application run
30
+ const appTsconfigPath = `${appRoot}/tsconfig.json`;
31
+ const appTsconfigJson = (0, devkit_1.readJson)(tree, appTsconfigPath);
32
+ const nextTypesInclude = '.next/types/**/*.ts';
33
+ if (!appTsconfigJson.include.includes(nextTypesInclude)) {
34
+ appTsconfigJson.include.push(nextTypesInclude);
35
+ (0, devkit_1.writeJson)(tree, appTsconfigPath, appTsconfigJson);
36
+ }
37
+ // Add app files
38
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), appRoot, Object.assign(Object.assign({}, options), { formatName: utils_1.formatName }));
39
+ // Add dependencies
40
+ (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, {});
41
+ yield (0, devkit_1.formatFiles)(tree);
42
+ return () => {
43
+ (0, devkit_1.installPackagesTask)(tree);
44
+ };
45
+ });
46
+ }
47
+ exports.nextAppGenerator = nextAppGenerator;
48
+ exports.default = nextAppGenerator;
49
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/next-app/generator.ts"],"names":[],"mappings":";;;;AAAA,iDAAyC;AACzC,uCAQoB;AAEpB,2BAAgC;AAChC,8CAAgD;AAChD,6BAA6B;AAE7B,MAAM,YAAY,GAAG;IACnB,WAAW,EAAE,SAAS;CACvB,CAAC;AAEF,SAAsB,gBAAgB,CACpC,IAAU,EACV,OAA+B;;QAE/B,MAAM,OAAO,GAAG,QAAQ,OAAO,CAAC,SAAS,EAAE,CAAC;QAE5C,0BAA0B;QAC1B,IAAA,wBAAQ,EAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAEtD,IAAI,CAAC,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE,CAAC;YACzB,IAAA,wBAAQ,EACN,yBAAyB,OAAO,CAAC,IAAI,qBAAqB,OAAO,CAAC,SAAS,2HAA2H,EACtM,EAAE,KAAK,EAAE,SAAS,EAAE,CACrB,CAAC;QACJ,CAAC;QAED,2DAA2D;QAC3D,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,kBAAkB,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,UAAU,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,eAAe,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,uBAAuB,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,iBAAiB,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,iBAAiB,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,iBAAiB,CAAC,CAAC;QAEzC,8FAA8F;QAC9F,MAAM,eAAe,GAAG,GAAG,OAAO,gBAAgB,CAAC;QACnD,MAAM,eAAe,GAAG,IAAA,iBAAQ,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QACxD,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;QAE/C,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACxD,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAC/C,IAAA,kBAAS,EAAC,IAAI,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;QACpD,CAAC;QAED,gBAAgB;QAChB,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,kCACrD,OAAO,KACV,UAAU,EAAV,kBAAU,IACV,CAAC;QAEH,mBAAmB;QACnB,IAAA,qCAA4B,EAAC,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;QAErD,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QAExB,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC;CAAA;AAjDD,4CAiDC;AAED,kBAAe,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface NextAppGeneratorSchema {
2
+ name: string;
3
+ directory: string;
4
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NextApp",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "Enter the name of the app (e.g: my-app)"
15
+ },
16
+ "directory": {
17
+ "type": "string",
18
+ "description": "",
19
+ "$default": {
20
+ "$source": "argv",
21
+ "index": 1
22
+ },
23
+ "x-prompt": "Enter the name of the directory in the 'apps/' folder (e.g: web)"
24
+ }
25
+ },
26
+ "required": ["name", "directory"]
27
+ }