-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: engine-cli support create platform with params (#626)
* feat: engine-cli support create platform with params * fix: add choices for theme * fix: del unnecessary empty options
- Loading branch information
1 parent
87169b4
commit c715a5a
Showing
8 changed files
with
102 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default { | ||
id: 'engine.config', | ||
theme: import.meta.env.VITE_THEME || 'light', | ||
material: ['/mock/bundle.json'], | ||
scripts: [], | ||
styles: [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
|
||
// 根据参数生成 config 文件内容 | ||
export const generateConfig = (options = {}) => { | ||
const { theme, platformId, material, scripts = [], styles = [] } = options | ||
|
||
const configContent = ` | ||
export default { | ||
id: 'engine.config', | ||
theme: import.meta.env.VITE_THEME || '${theme}', | ||
material: ${JSON.stringify(material)}, | ||
scripts: ${JSON.stringify(scripts)}, | ||
styles: ${JSON.stringify(styles)}, | ||
platformId: ${platformId} | ||
} | ||
` | ||
|
||
return configContent | ||
} | ||
|
||
// 根据参数修改 package.json | ||
export const generatePackageJson = (name, options, templatePath) => { | ||
const templatePackageJson = fs.readJSONSync(path.resolve(templatePath, 'package.json')) | ||
|
||
templatePackageJson.name = name | ||
templatePackageJson.scripts['serve:frontend'] = templatePackageJson.scripts['serve:frontend'].replace( | ||
/VITE_THEME=[^\s]+/, | ||
`VITE_THEME=${options.theme}` | ||
) | ||
templatePackageJson.scripts.build = templatePackageJson.scripts.build.replace( | ||
/VITE_THEME=[^\s]+/, | ||
`VITE_THEME=${options.theme}` | ||
) | ||
|
||
return templatePackageJson | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default { | ||
id: 'engine.config', | ||
theme: import.meta.env.VITE_THEME || 'light', | ||
material: ['/mock/bundle.json'], | ||
scripts: [], | ||
styles: [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters