-
-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Labels
Description
It feels like we can make the API simpler. Why isn't the community template just this, for example?
import { defineIntegration } from '@sveltejs/cli/integration';
export default defineIntegration({
description: 'An adder template demo',
environments: { kit: true, svelte: true },
options: {
demo: {
question: 'Do you want to use a demo?',
type: 'boolean',
default: false
}
},
files: ({ options }) => [
{
name: 'adder-template-demo.txt',
content: (file) => {
if (options.demo) {
return 'This is a text file made by the integration template demo!'
}
return file.content;
}
},
{
name: 'src/DemoComponent.svelte',
content: (file) => {
file.addImport('../adder-template-demo.txt?raw', 'default', 'Demo');
}
{
]
});Things to note:
- it's a single file. To me this is the difference between 'oh hey I can build one of these!' and 'ugh. strap in, I guess'. It probably doesn't even need a
srcdirectory idandnamehave been removed. They don't need to be separate concepts — it's less confusing if we just use anidconsistently, instead of leaving people who see 'Foo Bar' listed somewhere to wonder whether it'sfoobarorfoo-baror whatever. And for stuff onnpm, the package name is theid, I'd argue we don't need another (that could potentially be something different than the package name, which is another source of confusion). Maybe there's an argument for mandating anidfor programmatic usage but I think it's probably unnecessarydescriptionandenvironmentsmoved up to the top level instead of being inmetadata- no
packagesarray. Surelypackage.jsoncan be just like any other JSON file? The smaller the API surface area the better filesis a function that returns an array, instead of an array of objects. That way it's easier to put logic in one place (e.g. you can doconst ext = options.typescript ? 'ts' : 'js'once instead of in eachnamemethod, and easier to return a different set of files entirely under certain conditionscontentTypeis inferred from file extension (I don't know if this is possible to do reliably from a types perspective, just an idea)- utilities like
addImportare passed in rather than imported. The big downside here is that it slightly discourages you from extracting the logic out into separate functions, but I'd argue a) this is a context where less indirection is better anyway, and b) it's outweighed by the benefits of discoverability and not having to deal with the exposed guts of things likejsAstunless you absolutely have to
Related note: What's the technical reason for the prohibition on dependencies? Seems very restrictive
devcsrj