create-arui-scripts-app 1.0.0 → 1.2.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 (34) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +15 -3
  3. package/assets/.yarn/releases/yarn-4.9.1.cjs +0 -0
  4. package/build/build-context.js +20 -0
  5. package/build/build-file-map.js +29 -2
  6. package/build/create-program.js +18 -0
  7. package/build/defaults.d.ts +4 -1
  8. package/build/defaults.js +8 -2
  9. package/build/install-dependencies.d.ts +2 -0
  10. package/build/install-dependencies.js +18 -5
  11. package/build/questions.js +31 -0
  12. package/build/run.js +40 -0
  13. package/build/templates/app-component.template.js +20 -7
  14. package/build/templates/app-styles.template.js +43 -12
  15. package/build/templates/arui-scripts-config.template.js +2 -2
  16. package/build/templates/client-entry.template.js +28 -18
  17. package/build/templates/e2e-cypress.template.d.ts +5 -0
  18. package/build/templates/e2e-cypress.template.js +52 -0
  19. package/build/templates/e2e-playwright.template.d.ts +4 -0
  20. package/build/templates/e2e-playwright.template.js +56 -0
  21. package/build/templates/lint.template.d.ts +4 -0
  22. package/build/templates/lint.template.js +52 -0
  23. package/build/templates/misc.template.d.ts +1 -1
  24. package/build/templates/misc.template.js +62 -5
  25. package/build/templates/package-json.template.js +26 -0
  26. package/build/templates/router.template.d.ts +5 -0
  27. package/build/templates/router.template.js +159 -0
  28. package/build/templates/server-entry.template.js +37 -41
  29. package/build/templates/store.template.js +1 -1
  30. package/build/templates/tsconfig.template.js +9 -9
  31. package/build/types.d.ts +7 -0
  32. package/build/versions.d.ts +1 -1
  33. package/build/versions.js +1 -1
  34. package/package.json +55 -55
