Skip to content

Commit bbc9140

Browse files
committed
feat: support multiple platforms
1 parent e1c0066 commit bbc9140

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

packages/cli/src/commands/addPlatform/addPlatform.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,33 @@ async function addPlatform(
168168
const templateName = getTemplateName(templateSourceDir);
169169
const templateConfig = getTemplateConfig(templateName, templateSourceDir);
170170

171-
if (!templateConfig.platformName) {
171+
if (!templateConfig.platforms) {
172172
throw new CLIError(
173-
`Template ${templateName} is missing platformName in its template.config.js`,
173+
`Template ${templateName} is missing "platforms" in its "template.config.js"`,
174174
);
175175
}
176176

177-
await copyTemplate(
178-
templateName,
179-
templateConfig.templateDir,
180-
templateSourceDir,
181-
templateConfig.platformName,
182-
);
177+
for (const platform of templateConfig.platforms) {
178+
await copyTemplate(
179+
templateName,
180+
templateConfig.templateDir,
181+
templateSourceDir,
182+
platform,
183+
);
184+
}
183185

184186
loader.succeed();
185187
loader.start('Processing template');
186188

187-
await changePlaceholderInTemplate({
188-
projectName,
189-
projectTitle: title,
190-
placeholderName: templateConfig.placeholderName,
191-
placeholderTitle: templateConfig.titlePlaceholder,
192-
projectPath: join(root, templateConfig.platformName),
193-
});
189+
for (const platform of templateConfig.platforms) {
190+
await changePlaceholderInTemplate({
191+
projectName,
192+
projectTitle: title,
193+
placeholderName: templateConfig.placeholderName,
194+
placeholderTitle: templateConfig.titlePlaceholder,
195+
projectPath: join(root, platform),
196+
});
197+
}
194198

195199
loader.succeed();
196200

packages/cli/src/commands/init/editTemplate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export async function replacePlaceholderWithPackageName({
146146
placeholderName,
147147
placeholderTitle,
148148
packageName,
149-
projectPath,
149+
projectPath = process.cwd(),
150150
}: Omit<Required<PlaceholderConfig>, 'projectTitle'>) {
151151
validatePackageName(packageName);
152152
const cleanPackageName = packageName.replace(/[^\p{L}\p{N}.]+/gu, '');

packages/cli/src/commands/init/template.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type TemplateConfig = {
1414
templateDir: string;
1515
postInitScript?: string;
1616
titlePlaceholder?: string;
17-
platformName: string;
17+
platforms?: string[];
1818
};
1919

2020
export async function installTemplatePackage(
@@ -92,7 +92,7 @@ export async function copyTemplate(
9292
templateName: string,
9393
templateDir: string,
9494
templateSourceDir: string,
95-
platformName: string = '',
95+
platform: string = '',
9696
) {
9797
const templatePath = path.resolve(
9898
templateSourceDir,
@@ -103,13 +103,9 @@ export async function copyTemplate(
103103

104104
logger.debug(`Copying template from ${templatePath}`);
105105
let regexStr = path.resolve(templatePath, 'node_modules');
106-
await copyFiles(
107-
join(templatePath, platformName),
108-
join(process.cwd(), platformName),
109-
{
110-
exclude: [new RegExp(replacePathSepForRegex(regexStr))],
111-
},
112-
);
106+
await copyFiles(join(templatePath, platform), join(process.cwd(), platform), {
107+
exclude: [new RegExp(replacePathSepForRegex(regexStr))],
108+
});
113109
}
114110

115111
export function executePostInitScript(

0 commit comments

Comments
 (0)