Skip to content

Commit 9bd174d

Browse files
committed
Run svelte-kit sync #1063
1 parent 35138fe commit 9bd174d

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

browser/cli/src/generateIndex.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export const generateIndex = (
3333
const names = ontologies.map(x => {
3434
const res = store.getResourceLoading(x);
3535

36+
if (res.error) {
37+
throw new Error('error getting ontology');
38+
}
39+
3640
return camelCaseify(res.title);
3741
});
3842

@@ -43,10 +47,8 @@ export const generateIndex = (
4347
const importLines = names.map(createImportLine).join('\n');
4448
const registerArgs = names.join(', ');
4549

46-
const content = TEMPLATE.replaceAll(
47-
Inserts.MODULE_ALIAS,
48-
atomicConfig.moduleAlias ?? '@tomic/lib',
49-
)
50+
const moduleAlias = atomicConfig.moduleAlias ?? '@tomic/lib';
51+
const content = TEMPLATE.replaceAll(Inserts.MODULE_ALIAS, moduleAlias)
5052
.replace(Inserts.IMPORTS, importLines)
5153
.replace(Inserts.REGISTER_ARGS, registerArgs);
5254

browser/cli/src/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ export const dedupe = <T>(array: T[]): T[] => {
99
return Array.from(new Set(array));
1010
};
1111

12-
export const getExtension = () =>
13-
getTsconfig()?.config.compilerOptions?.moduleResolution === 'Bundler'
14-
? ''
15-
: '.js';
12+
export const getExtension = () => {
13+
try {
14+
return getTsconfig()?.config.compilerOptions?.moduleResolution === 'Bundler'
15+
? ''
16+
: '.js';
17+
} catch (e) {
18+
console.warn('Something went wrong getting TS Config / file extension', e);
19+
20+
return '.js';
21+
}
22+
};

browser/create-template/src/postprocess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function postProcess(context: PostProcessContext) {
3535
switch (ontology.error.type) {
3636
case ErrorType.NotFound:
3737
console.error(
38-
`\nThe ${baseTemplate.name} template does not exist on your drive. To get the template go to the Create Resource page and select the ${baseTemplate.name} template`,
38+
`\nThe '${baseTemplate.name}' template does not exist on your drive on '${ontologySubject}'. To get the template go to the Create Resource page and select the ${baseTemplate.name} template.`,
3939
);
4040
break;
4141
case ErrorType.Unauthorized:

browser/e2e/tests/template.spec.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,46 @@ import fs from 'node:fs';
1313
import { spawn, type ChildProcess } from 'node:child_process';
1414
import path from 'node:path';
1515
import kill from 'kill-port';
16-
import { promisify } from 'util';
1716
import { log } from 'node:console';
1817

19-
const execAsync = promisify(exec);
18+
const execAsync = async (
19+
command: Parameters<typeof exec>[0],
20+
options?: Parameters<typeof exec>[1],
21+
) => {
22+
return new Promise((resolve, reject) => {
23+
exec(command, options, (err, stdout, stderr) => {
24+
console.log(stdout, stderr);
25+
26+
if (err) {
27+
reject(new Error(err.message));
28+
}
29+
30+
if (stderr) {
31+
reject(new Error(stderr.toString()));
32+
}
33+
34+
resolve(stdout.toString());
35+
});
36+
});
37+
};
38+
2039
const TEMPLATE_DIR_NAME = 'template-tests';
2140
// test.describe.configure({ mode: 'serial' });
2241

2342
async function setupTemplateSite(
24-
templateDir: string,
2543
serverUrl: string,
26-
siteType: string,
44+
siteType: 'nextjs-site' | 'sveltekit-site',
2745
) {
28-
if (!fs.existsSync(templateDir)) {
29-
fs.mkdirSync(templateDir);
46+
if (!fs.existsSync(TEMPLATE_DIR_NAME)) {
47+
fs.mkdirSync(TEMPLATE_DIR_NAME);
3048
}
3149

3250
await execAsync('pnpm link ../create-template');
3351
await execAsync(
34-
`pnpm exec create-template ${templateDir}/${siteType} --template ${siteType} --server-url ${serverUrl}`,
52+
`pnpm exec create-template ${TEMPLATE_DIR_NAME}/${siteType} --template ${siteType} --server-url ${serverUrl}`,
3553
);
3654

37-
const sitePath = `${templateDir}/${siteType}`;
55+
const sitePath = `${TEMPLATE_DIR_NAME}/${siteType}`;
3856
await execAsync('pnpm install', { cwd: sitePath });
3957
await execAsync('pnpm link ../../../cli', { cwd: sitePath });
4058
await execAsync('pnpm link ../../../lib', { cwd: sitePath });
@@ -43,6 +61,7 @@ async function setupTemplateSite(
4361
await execAsync('pnpm link ../../../react', { cwd: sitePath });
4462
} else if (siteType === 'sveltekit-site') {
4563
await execAsync('pnpm link ../../../svelte', { cwd: sitePath });
64+
await execAsync('pnpm svelte-kit sync', { cwd: sitePath });
4665
}
4766

4867
await execAsync('pnpm update-ontologies', { cwd: sitePath });
@@ -123,7 +142,7 @@ test.describe('Create Next.js Template', () => {
123142
});
124143
await applyTemplateButton.click();
125144

126-
await setupTemplateSite(TEMPLATE_DIR_NAME, drive.driveURL, 'nextjs-site');
145+
await setupTemplateSite(drive.driveURL, 'nextjs-site');
127146

128147
try {
129148
//start server
@@ -202,11 +221,7 @@ test.describe('Create SvelteKit Template', () => {
202221
});
203222
await applyTemplateButton.click();
204223

205-
await setupTemplateSite(
206-
TEMPLATE_DIR_NAME,
207-
drive.driveURL,
208-
'sveltekit-site',
209-
);
224+
await setupTemplateSite(drive.driveURL, 'sveltekit-site');
210225

211226
try {
212227
const child = startServer(TEMPLATE_DIR_NAME, 'sveltekit-site');

0 commit comments

Comments
 (0)