@@ -3,64 +3,60 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serverEntryTemplate = serverEntryTemplate;
4
4
  function serverEntryTemplate(ctx) {
5
5
  const reduxImport = ctx.useRtk ? "\nimport { Provider } from 'react-redux';" : '';
6
+ const routerImport = ctx.useRouter ? "\nimport { StaticRouter } from 'react-router';" : '';
6
7
  const storeImport = ctx.useRtk ? "\nimport { makeStore } from '../client/store';" : '';
7
8
  const renderPageFn = ctx.useRtk
8
9
  ? `function renderPage(appHtml: string, assets: Assets, preloadedState: string): string {
9
- const css = assets.css
10
- .map((href) => '<link rel="stylesheet" href="/' + href + '" />')
11
- .join('');
12
- const js = assets.js.map((src) => '<script src="/' + src + '"></script>').join('');
13
- const state = '<script>window.__PRELOADED_STATE__ = ' + preloadedState + ';</script>';
10
+ const css = assets.css.map((href) => \`<link rel="stylesheet" href="/\${href}" />\`).join('');
11
+ const js = assets.js.map((src) => \`<script src="/\${src}"></script>\`).join('');
12
+ const state = \`<script>window.__PRELOADED_STATE__ = \${preloadedState};</script>\`;
14
13
 
15
- return (
16
- '<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8" /><base href="/" />' +
17
- css +
18
- '</head><body><div id="react-app">' +
19
- appHtml +
20
- '</div>' +
21
- state +
22
- js +
23
- '</body></html>'
24
- );
14
+ return \`<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8" /><base href="/" />\${css}</head><body><div id="react-app">\${appHtml}</div>\${state}\${js}</body></html>\`;
25
15
  }`
26
16
  : `function renderPage(appHtml: string, assets: Assets): string {
27
- const css = assets.css
28
- .map((href) => '<link rel="stylesheet" href="/' + href + '" />')
29
- .join('');
30
- const js = assets.js.map((src) => '<script src="/' + src + '"></script>').join('');
17
+ const css = assets.css.map((href) => \`<link rel="stylesheet" href="/\${href}" />\`).join('');
18
+ const js = assets.js.map((src) => \`<script src="/\${src}"></script>\`).join('');
31
19
 
32
- return (
33
- '<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8" /><base href="/" />' +
34
- css +
35
- '</head><body><div id="react-app">' +
36
- appHtml +
37
- '</div>' +
38
- js +
39
- '</body></html>'
40
- );
20
+ return \`<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8" /><base href="/" />\${css}</head><body><div id="react-app">\${appHtml}</div>\${js}</body></html>\`;
41
21
  }`;
22
+ const appJsx = (() => {
23
+ let inner = '<App />';
24
+ if (ctx.useRtk) {
25
+ inner = `<Provider store={store}>
26
+ ${inner}
27
+ </Provider>`;
28
+ }
29
+ if (ctx.useRouter) {
30
+ inner = `<StaticRouter location={location}>
31
+ ${inner}
32
+ </StaticRouter>`;
33
+ }
34
+ return inner;
35
+ })();
42
36
  const handlerBody = ctx.useRtk
43
37
  ? ` const assets = await readAssetsManifest();
44
38
  const store = makeStore();
45
39
  const appHtml = renderToString(
46
- <Provider store={store}>
47
- <App />
48
- </Provider>,
40
+ ${appJsx},
49
41
  );
50
42
  // Экранируем символ "<", чтобы через состояние нельзя было внедрить теги в HTML
51
43
  const preloadedState = JSON.stringify(store.getState()).replace(/</g, '\\\\u003c');
52
44
 
53
45
  return renderPage(appHtml, assets, preloadedState);`
54
46
  : ` const assets = await readAssetsManifest();
55
- const appHtml = renderToString(<App />);
47
+ const appHtml = renderToString(${appJsx});
56
48
 
57
49
  return renderPage(appHtml, assets);`;
58
- return `import path from 'path';
59
-
50
+ const routePath = ctx.useRouter ? '/{path*}' : '/';
51
+ const locationLine = ctx.useRouter
52
+ ? `
53
+ const location = request.url.pathname;`
54
+ : '';
55
+ return `import React from 'react';
56
+ import { renderToString } from 'react-dom/server';${reduxImport}${routerImport}
60
57
  import Hapi from '@hapi/hapi';
61
58
  import Inert from '@hapi/inert';
62
- import React from 'react';
63
- import { renderToString } from 'react-dom/server';${reduxImport}
59
+ import path from 'node:path';
64
60
 
65
61
  import { readAssetsManifest } from '@alfalab/scripts-server';
66
62
 
@@ -99,17 +95,17 @@ async function start() {
99
95
 
100
96
  server.route({
101
97
  method: 'GET',
102
- path: '/',
103
- handler: async () => {
98
+ path: '${routePath}',
99
+ handler: async (${ctx.useRouter ? 'request' : ''}) => {${locationLine}
104
100
  ${handlerBody}
105
101
  },
106
102
  });
107
103
 
108
104
  await server.start();
109
- // eslint-disable-next-line no-console
110
- console.log('Server is listening on ' + server.info.uri);
105
+ // eslint-disable-next-line no-console -- стартовый лог dev-сервера
106
+ console.log(\`Server is listening on \${server.info.uri}\`);
111
107
  }
112
108
 
113
- start();
109
+ void start();
114
110
  `;
115
111
  }
@@ -57,7 +57,7 @@ const counterSlice = createSlice({
57
57
  },
58
58
  });
59
59
 
60
- export const { increment, decrement } = counterSlice.actions;
60
+ export const { decrement, increment } = counterSlice.actions;
61
61
  export const counterReducer = counterSlice.reducer;
62
62
  `;
63
63
  }
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsconfigTemplate = tsconfigTemplate;
4
4
  function tsconfigTemplate(ctx) {
5
- const types = ctx.testRunner === 'jest' ? ['jest', 'node', 'webpack-env'] : ['node', 'webpack-env'];
6
- const tsconfig = {
7
- extends: 'arui-scripts/tsconfig.json',
8
- include: ['global-definitions.d.ts', 'src/**/*.ts', 'src/**/*.tsx'],
9
- compilerOptions: {
10
- types,
11
- },
12
- };
13
- return `${JSON.stringify(tsconfig, null, 4)}\n`;
5
+ const types = ctx.testRunner === 'jest' ? '["jest", "node", "webpack-env"]' : '["node", "webpack-env"]';
6
+ return `{
7
+ "extends": "arui-scripts/tsconfig.json",
8
+ "include": ["global-definitions.d.ts", "src/**/*.ts", "src/**/*.tsx"],
9
+ "compilerOptions": {
10
+ "types": ${types}
11
+ }
12
+ }
13
+ `;
14
14
  }
package/build/types.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  export type CodeLoader = 'swc' | 'babel' | 'tsc';
2
2
  export type TestRunner = 'jest' | 'vitest';
3
+ export type E2eFramework = 'cypress' | 'playwright' | 'none';
3
4
  export type InitAnswers = {
4
5
  name: string;
5
6
  useRtk: boolean;
6
7
  clientOnly: boolean;
7
8
  codeLoader: CodeLoader;
8
9
  testRunner: TestRunner;
10
+ e2eFramework: E2eFramework;
11
+ useRouter: boolean;
9
12
  cssModules: boolean;
10
13
  clientServerPort: number;
11
14
  serverPort: number;
@@ -13,6 +16,7 @@ export type InitAnswers = {
13
16
  presets: string;
14
17
  polyfills: boolean;
15
18
  reactCompiler: boolean;
19
+ useLint: boolean;
16
20
  install: boolean;
17
21
  };
18
22
  export type TemplateContext = {
@@ -21,6 +25,8 @@ export type TemplateContext = {
21
25
  clientOnly: boolean;
22
26
  codeLoader: CodeLoader;
23
27
  testRunner: TestRunner;
28
+ e2eFramework: E2eFramework;
29
+ useRouter: boolean;
24
30
  cssModules: boolean;
25
31
  clientServerPort: number;
26
32
  serverPort: number;
@@ -28,6 +34,7 @@ export type TemplateContext = {
28
34
  presets: string;
29
35
  polyfills: boolean;
30
36
  reactCompiler: boolean;
37
+ useLint: boolean;
31
38
  aruiScriptsVersion: string;
32
39
  dependencies: Record<string, string>;
33
40
  devDependencies: Record<string, string>;
@@ -1,4 +1,4 @@
1
1
  /** Версия arui-scripts, которую scaffold кладёт в package.json нового проекта.
2
2
  * Генерируется скриптом scripts/sync-arui-scripts-version.js при сборке.
3
3
  */
4
- export declare const DEFAULT_ARUI_SCRIPTS_VERSION = "23.2.0";
4
+ export declare const DEFAULT_ARUI_SCRIPTS_VERSION = "23.5.1";
package/build/versions.js CHANGED
@@ -4,4 +4,4 @@ exports.DEFAULT_ARUI_SCRIPTS_VERSION = void 0;
4
4
  /** Версия arui-scripts, которую scaffold кладёт в package.json нового проекта.
5
5
  * Генерируется скриптом scripts/sync-arui-scripts-version.js при сборке.
6
6
  */
7
- exports.DEFAULT_ARUI_SCRIPTS_VERSION = '23.2.0';
7
+ exports.DEFAULT_ARUI_SCRIPTS_VERSION = '23.5.1';
package/package.json CHANGED
@@ -1,56 +1,56 @@
1
1
  {
2
- "name": "create-arui-scripts-app",
3
- "version": "1.0.0",
4
- "description": "CLI для генерации нового react приложения на arui-scripts",
5
- "license": "MPL-2.0",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/core-ds/arui-scripts.git"
9
- },
10
- "bugs": {
11
- "url": "https://github.com/core-ds/arui-scripts/issues"
12
- },
13
- "homepage": "https://github.com/core-ds/arui-scripts/tree/master/packages/create-arui-scripts-app#readme",
14
- "bin": "./bin/create-arui-scripts-app.js",
15
- "main": "./build/run.js",
16
- "typings": "./build/run.d.ts",
17
- "files": [
18
- "assets",
19
- "bin",
20
- "build"
21
- ],
22
- "scripts": {
23
- "sync:version": "node ./scripts/sync-arui-scripts-version.js",
24
- "build": "yarn sync:version && tsc --project tsconfig.json",
25
- "test": "jest",
26
- "lint:scripts": "arui-presets-lint scripts",
27
- "format": "arui-presets-lint format",
28
- "format:check": "arui-presets-lint format:check",
29
- "lint": "yarn lint:scripts && yarn format:check",
30
- "lint:fix": "yarn lint:scripts --fix && yarn format",
31
- "audit": "yarn npm audit --severity high --environment production"
32
- },
33
- "dependencies": {
34
- "chalk": "^2.4.2",
35
- "commander": "^12",
36
- "fs-extra": "6.0.1",
37
- "ora": "^5",
38
- "prompts": "^2.4.2",
39
- "shelljs": "0.8.5",
40
- "validate-npm-package-name": "^5.0.1"
41
- },
42
- "devDependencies": {
43
- "@types/fs-extra": "^9.0.13",
44
- "@types/jest": "^29.5.14",
45
- "@types/node": "^20.19.0",
46
- "@types/prompts": "^2.4.9",
47
- "@types/shelljs": "^0.8.12",
48
- "@types/validate-npm-package-name": "^3.0.3",
49
- "jest": "28.1.3",
50
- "ts-jest": "28.0.8",
51
- "typescript": "6.0.2"
52
- },
53
- "engines": {
54
- "node": "^20.19.0 || >=22.12.0"
55
- }
56
- }
2
+ "name": "create-arui-scripts-app",
3
+ "version": "1.2.0",
4
+ "description": "CLI для генерации нового react приложения на arui-scripts",
5
+ "license": "MPL-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/core-ds/arui-scripts.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/core-ds/arui-scripts/issues"
12
+ },
13
+ "homepage": "https://github.com/core-ds/arui-scripts/tree/master/packages/create-arui-scripts-app#readme",
14
+ "bin": "./bin/create-arui-scripts-app.js",
15
+ "main": "./build/run.js",
16
+ "typings": "./build/run.d.ts",
17
+ "files": [
18
+ "assets",
19
+ "bin",
20
+ "build"
21
+ ],
22
+ "scripts": {
23
+ "sync:version": "node ./scripts/sync-arui-scripts-version.js",
24
+ "build": "yarn sync:version && tsc --project tsconfig.json",
25
+ "test": "jest",
26
+ "lint:scripts": "arui-presets-lint scripts",
27
+ "format": "arui-presets-lint format",
28
+ "format:check": "arui-presets-lint format:check",
29
+ "lint": "yarn lint:scripts && yarn format:check",
30
+ "lint:fix": "yarn lint:scripts --fix && yarn format",
31
+ "audit": "yarn npm audit --severity high --environment production"
32
+ },
33
+ "dependencies": {
34
+ "chalk": "^2.4.2",
35
+ "commander": "^12",
36
+ "fs-extra": "6.0.1",
37
+ "ora": "^5",
38
+ "prompts": "^2.4.2",
39
+ "shelljs": "0.8.5",
40
+ "validate-npm-package-name": "^5.0.1"
41
+ },
42
+ "devDependencies": {
43
+ "@types/fs-extra": "^9.0.13",
44
+ "@types/jest": "^29.5.14",
45
+ "@types/node": "^20.19.0",
46
+ "@types/prompts": "^2.4.9",
47
+ "@types/shelljs": "^0.8.12",
48
+ "@types/validate-npm-package-name": "^3.0.3",
49
+ "jest": "28.1.3",
50
+ "ts-jest": "28.0.8",
51
+ "typescript": "6.0.2"
52
+ },
53
+ "engines": {
54
+ "node": "^20.19.0 || >=22.12.0"
55
+ }
56
+ }