Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-svelte: add svelte-check for TS #1556

Merged
merged 3 commits into from
May 28, 2021
Merged
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
5 changes: 5 additions & 0 deletions .changeset/seven-bags-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Add svelte-check to TS templates
15 changes: 13 additions & 2 deletions packages/create-svelte/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function write_common_files(cwd, options) {
const pkg = /** @type {any} */ (JSON.parse(fs.readFileSync(pkg_file, 'utf-8')));

files.forEach((file) => {
const include = file.include.every((condition) => options[condition]);
const exclude = file.exclude.some((condition) => options[condition]);
const include = file.include.every((condition) => matchesCondition(condition, options));
const exclude = file.exclude.some((condition) => matchesCondition(condition, options));

if (exclude || !include) return;

Expand All @@ -205,6 +205,17 @@ function write_common_files(cwd, options) {
fs.writeFileSync(pkg_file, JSON.stringify(pkg, null, ' '));
}

/**
* @param {import('./types/internal').Condition} condition
* @param {import('./types/internal').Options} options
* @returns {boolean}
*/
function matchesCondition(condition, options) {
return condition === 'default' || condition === 'skeleton'
? options.template === condition
: options[condition];
}

/**
* @param {any} target
* @param {any} source
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"@types/cookie": "^0.4.0"
}
}
5 changes: 5 additions & 0 deletions packages/create-svelte/shared/+typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"scripts": {
"check": "svelte-check --tsconfig ./tsconfig.json",
benmccann marked this conversation as resolved.
Show resolved Hide resolved
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"typescript": "^4.0.0",
"tslib": "^2.0.0",
"svelte-check": "^2.0.0",
"svelte-preprocess": "^4.0.0"
}
}
6 changes: 4 additions & 2 deletions packages/create-svelte/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export type File = {
contents: string;
};

export type Condition = 'eslint' | 'prettier' | 'typescript' | 'skeleton' | 'default';

export type Common = {
files: Array<{
name: string;
include: Array<'eslint' | 'prettier' | 'typescript'>;
exclude: Array<'eslint' | 'prettier' | 'typescript'>;
include: Array<Condition>;
exclude: Array<Condition>;
contents: string;
}>;
};