@modern-js/entry-generator 3.6.3 → 3.7.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/package.json CHANGED
@@ -15,29 +15,27 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.6.3",
18
+ "version": "3.7.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "main": "./dist/index.js",
21
21
  "files": [
22
22
  "/templates",
23
23
  "/dist/index.js"
24
24
  ],
25
- "dependencies": {
26
- "@modern-js/utils": "2.60.3"
27
- },
28
25
  "devDependencies": {
29
- "@modern-js/codesmith": "2.5.2",
30
- "@modern-js/codesmith-api-app": "2.5.2",
31
- "@modern-js/codesmith-api-handlebars": "2.5.2",
26
+ "@modern-js/codesmith": "2.6.5",
27
+ "@modern-js/codesmith-utils": "2.6.5",
28
+ "@modern-js/codesmith-api-app": "2.6.5",
29
+ "@modern-js/codesmith-api-handlebars": "2.6.5",
32
30
  "@types/jest": "^29",
33
31
  "@types/node": "^14",
34
32
  "jest": "^29",
35
33
  "typescript": "^5",
36
- "@modern-js/generator-common": "3.6.3",
37
- "@modern-js/generator-utils": "3.6.3",
38
- "@scripts/build": "2.60.3",
39
- "@scripts/jest-config": "2.60.3",
40
- "@modern-js/plugin-i18n": "2.60.3"
34
+ "@modern-js/generator-common": "3.7.1",
35
+ "@modern-js/plugin-i18n": "2.60.5",
36
+ "@scripts/build": "2.60.5",
37
+ "@scripts/jest-config": "2.60.5",
38
+ "@modern-js/generator-utils": "3.7.1"
41
39
  },
42
40
  "sideEffects": false,
43
41
  "publishConfig": {
@@ -64,7 +64,8 @@ main {
64
64
  border-radius: 12px;
65
65
  padding: 0.6rem 0.9rem;
66
66
  font-size: 1.05rem;
67
- font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
67
+ font-family:
68
+ Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
68
69
  Bitstream Vera Sans Mono, Courier New, monospace;
69
70
  }
70
71
 
package/src/index.ts DELETED
@@ -1,141 +0,0 @@
1
- import path from 'path';
2
- import type { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
3
- import { AppAPI } from '@modern-js/codesmith-api-app';
4
- import {
5
- i18n as commonI18n,
6
- getEntrySchema,
7
- } from '@modern-js/generator-common';
8
- import { fs, getPackageObj, isTsProject } from '@modern-js/generator-utils';
9
- import { merge } from '@modern-js/utils/lodash';
10
- import { i18n, localeKeys } from './locale';
11
- import { isEmptySource, isSingleEntry } from './utils';
12
-
13
- const handleInput = async (
14
- context: GeneratorContext,
15
- generator: GeneratorCore,
16
- appApi: AppAPI,
17
- ) => {
18
- const appDir = context.materials.default.basePath;
19
-
20
- const { entriesDir } = context.config;
21
-
22
- await fs.ensureDir(path.join(appDir, entriesDir));
23
-
24
- const analysisInfo = {
25
- isEmptySrc: isEmptySource(appDir, entriesDir),
26
- isSingleEntry: isSingleEntry(appDir, entriesDir),
27
- isTsProject: isTsProject(appDir),
28
- };
29
-
30
- generator.logger.debug(
31
- `💡 [Entry Analysis Info]: ${JSON.stringify(analysisInfo)}`,
32
- );
33
-
34
- const config = { ...context.config, ...analysisInfo };
35
- const ans = await appApi.getInputBySchemaFunc(getEntrySchema, config);
36
-
37
- return ans;
38
- };
39
-
40
- const refactorSingleEntry = async (
41
- context: GeneratorContext,
42
- generator: GeneratorCore,
43
- ) => {
44
- const pkgObj = await getPackageObj(context);
45
- const pkgName = pkgObj.name;
46
-
47
- const { entriesDir } = context.config;
48
-
49
- const oldFilePath = path.join(context.materials.default.basePath, entriesDir);
50
- const oldFiles = fs
51
- .readdirSync(oldFilePath)
52
- .filter(filePath => {
53
- if (fs.statSync(path.join(oldFilePath, filePath)).isDirectory()) {
54
- const files = fs.readdirSync(path.join(oldFilePath, filePath));
55
- return files.length;
56
- }
57
- return (
58
- filePath !== '.eslintrc.json' &&
59
- filePath !== '.eslintrc.js' &&
60
- filePath !== 'modern-app-env.d.ts' &&
61
- filePath !== 'modern.runtime.ts' &&
62
- filePath !== 'modern.runtime.js'
63
- );
64
- })
65
- .map(file =>
66
- path.join(context.materials.default.basePath, entriesDir, file),
67
- );
68
-
69
- // create new dir in entriesDir and move code to that dir
70
- fs.mkdirpSync(
71
- path.join(context.materials.default.basePath, entriesDir, pkgName),
72
- );
73
- oldFiles.forEach(file => {
74
- generator.logger.debug(
75
- `💡 [Rename Entry Info]: from ${file} to ${file.replace(
76
- entriesDir,
77
- path.join(entriesDir, pkgName),
78
- )}`,
79
- );
80
- fs.renameSync(
81
- file,
82
- file.replace(entriesDir, path.join(entriesDir, pkgName)),
83
- );
84
- });
85
- };
86
-
87
- export const handleTemplateFile = async (
88
- context: GeneratorContext,
89
- generator: GeneratorCore,
90
- appApi: AppAPI,
91
- ) => {
92
- const ans = await handleInput(context, generator, appApi);
93
-
94
- if (ans.isSingleEntry) {
95
- generator.logger.debug(
96
- `💡 [Current Entry Info]: Current Entry is Single Entry`,
97
- );
98
- await refactorSingleEntry(context, generator);
99
- }
100
-
101
- const entryName = (ans.name as string) || '';
102
- const fileExtra = ans.isTsProject ? 'tsx' : 'jsx';
103
- const targetPath = path.join(context.config.entriesDir, entryName);
104
-
105
- await appApi.forgeTemplate(`templates/**/*`, undefined, resourceKey =>
106
- resourceKey
107
- .replace('templates', targetPath)
108
- .replace('.handlebars', `.${fileExtra}`),
109
- );
110
- };
111
-
112
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
113
- const appApi = new AppAPI(context, generator);
114
-
115
- const { locale } = context.config;
116
- commonI18n.changeLanguage({ locale });
117
- appApi.i18n.changeLanguage({ locale });
118
- i18n.changeLanguage({ locale });
119
-
120
- if (!(await appApi.checkEnvironment())) {
121
- process.exit(1);
122
- }
123
-
124
- generator.logger.debug(`🚀 [Start Run Entry Generator]`);
125
- generator.logger.debug(
126
- '💡 [Current Config]:',
127
- JSON.stringify(context.config),
128
- );
129
-
130
- merge(context.config, { entriesDir: context.config.entriesDir || 'src' });
131
-
132
- await handleTemplateFile(context, generator, appApi);
133
-
134
- if (!context.config.isEmptySrc) {
135
- appApi.showSuccessInfo(
136
- i18n.t(localeKeys.success, { name: context.config.name }),
137
- );
138
- }
139
-
140
- generator.logger.debug(`🌟 [End Run Entry Generator]`);
141
- };