|
8 | 8 | import { |
9 | 9 | renameCommonFiles, |
10 | 10 | renamePlaceholder, |
11 | | - rewritePackageJson, |
| 11 | + sortDevDepsInPackageJson, |
12 | 12 | } from './edit-template.js'; |
13 | 13 | import { copyDirSync, isEmptyDirSync, removeDir } from './fs.js'; |
14 | 14 | import { printLogo } from './logo.js'; |
@@ -92,10 +92,10 @@ export async function run() { |
92 | 92 |
|
93 | 93 | const loader = spinner(); |
94 | 94 | loader.start('Updating template...'); |
95 | | - rewritePackageJson(absoluteTargetDir, projectName, platforms); |
| 95 | + sortDevDepsInPackageJson(absoluteTargetDir); |
96 | 96 | renameCommonFiles(absoluteTargetDir); |
97 | 97 | renamePlaceholder(absoluteTargetDir, projectName); |
98 | | - createConfig(absoluteTargetDir, platforms); |
| 98 | + createConfig(absoluteTargetDir, platforms, plugins); |
99 | 99 | loader.stop('Updated template.'); |
100 | 100 |
|
101 | 101 | printByeMessage(absoluteTargetDir); |
@@ -160,25 +160,37 @@ async function extractPackage(absoluteTargetDir: string, pkg: TemplateInfo) { |
160 | 160 | ); |
161 | 161 | } |
162 | 162 |
|
163 | | -function createConfig(absoluteTargetDir: string, platforms: TemplateInfo[]) { |
| 163 | +function createConfig( |
| 164 | + absoluteTargetDir: string, |
| 165 | + platforms: TemplateInfo[], |
| 166 | + plugins: TemplateInfo[] |
| 167 | +) { |
164 | 168 | const rnefConfig = path.join(absoluteTargetDir, 'rnef.config.mjs'); |
165 | | - fs.writeFileSync(rnefConfig, formatConfig(platforms)); |
| 169 | + fs.writeFileSync(rnefConfig, formatConfig(platforms, plugins)); |
166 | 170 | } |
167 | 171 |
|
168 | | -export function formatConfig(platforms: TemplateInfo[]) { |
| 172 | +export function formatConfig( |
| 173 | + platforms: TemplateInfo[], |
| 174 | + plugins: TemplateInfo[] |
| 175 | +) { |
169 | 176 | const platformsWithImports = platforms.filter( |
170 | 177 | (template) => template.importName |
171 | 178 | ); |
| 179 | + const pluginsWithImports = plugins.filter((template) => template.importName); |
172 | 180 |
|
173 | | - return `${platformsWithImports |
| 181 | + return `${[...platformsWithImports, ...pluginsWithImports] |
174 | 182 | .map( |
175 | 183 | (template) => |
176 | 184 | `import { ${template.importName} } from '${template.packageName}';` |
177 | 185 | ) |
178 | 186 | .join('\n')} |
179 | 187 |
|
180 | 188 | export default { |
181 | | - plugins: {}, |
| 189 | + plugins: { |
| 190 | + ${pluginsWithImports |
| 191 | + .map((template) => `${template.name}: ${template.importName}(),`) |
| 192 | + .join('\n ')} |
| 193 | + }, |
182 | 194 | platforms: { |
183 | 195 | ${platformsWithImports |
184 | 196 | .map((template) => `${template.name}: ${template.importName}(),`) |
|
0 commit comments