@ronas-it/nx-generators 0.3.8 → 0.4.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/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.0",
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,C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",
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
+ }