-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example components and resulting output files.
- Loading branch information
Showing
8 changed files
with
335 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/test | ||
/examples | ||
/scripts | ||
.eslintrc.json | ||
.gitignore | ||
yarn.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"version": 3, | ||
"name": "alert", | ||
"data": [ | ||
{ | ||
"visibility": "private", | ||
"description": null, | ||
"keywords": [], | ||
"name": "createEventDispatcher", | ||
"kind": "const", | ||
"static": false, | ||
"readonly": true, | ||
"type": { | ||
"kind": "type", | ||
"text": "any", | ||
"type": "any" | ||
}, | ||
"importPath": "svelte", | ||
"originalName": "createEventDispatcher" | ||
}, | ||
{ | ||
"visibility": "private", | ||
"description": null, | ||
"keywords": [], | ||
"name": "dispatch", | ||
"kind": "const", | ||
"static": false, | ||
"readonly": true, | ||
"type": { | ||
"kind": "type", | ||
"text": "any", | ||
"type": "any" | ||
} | ||
}, | ||
{ | ||
"visibility": "public", | ||
"description": null, | ||
"keywords": [], | ||
"name": "closable", | ||
"kind": "let", | ||
"static": false, | ||
"readonly": false, | ||
"type": { | ||
"kind": "type", | ||
"text": "boolean", | ||
"type": "boolean" | ||
}, | ||
"defaultValue": false | ||
} | ||
], | ||
"computed": [], | ||
"methods": [], | ||
"components": [], | ||
"description": null, | ||
"keywords": [], | ||
"events": [ | ||
{ | ||
"visibility": "public", | ||
"description": null, | ||
"keywords": [], | ||
"name": "close" | ||
} | ||
], | ||
"slots": [ | ||
{ | ||
"name": "default", | ||
"description": "The internal content of the alert block.", | ||
"visibility": "public", | ||
"parameters": [] | ||
} | ||
], | ||
"refs": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script> | ||
import { createEventDispatcher } from 'svelte'; | ||
const dispatch = createEventDispatcher(); | ||
export let closable = false; | ||
</script> | ||
|
||
<div> | ||
<div> | ||
<!-- The internal content of the alert block. --> | ||
<slot></slot> | ||
</div> | ||
{#if closable} | ||
<div> | ||
<button on:click="{e => dispatch('close')}"></button> | ||
</div> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"version": 3, | ||
"name": "button", | ||
"data": [ | ||
{ | ||
"keywords": [ | ||
{ | ||
"name": "type", | ||
"description": "{string}" | ||
} | ||
], | ||
"visibility": "public", | ||
"description": "The text content of the button.", | ||
"name": "text", | ||
"kind": "let", | ||
"static": false, | ||
"readonly": false, | ||
"type": { | ||
"kind": "type", | ||
"text": "string", | ||
"type": "string" | ||
}, | ||
"defaultValue": "" | ||
}, | ||
{ | ||
"keywords": [ | ||
{ | ||
"name": "type", | ||
"description": "{'default'|'primary'|'danger'|'success'}" | ||
} | ||
], | ||
"visibility": "public", | ||
"description": "The style type of the button.", | ||
"name": "type", | ||
"kind": "let", | ||
"static": false, | ||
"readonly": false, | ||
"type": { | ||
"kind": "union", | ||
"text": "'default'|'primary'|'danger'|'success'", | ||
"type": [ | ||
{ | ||
"kind": "const", | ||
"text": "'default'", | ||
"type": "string", | ||
"value": "default" | ||
}, | ||
{ | ||
"kind": "const", | ||
"text": "'primary'", | ||
"type": "string", | ||
"value": "primary" | ||
}, | ||
{ | ||
"kind": "const", | ||
"text": "'danger'", | ||
"type": "string", | ||
"value": "danger" | ||
}, | ||
{ | ||
"kind": "const", | ||
"text": "'success'", | ||
"type": "string", | ||
"value": "success" | ||
} | ||
] | ||
}, | ||
"defaultValue": "default" | ||
}, | ||
{ | ||
"keywords": [ | ||
{ | ||
"name": "type", | ||
"description": "{'small'|'normal'|'big'}" | ||
} | ||
], | ||
"visibility": "public", | ||
"description": "The size of the button.", | ||
"name": "size", | ||
"kind": "let", | ||
"static": false, | ||
"readonly": false, | ||
"type": { | ||
"kind": "union", | ||
"text": "'small'|'normal'|'big'", | ||
"type": [ | ||
{ | ||
"kind": "const", | ||
"text": "'small'", | ||
"type": "string", | ||
"value": "small" | ||
}, | ||
{ | ||
"kind": "const", | ||
"text": "'normal'", | ||
"type": "string", | ||
"value": "normal" | ||
}, | ||
{ | ||
"kind": "const", | ||
"text": "'big'", | ||
"type": "string", | ||
"value": "big" | ||
} | ||
] | ||
}, | ||
"defaultValue": "normal" | ||
} | ||
], | ||
"computed": [], | ||
"methods": [], | ||
"components": [], | ||
"description": "The simple component button.", | ||
"keywords": [ | ||
{ | ||
"name": "component", | ||
"description": "Button" | ||
}, | ||
{ | ||
"name": "example", | ||
"description": "<Button text=\"Click there!\" on:click={() => ...} />" | ||
} | ||
], | ||
"events": [ | ||
{ | ||
"name": "click", | ||
"parent": "button", | ||
"modificators": [], | ||
"locations": null, | ||
"loc": null, | ||
"visibility": "public", | ||
"description": "", | ||
"keywords": [] | ||
} | ||
], | ||
"slots": [], | ||
"refs": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script> | ||
/** | ||
* The simple component button. | ||
* | ||
* @component Button | ||
* @example | ||
* <Button text="Click there!" on:click={() => ...} /> | ||
*/ | ||
/** | ||
* The text content of the button. | ||
* @type {string} | ||
*/ | ||
export let text = ''; | ||
/** | ||
* The style type of the button. | ||
* @type {'default'|'primary'|'danger'|'success'} | ||
*/ | ||
export let type = 'default'; | ||
/** | ||
* The size of the button. | ||
* @type {'small'|'normal'|'big'} | ||
*/ | ||
export let size = 'normal'; | ||
</script> | ||
|
||
<button type="button" on:click> | ||
{text} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const parser = require('../index'); | ||
|
||
function getFileName(input) { | ||
const basename = path.basename(input); | ||
const dotIndex = basename.lastIndexOf('.'); | ||
|
||
if (dotIndex > 0) { | ||
return basename.substring(0, dotIndex); | ||
} | ||
|
||
return basename; | ||
} | ||
|
||
function processSvelteFile(svelteFilePath) { | ||
return new Promise(resolve => { | ||
parser.parse({ | ||
version: 3, | ||
filename: svelteFilePath, | ||
ignoredVisibilities: [] | ||
}).then(doc => { | ||
const targetFilePath = path.join(path.dirname(svelteFilePath), `${getFileName(svelteFilePath)}.json`); | ||
|
||
fs.writeFile( | ||
targetFilePath, | ||
JSON.stringify(doc, undefined, 4), | ||
(err) => { | ||
if (err) { | ||
console.log(`[Error] ${svelteFilePath} (${err.message})`); | ||
resolve({ err, svelteFilePath }); | ||
|
||
return; | ||
} | ||
|
||
console.log('[Done]', svelteFilePath); | ||
resolve({ svelteFilePath }); | ||
}); | ||
}).catch(err => { | ||
console.log(`[Error] ${svelteFilePath} (${err.message})`); | ||
resolve({ err, svelteFilePath }); | ||
}); | ||
}); | ||
} | ||
|
||
glob('./examples/**/*.svelte', (err, files) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
const promises = files.map(svelteFilePath => { | ||
return processSvelteFile(svelteFilePath); | ||
}); | ||
|
||
Promise.all(promises) | ||
.then(errors => { | ||
if (errors) { | ||
errors.forEach(({ err, svelteFilePath }) => { | ||
if (err) { | ||
console.error(`\nError at file processing "${svelteFilePath}":`, err); | ||
} | ||
}); | ||
} | ||
|
||
process.exit(errors.filter(({ err }) => err).length); | ||
}); | ||
}); |