Skip to content

Commit

Permalink
add runes support
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryB432 committed Sep 27, 2024
1 parent f821c83 commit ba5f9ce
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/sveltekit-component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function normalizeOptions(options: Options): Options {
}

export default function (options: Options): Rule {
if (!options.runes) throw new Error('only runes mode is supported');
const opts = normalizeOptions(options);
const directory = opts.directory ?? 'lib/components';
const projectRoot = (opts.projectRoot ?? '.') as Path;
Expand All @@ -46,7 +47,7 @@ export default function (options: Options): Rule {
if (!tree.exists(normalize(join(projectRoot, 'svelte.config.js')))) {
context.logger.warn(`no svelte configuration found in '${projectRoot}'`);
}
const templateSource = apply(url('./files'), [
const templateSource = apply(url('./files/v2/runes'), [
applyTemplates({ ...opts, ...strings }),
move(normalize(join(projectRoot, 'src', parsedPath.path))),
]);
Expand Down
3 changes: 3 additions & 0 deletions src/sveltekit-component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('sveltekit-component', () => {
expect(tree.files).toEqual(
jasmine.arrayWithExactContents(['/src/lib/components/Tester.svelte'])
);
expect(tree.readContent('/src/lib/components/Tester.svelte')).not.toContain(
'export let'
);
});

it('works with directory', async () => {
Expand Down
5 changes: 5 additions & 0 deletions src/sveltekit-component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"projectRoot": {
"type": "string",
"description": "Svelte App root directory"
},
"runes": {
"type": "boolean",
"description": "Use runes for reactivitty",
"default": true
}
},
"additionalProperties": false,
Expand Down
5 changes: 3 additions & 2 deletions src/sveltekit-route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ function normalizeOptions(o: Options): Required<Options> {
const endpoint = o.endpoint ?? false;
const skipTests = o.skipTests ?? false;
const projectRoot = o.projectRoot ?? '.';
return { ...o, path, style, skipTests, endpoint, projectRoot };
return { ...o, path, style, skipTests, endpoint, projectRoot, runes: true };
}

export default function (opts: Options): Rule {
if (!opts.runes) throw new Error('only runes mode is supported');
return async (tree: Tree, context: SchematicContext) => {
const options = normalizeOptions(opts);
if (!tree.exists(join(options.projectRoot as Path, 'svelte.config.js'))) {
Expand All @@ -53,7 +54,7 @@ export default function (opts: Options): Rule {
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
const templateSource = apply(url('./files/v0'), [
const templateSource = apply(url('./files/v2/runes'), [
applyTemplates({
...strings,
...options,
Expand Down
3 changes: 3 additions & 0 deletions src/sveltekit-route/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ describe('sveltekit-route', () => {
'/tests/tester.spec.ts',
])
);
expect(tree.readContent('/src/routes/tester/+page.svelte')).toContain(
'$props()'
);
});
});

Expand Down
5 changes: 5 additions & 0 deletions src/sveltekit-route/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
},
"description": "The path to your project root, relative to the current workspace. Default is workingDirectory",
"visible": false
},
"runes": {
"type": "boolean",
"description": "Use runes for reactivitty",
"default": true
}
},
"required": ["name"]
Expand Down

0 comments on commit ba5f9ce

Please sign in to comment.