Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/boilersmith/scaffolding/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ export async function applyModule<MN extends string, TN extends string>(
string
>;

// This is necessary because one layer of escaped backslashes is lost on template population.
tplData.params = Object.fromEntries(Object.entries(paramVals).map(([k, v]) => [k, typeof v === 'string' ? v.replace('\\', '\\\\') : v])) as Record<
TN,
unknown
>;

for (const file of module.filesToReplace) {
const path = typeof file === 'string' ? file : file.path;
Expand Down Expand Up @@ -270,8 +265,15 @@ export async function applyModule<MN extends string, TN extends string>(
}

const jsonPaths = cloneAndFill(module.jsonToAugment, tplDataFlat);

// This is necessary because one layer of escaped backslashes is lost on template population.
const clonedTplData = { ...tplData };
clonedTplData.params = Object.fromEntries(
Object.entries(paramVals).map(([k, v]) => [k, typeof v === 'string' ? v.replace('\\', '\\\\') : v])
) as Record<TN, unknown>;

for (const jsonPath of Object.keys(jsonPaths)) {
const scaffoldContents = readTpl(resolve(scaffoldDir, jsonPath), tplData);
const scaffoldContents = readTpl(resolve(scaffoldDir, jsonPath), clonedTplData);
const scaffoldContentsJson = JSON.parse(scaffoldContents);

const excludeKeys = cloneAndFill(excludeScaffolding.configKeys[jsonPath] ?? [], tplDataFlat);
Expand Down
16 changes: 15 additions & 1 deletion src/steps/gen-ext-scaffolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { resolve } from 'path';
import simpleGit from 'simple-git';
import spdxLicenseListSimple from 'spdx-license-list/simple';
import { getComposerJson } from '../utils/composer';
import s from 'string';

function assertUnreachable(_x: never): never {
throw new Error("Didn't expect to get here");
Expand Down Expand Up @@ -75,6 +76,13 @@ function paramNamesToDef(name: ExtensionParams): TemplateParam<string, Extension
name,
type: 'text',
message: `Package namespace ${chalk.dim('(Vendor\\ExtensionName)')}`,
initial: (_prev, values) =>
(values as unknown as Map<string, string>)
.get('packageName')!
.replace('/flarum-', '/')
.split('/')
.map((b: string) => s(b).camelize().capitalize().toString())
.join('\\'),
validate: (s) => /^([\dA-Za-z]+)\\([\dA-Za-z]+)$/.test(s.trim()) || 'Invalid namespace format',
format: (str: string) =>
str &&
Expand All @@ -86,7 +94,7 @@ function paramNamesToDef(name: ExtensionParams): TemplateParam<string, Extension
getCurrVal: async (fs: Store, paths: Paths) => {
const json = getComposerJson(fs, paths);
const namespace = (Object.keys(json?.autoload?.['psr-4'] ?? {})?.[0] ?? '')?.slice(0, -1);
return namespace || '';
return (namespace || '').replace('\\\\', '\\');
},
};

Expand Down Expand Up @@ -124,6 +132,12 @@ function paramNamesToDef(name: ExtensionParams): TemplateParam<string, Extension
type: 'text',
message: 'Extension name',
validate: (str) => Boolean(str.trim()) || 'The extension name is required',
initial: (_prev, values) =>
s((values as unknown as Map<string, string>).get('packageName')!.split('/')[1])
.replaceAll('flarum-', '')
.humanize()
.capitalize()
.toString(),
format: (str) =>
str
.split(' ')
Expand Down