Skip to content

Commit

Permalink
create-svelte: add svelte-check for TS (#1556)
Browse files Browse the repository at this point in the history
This add svelte-check along with two validate scripts to the package.json if the user selects TS. This uncovered missing type definitions for the cookie package in the default template, which are now added as well if the user selects TS.
Closes #1536
  • Loading branch information
dummdidumm authored May 28, 2021
1 parent 028abd9 commit 1739443
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
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",
"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;
}>;
};

0 comments on commit 1739443

Please sign in to comment.