├── .editorconfig ├── .gitignore ├── build.js ├── build ├── interface │ ├── components │ │ ├── Application │ │ │ ├── Application.svelte │ │ │ ├── ApplicationSource │ │ │ │ ├── ApplicationSource.svelte │ │ │ │ └── index.js │ │ │ └── index.js │ │ ├── Component │ │ │ ├── Component.svelte │ │ │ ├── ComponentClasses │ │ │ │ ├── ComponentClasses.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentCode │ │ │ │ ├── ComponentCode.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentContext │ │ │ │ ├── ComponentContext.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentDefinition │ │ │ │ ├── ComponentDefinition.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentDescription │ │ │ │ ├── ComponentDescription.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentFunctions │ │ │ │ ├── ComponentFunctions.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentInitialization │ │ │ │ ├── ComponentInitialization.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentProperties │ │ │ │ ├── ComponentProperties.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentUsage │ │ │ │ ├── ComponentUsage.svelte │ │ │ │ ├── consntants.js │ │ │ │ └── index.js │ │ │ ├── ComponentUsages │ │ │ │ ├── ComponentUsages.svelte │ │ │ │ └── index.js │ │ │ ├── ComponentVariables │ │ │ │ ├── ComponentVariables.svelte │ │ │ │ ├── ComponentVariablesTable │ │ │ │ │ ├── ComponentVariablesTable.svelte │ │ │ │ │ └── index.js │ │ │ │ └── index.js │ │ │ └── index.js │ │ └── Source │ │ │ ├── Source.svelte │ │ │ └── index.js │ ├── helpers │ │ ├── convertCamelToCode.js │ │ ├── convertCodeToComponent.js │ │ ├── decodeSpecialChars.js │ │ ├── filterObject.js │ │ ├── isDeclarationContext.js │ │ ├── resolveHighlightedSource.js │ │ └── resolveMenuFromLibrary.js │ ├── index.css │ ├── index.js │ ├── stores.js │ └── styles │ │ ├── global.css │ │ └── reset.css ├── system │ ├── base │ │ ├── Base.d.ts │ │ ├── Base.js │ │ ├── Object.d.ts │ │ ├── Object.js │ │ ├── Source.d.ts │ │ ├── Source.js │ │ ├── SvelteSource.d.ts │ │ └── SvelteSource.js │ ├── cli.d.ts │ ├── cli.js │ ├── cli │ │ ├── generate.d.ts │ │ ├── generate.js │ │ ├── setup.d.ts │ │ ├── setup.js │ │ ├── watch.d.ts │ │ └── watch.js │ ├── constants.d.ts │ ├── constants.js │ ├── exports │ │ ├── BaseExport.d.ts │ │ ├── BaseExport.js │ │ ├── ClassExport.d.ts │ │ ├── ClassExport.js │ │ ├── FunctionExport.d.ts │ │ ├── FunctionExport.js │ │ ├── VariableExport.d.ts │ │ └── VariableExport.js │ ├── helpers │ │ ├── createEmptyDirectory.d.ts │ │ ├── createEmptyDirectory.js │ │ ├── displayCommandDone.d.ts │ │ ├── displayCommandDone.js │ │ ├── displayCommandGreetings.d.ts │ │ ├── displayCommandGreetings.js │ │ ├── displayCommandStep.d.ts │ │ ├── displayCommandStep.js │ │ ├── encodeSpecialChars.d.ts │ │ ├── encodeSpecialChars.js │ │ ├── encodeSvelteValue.d.ts │ │ ├── encodeSvelteValue.js │ │ ├── generateUniqueIdentifier.d.ts │ │ ├── generateUniqueIdentifier.js │ │ ├── resolveDocumentationComponentPath.d.ts │ │ ├── resolveDocumentationComponentPath.js │ │ ├── resolveDocumentationDirectoryComponentPath.d.ts │ │ ├── resolveDocumentationDirectoryComponentPath.js │ │ ├── resolveDocumentationDirectoryPath.d.ts │ │ ├── resolveDocumentationDirectoryPath.js │ │ ├── resolveMarkdownFromComment.d.ts │ │ ├── resolveMarkdownFromComment.js │ │ ├── resolveMenuFromGenerators.d.ts │ │ ├── resolveMenuFromGenerators.js │ │ ├── resolvePackagePath.d.ts │ │ ├── resolvePackagePath.js │ │ ├── resolveRelativeImports.d.ts │ │ └── resolveRelativeImports.js │ ├── imports │ │ ├── BaseImport.d.ts │ │ ├── BaseImport.js │ │ ├── DefaultImport.d.ts │ │ ├── DefaultImport.js │ │ ├── Import.d.ts │ │ ├── Import.js │ │ ├── NamespaceImport.d.ts │ │ └── NamespaceImport.js │ ├── models │ │ ├── Attribute.d.ts │ │ ├── Attribute.js │ │ ├── Component.d.ts │ │ ├── Component.js │ │ ├── Description.d.ts │ │ ├── Description.js │ │ ├── Dictionary.d.ts │ │ ├── Dictionary.js │ │ ├── Documentation.d.ts │ │ ├── Documentation.js │ │ ├── Generator.d.ts │ │ ├── Generator.js │ │ ├── Location.d.ts │ │ ├── Location.js │ │ ├── Package.d.ts │ │ ├── Package.js │ │ ├── Router.d.ts │ │ ├── Router.js │ │ ├── Script.d.ts │ │ ├── Script.js │ │ ├── Variable.d.ts │ │ └── Variable.js │ ├── partials │ │ ├── BasePartial.d.ts │ │ ├── BasePartial.js │ │ ├── DescriptionPartial.d.ts │ │ ├── DescriptionPartial.js │ │ ├── MainPartial.d.ts │ │ ├── MainPartial.js │ │ ├── UsagePartial.d.ts │ │ └── UsagePartial.js │ └── types │ │ ├── ExportResultType.d.ts │ │ ├── ExportResultType.js │ │ ├── ExportType.d.ts │ │ ├── ExportType.js │ │ ├── ImportType.d.ts │ │ ├── ImportType.js │ │ ├── ItemType.d.ts │ │ ├── ItemType.js │ │ ├── PartialType.d.ts │ │ └── PartialType.js └── vendors │ └── bootstrap │ └── bootstrap.css ├── documentation └── screenshots │ ├── component-checkbox-group.png │ └── component-input.png ├── gulpfile.js ├── interface ├── components │ ├── Application │ │ ├── Application.svelte │ │ ├── ApplicationSource │ │ │ ├── ApplicationSource.svelte │ │ │ └── index.js │ │ └── index.js │ ├── Component │ │ ├── Component.svelte │ │ ├── ComponentClasses │ │ │ ├── ComponentClasses.svelte │ │ │ └── index.js │ │ ├── ComponentCode │ │ │ ├── ComponentCode.svelte │ │ │ └── index.js │ │ ├── ComponentContext │ │ │ ├── ComponentContext.svelte │ │ │ └── index.js │ │ ├── ComponentDefinition │ │ │ ├── ComponentDefinition.svelte │ │ │ └── index.js │ │ ├── ComponentDescription │ │ │ ├── ComponentDescription.svelte │ │ │ └── index.js │ │ ├── ComponentFunctions │ │ │ ├── ComponentFunctions.svelte │ │ │ └── index.js │ │ ├── ComponentInitialization │ │ │ ├── ComponentInitialization.svelte │ │ │ └── index.js │ │ ├── ComponentProperties │ │ │ ├── ComponentProperties.svelte │ │ │ └── index.js │ │ ├── ComponentUsage │ │ │ ├── ComponentUsage.svelte │ │ │ ├── consntants.js │ │ │ └── index.js │ │ ├── ComponentUsages │ │ │ ├── ComponentUsages.svelte │ │ │ └── index.js │ │ ├── ComponentVariables │ │ │ ├── ComponentVariables.svelte │ │ │ ├── ComponentVariablesTable │ │ │ │ ├── ComponentVariablesTable.svelte │ │ │ │ └── index.js │ │ │ └── index.js │ │ └── index.js │ └── Source │ │ ├── Source.svelte │ │ └── index.js ├── helpers │ ├── convertCamelToCode.js │ ├── convertCodeToComponent.js │ ├── decodeSpecialChars.js │ ├── filterObject.js │ ├── isDeclarationContext.js │ ├── resolveHighlightedSource.js │ └── resolveMenuFromLibrary.js ├── index.js ├── index.pcss ├── stores.js └── styles │ ├── global.pcss │ └── reset.pcss ├── package-lock.json ├── package.json ├── postcss.config.js ├── readme.md ├── system ├── base │ ├── Base.ts │ ├── Object.ts │ ├── Source.ts │ └── SvelteSource.ts ├── cli.ts ├── cli │ ├── generate.ts │ ├── setup.ts │ └── watch.ts ├── constants.ts ├── exports │ ├── BaseExport.ts │ ├── ClassExport.ts │ ├── FunctionExport.ts │ └── VariableExport.ts ├── helpers │ ├── createEmptyDirectory.ts │ ├── displayCommandDone.ts │ ├── displayCommandGreetings.ts │ ├── displayCommandStep.ts │ ├── encodeSpecialChars.ts │ ├── encodeSvelteValue.ts │ ├── generateUniqueIdentifier.ts │ ├── resolveDocumentationComponentPath.ts │ ├── resolveDocumentationDirectoryComponentPath.ts │ ├── resolveDocumentationDirectoryPath.ts │ ├── resolveMarkdownFromComment.ts │ ├── resolveMenuFromGenerators.ts │ ├── resolvePackagePath.ts │ └── resolveRelativeImports.ts ├── imports │ ├── BaseImport.ts │ ├── DefaultImport.ts │ ├── Import.ts │ └── NamespaceImport.ts ├── models │ ├── Attribute.ts │ ├── Component.ts │ ├── Description.ts │ ├── Dictionary.ts │ ├── Documentation.ts │ ├── Generator.ts │ ├── Location.ts │ ├── Package.ts │ ├── Router.ts │ ├── Script.ts │ └── Variable.ts ├── partials │ ├── BasePartial.ts │ ├── DescriptionPartial.ts │ ├── MainPartial.ts │ └── UsagePartial.ts └── types │ ├── ExportResultType.ts │ ├── ExportType.ts │ ├── ImportType.ts │ ├── ItemType.ts │ └── PartialType.ts ├── template ├── .gitignore ├── .npmrc ├── package.json ├── public │ └── index.html ├── site │ ├── App.svelte │ ├── constants.js │ ├── context.js │ ├── helpers │ │ └── addProductionHash.js │ ├── index.js │ └── pages │ │ ├── ComponentPage.svelte │ │ └── DefaultPage.svelte └── webpack.config.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = space 3 | indent_size = 2 4 | charset = utf-8 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | end_of_line = lf 8 | max_line_length = 120 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /node_modules 3 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import glob from 'glob'; 3 | import path from 'path'; 4 | import postcss from 'postcss'; 5 | import { preprocess } from 'svelte/compiler'; 6 | 7 | const { plugins } = require('./postcss.config'); 8 | 9 | const PATH_TO_SOURCE = path.resolve('interface'); 10 | const PATH_TO_TARGET = path.resolve('build', 'interface'); 11 | 12 | // start processing chain 13 | let chain = Promise.resolve(); 14 | 15 | // process svelte components 16 | const components = glob.sync(`${PATH_TO_SOURCE}/**/*.svelte`); 17 | chain = components.reduce((chain, pathToSource) => chain.then(async () => { 18 | const pathRelative = path.relative(PATH_TO_SOURCE, pathToSource); 19 | const pathToTarget = path.resolve(PATH_TO_TARGET, pathRelative); 20 | 21 | // get content of the component 22 | const source = fs.readFileSync(pathToSource).toString(); 23 | 24 | // process component with preprocessors 25 | const { code } = await preprocess(source, { 26 | style: ({ content, attributes }) => { 27 | if (attributes.lang !== 'postcss') { 28 | return; 29 | } 30 | 31 | return postcss(plugins).process(content, { 32 | from: pathToSource, 33 | to: pathToTarget 34 | }).then((result) => ({ 35 | code: result.css.toString() 36 | })); 37 | } 38 | }, { 39 | filename: pathRelative 40 | }); 41 | 42 | // create target folder 43 | fs.mkdirSync(path.dirname(pathToTarget), { recursive: true }); 44 | 45 | // save just preprocessed code to the target folder 46 | fs.writeFileSync(pathToTarget, code); 47 | }), chain); 48 | 49 | // process js files 50 | const scripts = glob.sync(`${PATH_TO_SOURCE}/**/*.js`); 51 | chain = scripts.reduce((chain, pathToSource) => chain.then(async () => { 52 | const pathRelative = path.relative(PATH_TO_SOURCE, pathToSource); 53 | const pathToTarget = path.resolve(PATH_TO_TARGET, pathRelative); 54 | 55 | // create target folder 56 | fs.mkdirSync(path.dirname(pathToTarget), { recursive: true }); 57 | 58 | // copy source file 59 | fs.copyFileSync(pathToSource, pathToTarget); 60 | }), chain); 61 | 62 | // process postcss files 63 | const styles = glob.sync(`${PATH_TO_SOURCE}/**/*.pcss`); 64 | chain = styles.reduce((chain, pathToSource) => chain.then(async () => { 65 | const pathRelative = path.relative(PATH_TO_SOURCE, pathToSource); 66 | const pathToTarget = path.resolve(PATH_TO_TARGET, path.dirname(pathRelative), `${path.basename(pathRelative, '.pcss')}.css`); 67 | 68 | // get content of the component 69 | const source = fs.readFileSync(pathToSource).toString(); 70 | 71 | const { code } = await postcss(plugins).process(source, { 72 | from: pathToSource, 73 | to: pathToTarget 74 | }).then((result) => ({ 75 | code: result.css.toString() 76 | })); 77 | 78 | // create target folder 79 | fs.mkdirSync(path.dirname(pathToTarget), { recursive: true }); 80 | 81 | // save just preprocessed code to the target folder 82 | fs.writeFileSync(pathToTarget, code); 83 | }), chain); 84 | -------------------------------------------------------------------------------- /build/interface/components/Application/Application.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 |
23 | 39 | 40 |
41 | {#each routes as route} 42 | 43 | {/each} 44 |
45 |
46 |
47 | 48 | {#if $source} 49 | 50 | {/if} 51 | -------------------------------------------------------------------------------- /build/interface/components/Application/ApplicationSource/ApplicationSource.svelte: -------------------------------------------------------------------------------- 1 | 23 | 24 | 25 | 26 |
27 |
28 | 29 | 42 |
43 | -------------------------------------------------------------------------------- /build/interface/components/Application/ApplicationSource/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ApplicationSource.svelte'; 2 | 3 | export default Component; 4 | -------------------------------------------------------------------------------- /build/interface/components/Application/index.js: -------------------------------------------------------------------------------- 1 | import Application from './Application.svelte'; 2 | 3 | export default Application; 4 | -------------------------------------------------------------------------------- /build/interface/components/Component/Component.svelte: -------------------------------------------------------------------------------- 1 | 28 | 29 | 30 | 31 |
32 |
33 |
{title} {@html badgeCompiled}
34 | 35 | {#if withDescription} 36 |
37 | 38 | 39 | 40 |
41 | {/if} 42 |
43 | 44 |
45 | {#if withUsages} 46 |
47 | 48 | 49 | 50 |
51 | {/if} 52 | 53 |
54 | {#if withInitialization} 55 |
56 | 57 |
58 | {/if} 59 | 60 | {#if withDefinition} 61 |
62 | 63 |
64 | {/if} 65 |
66 |
67 |
68 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentClasses/ComponentClasses.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentClasses/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentClasses.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentCode/ComponentCode.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentCode/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentCode.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentContext/ComponentContext.svelte: -------------------------------------------------------------------------------- 1 | 23 | 24 | 25 | 26 |
27 |
{title}
28 |
{tag}
29 | 30 |
31 |
32 | 33 |
34 | 35 |
36 | 37 |
38 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentContext/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentContext.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentDefinition/ComponentDefinition.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 |
12 |
{title}
13 | 14 | 15 | 16 | {#if module && instance} 17 |
18 | {/if} 19 | 20 | 21 |
22 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentDefinition/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentDefinition.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentDescription/ComponentDescription.svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | 6 |
7 |
8 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentDescription/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentDescription.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentFunctions/ComponentFunctions.svelte: -------------------------------------------------------------------------------- 1 | 27 | 28 |
29 | 30 |
31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | {#each sorted as item} 43 | 44 | 48 | 53 | 54 | 55 | 56 | {/each} 57 | 58 |
NameArgumentsDescriptionNote
45 | {item.name} 46 | (definitions) 47 | 49 | {#each item.arguments as argument} 50 | {@html resolveFunctionArgumentLabel(argument)}  51 | {/each} 52 | {@html md.render(item.description || '')}{@html md.render(item.note || '')}
59 |
60 |
61 |
62 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentFunctions/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentFunctions.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentInitialization/ComponentInitialization.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 |
14 |
{title}
15 |
16 | 17 | {#if decoded} 18 | 19 | {:else} 20 | 23 | {/if} 24 |
25 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentInitialization/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentInitialization.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentProperties/ComponentProperties.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 |
9 |
{title}
10 | 11 | {#if visible} 12 | 13 | {:else} 14 | 17 | {/if} 18 |
19 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentProperties/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentProperties.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentUsage/ComponentUsage.svelte: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | 23 |
24 |
{title} {@html badgeCompiled}
25 | 26 |
27 |
28 | 29 |
30 | 31 | {#if decoded} 32 |
33 | 34 |
35 | {/if} 36 |
37 |
38 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentUsage/consntants.js: -------------------------------------------------------------------------------- 1 | export const COMPONENT_USAGE_THEME_LIGHT = 'light'; 2 | export const COMPONENT_USAGE_THEME_DARK = 'dark'; 3 | export const COMPONENT_USAGE_THEME_NEUTRAL = 'neutral'; 4 | export const COMPONENT_USAGE_ACCEPTABLE_THEMES = [ 5 | COMPONENT_USAGE_THEME_LIGHT, 6 | COMPONENT_USAGE_THEME_DARK, 7 | COMPONENT_USAGE_THEME_NEUTRAL 8 | ]; 9 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentUsage/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentUsage.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentUsages/ComponentUsages.svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
Component usages
5 | 6 | 7 | 10 | 11 |
12 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentUsages/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentUsages.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentVariables/ComponentVariables.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | {#if constants.length} 16 | 17 | {/if} 18 | 19 | {#if constants.length && changable.length} 20 |
21 | {/if} 22 | 23 | {#if changable.length} 24 | 25 | {/if} 26 |
27 |
28 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentVariables/ComponentVariablesTable/ComponentVariablesTable.svelte: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 |
23 |
{title} export {type}
24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {#each data as item} 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | {/each} 49 | 50 |
NameTypeDefaultDescriptionNote
40 | {item.name} 41 | (definitions) 42 | {typeof item.default}{JSON.stringify(item.default)}{@html md.render(item.description || '')}{@html md.render(item.note || '')}
51 |
52 |
53 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentVariables/ComponentVariablesTable/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentVariablesTable.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/ComponentVariables/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentVariables.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /build/interface/components/Component/index.js: -------------------------------------------------------------------------------- 1 | import Component from './Component.svelte'; 2 | import ComponentCode from './ComponentCode'; 3 | import ComponentDescription from './ComponentDescription'; 4 | import ComponentUsage from './ComponentUsage'; 5 | 6 | Component.Code = ComponentCode; 7 | Component.Description = ComponentDescription; 8 | Component.Usage = ComponentUsage; 9 | export default Component; 10 | -------------------------------------------------------------------------------- /build/interface/components/Source/Source.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 |
22 |
23 | {#each lines as {indent, source}, index} 24 |
{index + 1}
25 | {/each} 26 |
27 | 28 |
29 | {#each lines as {indent, source}, index} 30 |
31 | {@html getLineIndent(indent)}{@html source} 32 |
33 | {/each} 34 |
35 |
36 | -------------------------------------------------------------------------------- /build/interface/components/Source/index.js: -------------------------------------------------------------------------------- 1 | import Component from './Source.svelte'; 2 | 3 | export default Component; 4 | -------------------------------------------------------------------------------- /build/interface/helpers/convertCamelToCode.js: -------------------------------------------------------------------------------- 1 | export default function convertCamelToCode(string) { 2 | const camelCase = string[0].toLowerCase() + string.substr(1); 3 | return camelCase.replace(/[A-Z]/g, a => `-${a.toLowerCase()}`); 4 | } 5 | -------------------------------------------------------------------------------- /build/interface/helpers/convertCodeToComponent.js: -------------------------------------------------------------------------------- 1 | export default function convertCodeToComponent(string) { 2 | const componentCase = string[0].toUpperCase() + string.substr(1); 3 | return componentCase.replace(/-([a-z])/g, (_, a) => a.toUpperCase()); 4 | } 5 | -------------------------------------------------------------------------------- /build/interface/helpers/decodeSpecialChars.js: -------------------------------------------------------------------------------- 1 | export default function decodeSpecialChars(source) { 2 | return source 3 | .replace(/&/g, '&') 4 | .replace(/>/g, '>') 5 | .replace(/</g, '<') 6 | .replace(/"/g, '"'); 7 | } 8 | -------------------------------------------------------------------------------- /build/interface/helpers/filterObject.js: -------------------------------------------------------------------------------- 1 | export default function filterObject(data, filter) { 2 | const names = Object.keys(data); 3 | const filtered = names.filter((name) => filter(name, data[name])); 4 | return filtered.reduce((stack, name) => { 5 | stack[name] = data[name]; 6 | return stack; 7 | }, {}); 8 | } 9 | -------------------------------------------------------------------------------- /build/interface/helpers/isDeclarationContext.js: -------------------------------------------------------------------------------- 1 | export default function isDeclarationContext({ variables, functions, classes } = {}) { 2 | const isVariables = variables && Object.keys(variables).length; 3 | const isFunctions = functions && Object.keys(functions).length; 4 | const isClasses = classes && Object.keys(classes).length; 5 | return isVariables || isFunctions || isClasses; 6 | } 7 | -------------------------------------------------------------------------------- /build/interface/helpers/resolveHighlightedSource.js: -------------------------------------------------------------------------------- 1 | const hljs = require('highlight.js'); 2 | 3 | export default function resolveHighlightedSource(source, lang = 'html') { 4 | // highlight source code 5 | const highlighted = hljs.highlight(lang, source).value; 6 | 7 | // split source code into lines with indent value 8 | const lines = highlighted.split('\n').map((line) => { 9 | const match = line.match(/^([\t\s]*)(.*?)$/); 10 | const indent = match[1].length; 11 | const source = match[2]; 12 | return { indent, source }; 13 | }); 14 | 15 | // find minimum indent to offset indents 16 | const filledLines = lines.filter((line) => line.source.replace(/^[\t\s]+/, '').length); 17 | const minimumIndent = Math.min(...filledLines.map((line) => line.indent)); 18 | 19 | // recalculate indents based on offset 20 | const changedLines = lines.map((line) => { 21 | const indent = line.indent > minimumIndent 22 | ? line.indent - minimumIndent : 0; 23 | return { ...line, indent }; 24 | }); 25 | 26 | // mark empty lines at the beginning as empty 27 | for (let i = 0; i < changedLines.length; i++) { 28 | if(!changedLines[i].source) { 29 | changedLines[i] = undefined; 30 | continue; 31 | } 32 | 33 | break; 34 | } 35 | 36 | // mark empty lines at the ending as empty 37 | for (let i = changedLines.length - 1; i > 0; i--) { 38 | if(!changedLines[i].source) { 39 | changedLines[i] = undefined; 40 | continue; 41 | } 42 | 43 | break; 44 | } 45 | 46 | // return only non empty lines 47 | return changedLines.filter((line) => line); 48 | } 49 | -------------------------------------------------------------------------------- /build/interface/helpers/resolveMenuFromLibrary.js: -------------------------------------------------------------------------------- 1 | import convertCamelToCode from './convertCamelToCode'; 2 | 3 | export default function resolveMenuFromLibrary(index, basePath = '/') { 4 | const menu = index.map(({ name }) => ({ 5 | path: basePath + convertCamelToCode(name) + '/', 6 | label: name, 7 | })); 8 | 9 | menu.sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0)); 10 | 11 | return menu; 12 | } 13 | -------------------------------------------------------------------------------- /build/interface/index.js: -------------------------------------------------------------------------------- 1 | import convertCamelToCode from './helpers/convertCamelToCode'; 2 | import convertCodeToComponent from './helpers/convertCodeToComponent'; 3 | import decodeSpecialChars from './helpers/decodeSpecialChars'; 4 | import filterObject from './helpers/filterObject'; 5 | import isDeclarationContext from './helpers/isDeclarationContext'; 6 | import resolveHighlightedSource from './helpers/resolveHighlightedSource'; 7 | import resolveMenuFromLibrary from './helpers/resolveMenuFromLibrary'; 8 | 9 | import Application from './components/Application'; 10 | import Component from './components/Component'; 11 | 12 | export { 13 | convertCamelToCode, 14 | convertCodeToComponent, 15 | decodeSpecialChars, 16 | filterObject, 17 | isDeclarationContext, 18 | resolveHighlightedSource, 19 | resolveMenuFromLibrary, 20 | 21 | Application, 22 | Component 23 | }; 24 | -------------------------------------------------------------------------------- /build/interface/stores.js: -------------------------------------------------------------------------------- 1 | import { writable } from 'svelte/store'; 2 | 3 | export const source = writable(false); 4 | export const line = writable(false); 5 | -------------------------------------------------------------------------------- /build/interface/styles/global.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gustarus/svelte-doc-generator/a16e6d0705821ef3be9d3b21c184636bd31b2f31/build/interface/styles/global.css -------------------------------------------------------------------------------- /build/interface/styles/reset.css: -------------------------------------------------------------------------------- 1 | a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,button,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:"";content:none}table{border-collapse:collapse;border-spacing:0} -------------------------------------------------------------------------------- /build/system/base/Base.d.ts: -------------------------------------------------------------------------------- 1 | export default class Base extends Object { 2 | private _defaults; 3 | config: C; 4 | constructor(config: C); 5 | get defaults(): C; 6 | set defaults(config: C); 7 | private configure; 8 | } 9 | -------------------------------------------------------------------------------- /build/system/base/Base.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class Base extends Object { 4 | constructor(config) { 5 | super(); 6 | this.configure(config); 7 | } 8 | get defaults() { 9 | return this._defaults; 10 | } 11 | set defaults(config) { 12 | this._defaults = { ...this._defaults, ...config }; 13 | } 14 | configure(custom = {}) { 15 | const config = { ...this.defaults, ...custom }; 16 | for (const name in config) { 17 | if (typeof config[name] !== 'undefined') { 18 | this[name] = config[name]; 19 | } 20 | } 21 | return this; 22 | } 23 | } 24 | exports.default = Base; 25 | ; 26 | -------------------------------------------------------------------------------- /build/system/base/Object.d.ts: -------------------------------------------------------------------------------- 1 | export default abstract class Object { 2 | static create(config: { 3 | [key: string]: any; 4 | }): Object; 5 | } 6 | -------------------------------------------------------------------------------- /build/system/base/Object.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class Object { 4 | static create(config) { 5 | throw new ReferenceError('Not implemented yet'); 6 | } 7 | ; 8 | } 9 | exports.default = Object; 10 | ; 11 | -------------------------------------------------------------------------------- /build/system/base/Source.d.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import DOMParser from 'dom-parser'; 3 | export declare namespace SourceSpace { 4 | type Config = { 5 | path: string; 6 | }; 7 | type Position = { 8 | line: number; 9 | column: number; 10 | }; 11 | } 12 | export default abstract class Source extends Base { 13 | private _path; 14 | private _source?; 15 | private _dom?; 16 | set path(value: string); 17 | get path(): string; 18 | get source(): string; 19 | set source(content: string); 20 | get dom(): DOMParser.Dom; 21 | save(): void; 22 | reset(): void; 23 | getPosition(position: number): SourceSpace.Position; 24 | } 25 | -------------------------------------------------------------------------------- /build/system/base/Source.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const path = __importStar(require("path")); 14 | const Base_1 = __importDefault(require("../base/Base")); 15 | const fs = __importStar(require("fs")); 16 | const dom_parser_1 = __importDefault(require("dom-parser")); 17 | class Source extends Base_1.default { 18 | set path(value) { 19 | this._path = path.resolve(value); 20 | } 21 | get path() { 22 | return this._path; 23 | } 24 | get source() { 25 | if (!this._source) { 26 | this._source = fs.readFileSync(this.path).toString(); 27 | } 28 | return this._source; 29 | } 30 | set source(content) { 31 | this._source = content; 32 | this.save(); 33 | } 34 | get dom() { 35 | if (!this._dom) { 36 | const parser = new dom_parser_1.default(); 37 | this._dom = parser.parseFromString(this.source); 38 | } 39 | return this._dom; 40 | } 41 | save() { 42 | fs.writeFileSync(this.path, this.source); 43 | this.reset(); 44 | } 45 | reset() { 46 | delete this._source; 47 | delete this._dom; 48 | } 49 | getPosition(position) { 50 | const part = this.source.substr(0, position); 51 | const lines = part.split('\n'); 52 | const line = lines.length; 53 | const column = lines[lines.length - 1].length; 54 | return { line, column }; 55 | } 56 | } 57 | exports.default = Source; 58 | -------------------------------------------------------------------------------- /build/system/base/SvelteSource.d.ts: -------------------------------------------------------------------------------- 1 | import { Ast } from 'svelte/types/compiler/interfaces'; 2 | import Source from './Source'; 3 | import Script from "../models/Script"; 4 | export declare namespace SvelteComponentSpace { 5 | type Config = {}; 6 | } 7 | export default abstract class SvelteSource extends Source { 8 | private _module; 9 | private _instance; 10 | private _tree?; 11 | get tree(): Ast; 12 | get module(): Script; 13 | get instance(): Script; 14 | reset(): void; 15 | } 16 | -------------------------------------------------------------------------------- /build/system/base/SvelteSource.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const compiler_1 = require("svelte/compiler"); 7 | const Source_1 = __importDefault(require("./Source")); 8 | const Script_1 = __importDefault(require("../models/Script")); 9 | class SvelteSource extends Source_1.default { 10 | get tree() { 11 | if (!this._tree) { 12 | try { 13 | this._tree = compiler_1.parse(this.source); 14 | } 15 | catch (error) { 16 | error.message = `Unable to parse svelte component '${this.path}' with an error '${error.message}'`; 17 | throw error; 18 | } 19 | } 20 | return this._tree; 21 | } 22 | get module() { 23 | if (!this._module && this.tree.module) { 24 | this._module = new Script_1.default({ path: this.path, data: this.tree.module }); 25 | } 26 | return this._module; 27 | } 28 | get instance() { 29 | if (!this._instance && this.tree.instance) { 30 | this._instance = new Script_1.default({ path: this.path, data: this.tree.instance }); 31 | } 32 | return this._instance; 33 | } 34 | reset() { 35 | super.reset(); 36 | delete this._tree; 37 | } 38 | } 39 | exports.default = SvelteSource; 40 | -------------------------------------------------------------------------------- /build/system/cli.d.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | export {}; 3 | -------------------------------------------------------------------------------- /build/system/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | var __importStar = (this && this.__importStar) || function (mod) { 4 | if (mod && mod.__esModule) return mod; 5 | var result = {}; 6 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 7 | result["default"] = mod; 8 | return result; 9 | }; 10 | var __importDefault = (this && this.__importDefault) || function (mod) { 11 | return (mod && mod.__esModule) ? mod : { "default": mod }; 12 | }; 13 | Object.defineProperty(exports, "__esModule", { value: true }); 14 | const path = __importStar(require("path")); 15 | const commander_1 = __importDefault(require("commander")); 16 | const generate_1 = __importDefault(require("./cli/generate")); 17 | const watch_1 = __importDefault(require("./cli/watch")); 18 | const setup_1 = __importDefault(require("./cli/setup")); 19 | const constants_1 = require("./constants"); 20 | const Package_1 = __importDefault(require("./models/Package")); 21 | const pathToPackage = path.resolve(constants_1.PATH_ROOT, 'package.json'); 22 | const that = new Package_1.default({ path: pathToPackage }); 23 | // display description 24 | commander_1.default 25 | .version(that.version) 26 | .description('Tool to generate svelte documentation'); 27 | // bind commands 28 | generate_1.default(commander_1.default); 29 | watch_1.default(commander_1.default); 30 | setup_1.default(commander_1.default); 31 | // parse arguments 32 | commander_1.default.parse(process.argv); 33 | // display help command 34 | if (!process.argv.slice(2).length) { 35 | commander_1.default.help(); 36 | } 37 | -------------------------------------------------------------------------------- /build/system/cli/generate.d.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | export default function generate(program: Command): void; 3 | -------------------------------------------------------------------------------- /build/system/cli/setup.d.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | export default function setup(program: Command): void; 3 | -------------------------------------------------------------------------------- /build/system/cli/setup.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const fs = __importStar(require("fs-extra")); 14 | const path = __importStar(require("path")); 15 | const colors_1 = __importDefault(require("colors")); 16 | const displayCommandGreetings_1 = __importDefault(require("./../helpers/displayCommandGreetings")); 17 | const displayCommandDone_1 = __importDefault(require("../helpers/displayCommandDone")); 18 | const displayCommandStep_1 = __importDefault(require("../helpers/displayCommandStep")); 19 | const constants_1 = require("../constants"); 20 | function setup(program) { 21 | program 22 | .command('setup') 23 | .description('Setup target project with the template') 24 | .requiredOption('--project ', 'Path to the target project (where you store package.json for your project)') 25 | .action((cmd) => { 26 | displayCommandGreetings_1.default(cmd); 27 | const sourcePath = path.resolve(constants_1.PATH_TEMPLATE); 28 | const targetPath = path.resolve(cmd.project); 29 | displayCommandStep_1.default(cmd, colors_1.default.blue.bold('Setup your project with the documentation site template')); 30 | displayCommandStep_1.default(cmd, `${colors_1.default.bold('Path to the template')}: ${colors_1.default.italic(sourcePath)}`); 31 | displayCommandStep_1.default(cmd, `${colors_1.default.bold('Path to the project')}: ${colors_1.default.italic(targetPath)}`); 32 | let conflictsCounter = 0; 33 | function filter(src, dest) { 34 | const srcStat = fs.statSync(src); 35 | if (srcStat.isFile()) { 36 | displayCommandStep_1.default(cmd, ` ${colors_1.default.blue('Copy template file...')}`); 37 | displayCommandStep_1.default(cmd, ` From '${colors_1.default.italic(src)}'`); 38 | displayCommandStep_1.default(cmd, ` To '${colors_1.default.italic(dest)}'`); 39 | if (fs.existsSync(dest)) { 40 | conflictsCounter++; 41 | displayCommandStep_1.default(cmd, ` ${colors_1.default.yellow('File already exists: skipped;')}`); 42 | return false; 43 | } 44 | } 45 | return true; 46 | } 47 | displayCommandStep_1.default(cmd, 'Copy every file from the template...'); 48 | fs.copySync(sourcePath, targetPath, { recursive: true, overwrite: true, filter }); 49 | if (conflictsCounter) { 50 | displayCommandStep_1.default(cmd, colors_1.default.yellow(`${colors_1.default.bold(conflictsCounter.toString())} conflicts were found: take a look at yellow text above`)); 51 | } 52 | displayCommandDone_1.default(cmd); 53 | }); 54 | } 55 | exports.default = setup; 56 | ; 57 | -------------------------------------------------------------------------------- /build/system/cli/watch.d.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | export default function watch(program: Command): void; 3 | -------------------------------------------------------------------------------- /build/system/constants.d.ts: -------------------------------------------------------------------------------- 1 | import Import from "./imports/Import"; 2 | import DefaultImport from "./imports/DefaultImport"; 3 | import NamespaceImport from "./imports/NamespaceImport"; 4 | export declare const PATH_ROOT: string; 5 | export declare const PATH_TEMPLATE: string; 6 | export declare const DOCUMENTATION_PATH_SUFFIX = "Documentation"; 7 | export declare const DOCUMENTATION_PATH_EXTENSION = "svelte"; 8 | export declare const DOCUMENTATION_VARIABLE_RAW: string; 9 | export declare const DOCUMENTATION_VARIABLE_DEFINITION: string; 10 | export declare const DOCUMENTATION_VARIABLE_INITIALIZATION: string; 11 | export declare const WATCH_DELAY = 1000; 12 | export declare const WATCH_TEMPLATES: string[]; 13 | export declare const IMPORT_SPECIFIER_TO_MODEL: { 14 | ImportSpecifier: typeof Import; 15 | ImportDefaultSpecifier: typeof DefaultImport; 16 | ImportNamespaceSpecifier: typeof NamespaceImport; 17 | }; 18 | -------------------------------------------------------------------------------- /build/system/constants.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const path = __importStar(require("path")); 14 | const resolvePackagePath_1 = __importDefault(require("./helpers/resolvePackagePath")); 15 | const Import_1 = __importDefault(require("./imports/Import")); 16 | const DefaultImport_1 = __importDefault(require("./imports/DefaultImport")); 17 | const NamespaceImport_1 = __importDefault(require("./imports/NamespaceImport")); 18 | const generateUniqueIdentifier_1 = __importDefault(require("./helpers/generateUniqueIdentifier")); 19 | exports.PATH_ROOT = resolvePackagePath_1.default(__dirname); 20 | exports.PATH_TEMPLATE = path.resolve(exports.PATH_ROOT, 'template'); 21 | exports.DOCUMENTATION_PATH_SUFFIX = 'Documentation'; 22 | exports.DOCUMENTATION_PATH_EXTENSION = 'svelte'; 23 | exports.DOCUMENTATION_VARIABLE_RAW = generateUniqueIdentifier_1.default(); 24 | exports.DOCUMENTATION_VARIABLE_DEFINITION = generateUniqueIdentifier_1.default(); 25 | exports.DOCUMENTATION_VARIABLE_INITIALIZATION = generateUniqueIdentifier_1.default(); 26 | exports.WATCH_DELAY = 1000; 27 | exports.WATCH_TEMPLATES = ['/**/*']; 28 | exports.IMPORT_SPECIFIER_TO_MODEL = { 29 | ImportSpecifier: Import_1.default, 30 | ImportDefaultSpecifier: DefaultImport_1.default, 31 | ImportNamespaceSpecifier: NamespaceImport_1.default 32 | }; 33 | -------------------------------------------------------------------------------- /build/system/exports/BaseExport.d.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { Declaration, ExportNamedDeclaration, Node } from 'estree'; 3 | import Location from '../models/Location'; 4 | export declare namespace BaseExportSpace { 5 | type Config = { 6 | data: ExportNamedDeclaration; 7 | }; 8 | type Result = {}; 9 | } 10 | export default abstract class BaseExport extends Base { 11 | data: ExportNamedDeclaration; 12 | abstract get declaration(): Declaration; 13 | abstract get name(): string; 14 | abstract get result(): BaseExportSpace.Result; 15 | get location(): Location; 16 | protected static resolveDefaultValue(node: Node): any; 17 | } 18 | -------------------------------------------------------------------------------- /build/system/exports/BaseExport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const Base_1 = __importDefault(require("../base/Base")); 7 | const Location_1 = __importDefault(require("../models/Location")); 8 | class BaseExport extends Base_1.default { 9 | get location() { 10 | const data = this.data.loc; 11 | return new Location_1.default({ data }); 12 | } 13 | static resolveDefaultValue(node) { 14 | if (node.type === 'Literal') { 15 | const literal = node; 16 | return literal.value; 17 | } 18 | else if (node.type === 'ObjectExpression') { 19 | // TODO Parse properties structure in desired value. 20 | // const objectExpression = assigment.right as ObjectExpression; 21 | return {}; 22 | } 23 | return undefined; 24 | } 25 | } 26 | exports.default = BaseExport; 27 | -------------------------------------------------------------------------------- /build/system/exports/ClassExport.d.ts: -------------------------------------------------------------------------------- 1 | import { ClassDeclaration } from 'estree'; 2 | import BaseExport, { BaseExportSpace } from './BaseExport'; 3 | export declare namespace ClassExportSpace { 4 | type Config = {}; 5 | type Result = {}; 6 | } 7 | export default class ClassExport extends BaseExport { 8 | get declaration(): ClassDeclaration; 9 | get name(): string; 10 | get result(): BaseExportSpace.Result; 11 | } 12 | -------------------------------------------------------------------------------- /build/system/exports/ClassExport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BaseExport_1 = __importDefault(require("./BaseExport")); 7 | class ClassExport extends BaseExport_1.default { 8 | get declaration() { 9 | throw new ReferenceError('Not implemented'); 10 | } 11 | get name() { 12 | throw new ReferenceError('Not implemented'); 13 | } 14 | get result() { 15 | throw new ReferenceError('Not implemented'); 16 | } 17 | } 18 | exports.default = ClassExport; 19 | -------------------------------------------------------------------------------- /build/system/exports/FunctionExport.d.ts: -------------------------------------------------------------------------------- 1 | import parse from 'comment-parser'; 2 | import { FunctionDeclaration } from 'estree'; 3 | import BaseExport from './BaseExport'; 4 | import Description from '../models/Description'; 5 | import { LocationSpace } from '../models/Location'; 6 | export declare namespace FunctionExportSpace { 7 | type Config = {}; 8 | type Result = { 9 | arguments: Argument[]; 10 | description: string | false; 11 | tags: parse.Tag[]; 12 | location: LocationSpace.Result; 13 | }; 14 | type Argument = { 15 | name: string; 16 | default?: any; 17 | }; 18 | } 19 | export default class FunctionExport extends BaseExport { 20 | get declaration(): FunctionDeclaration; 21 | get name(): string; 22 | get jsdoc(): parse.Comment | false; 23 | get description(): Description | false; 24 | get tags(): any; 25 | get arguments(): FunctionExportSpace.Argument[]; 26 | get result(): FunctionExportSpace.Result; 27 | } 28 | -------------------------------------------------------------------------------- /build/system/exports/FunctionExport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const comment_parser_1 = __importDefault(require("comment-parser")); 7 | const BaseExport_1 = __importDefault(require("./BaseExport")); 8 | const Description_1 = __importDefault(require("../models/Description")); 9 | class FunctionExport extends BaseExport_1.default { 10 | get declaration() { 11 | return this.data.declaration; 12 | } 13 | get name() { 14 | return this.declaration.id.name; 15 | } 16 | get jsdoc() { 17 | if (!this.data.leadingComments) { 18 | return false; 19 | } 20 | // parse only block comments 21 | const comment = this.data.leadingComments[0]; 22 | if (comment.type !== 'Block') { 23 | return false; 24 | } 25 | // parse only jsdoc comments 26 | // comment value should be like 27 | // `*\n* Hello!\n* @returns {string}\n` 28 | if (!comment.value.match(/^\*[^*]/)) { 29 | return false; 30 | } 31 | // make jsdoc comment block 32 | const raw = `/*${comment.value}*/`; 33 | const parsed = comment_parser_1.default(raw); 34 | if (!parsed) { 35 | return false; 36 | } 37 | return parsed[0]; 38 | } 39 | get description() { 40 | if (!this.jsdoc) { 41 | if (!this.data.leadingComments) { 42 | return false; 43 | } 44 | return new Description_1.default({ comments: this.data.leadingComments }); 45 | } 46 | const content = this.jsdoc.description; 47 | const data = { type: 'Block', value: content }; 48 | return new Description_1.default({ comments: [data] }); 49 | } 50 | get tags() { 51 | if (!this.jsdoc) { 52 | return []; 53 | } 54 | return this.jsdoc.tags; 55 | } 56 | get arguments() { 57 | const declaration = this.data.declaration; 58 | if (!declaration.params) { 59 | return []; 60 | } 61 | const args = []; 62 | for (const param of declaration.params) { 63 | let name = '?'; 64 | let value; 65 | if (param.type === 'Identifier') { 66 | const identifier = param; 67 | name = identifier.name; 68 | } 69 | else if (param.type === 'AssignmentPattern') { 70 | const assigment = param; 71 | const identifier = assigment.left; 72 | name = identifier.name; 73 | value = FunctionExport.resolveDefaultValue(assigment.right); 74 | } 75 | args.push({ name, default: value }); 76 | } 77 | return args; 78 | } 79 | get result() { 80 | return { 81 | arguments: this.arguments, 82 | description: this.description && this.description.markdown, 83 | tags: this.tags, 84 | location: this.location.result 85 | }; 86 | } 87 | } 88 | exports.default = FunctionExport; 89 | -------------------------------------------------------------------------------- /build/system/exports/VariableExport.d.ts: -------------------------------------------------------------------------------- 1 | import BaseExport from './BaseExport'; 2 | import { VariableDeclaration, VariableDeclarator } from 'estree'; 3 | import Description from '../models/Description'; 4 | import { LocationSpace } from '../models/Location'; 5 | export declare namespace VariableExportSpace { 6 | type Config = {}; 7 | type Result = { 8 | default: any; 9 | constant: boolean; 10 | description: string | undefined; 11 | note: string | undefined; 12 | location: LocationSpace.Result; 13 | }; 14 | } 15 | export default class VariableExport extends BaseExport { 16 | get declaration(): VariableDeclaration; 17 | get declarator(): VariableDeclarator; 18 | get kind(): string; 19 | get constant(): boolean; 20 | get name(): string; 21 | get default(): any; 22 | get description(): Description | undefined; 23 | get note(): Description | undefined; 24 | get result(): VariableExportSpace.Result; 25 | } 26 | -------------------------------------------------------------------------------- /build/system/exports/VariableExport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BaseExport_1 = __importDefault(require("./BaseExport")); 7 | const Description_1 = __importDefault(require("../models/Description")); 8 | class VariableExport extends BaseExport_1.default { 9 | get declaration() { 10 | return this.data.declaration; 11 | } 12 | get declarator() { 13 | return this.declaration.declarations[0]; 14 | } 15 | get kind() { 16 | return this.declaration.kind; 17 | } 18 | get constant() { 19 | return this.kind === 'const'; 20 | } 21 | get name() { 22 | return this.declarator.id.name; 23 | } 24 | get default() { 25 | if (!this.declarator.init) { 26 | return undefined; 27 | } 28 | return VariableExport.resolveDefaultValue(this.declarator.init); 29 | } 30 | get description() { 31 | if (!this.data.leadingComments) { 32 | return undefined; 33 | } 34 | return new Description_1.default({ comments: this.data.leadingComments }); 35 | } 36 | get note() { 37 | if (!this.data.trailingComments) { 38 | return undefined; 39 | } 40 | return new Description_1.default({ comments: this.data.trailingComments }); 41 | } 42 | get result() { 43 | return { 44 | default: this.default, 45 | constant: this.constant, 46 | description: this.description && this.description.markdown, 47 | note: this.note && this.note.markdown, 48 | location: this.location.result 49 | }; 50 | } 51 | } 52 | exports.default = VariableExport; 53 | -------------------------------------------------------------------------------- /build/system/helpers/createEmptyDirectory.d.ts: -------------------------------------------------------------------------------- 1 | export default function createEmptyDirectory(path: string): void; 2 | -------------------------------------------------------------------------------- /build/system/helpers/createEmptyDirectory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const fs = __importStar(require("fs-extra")); 11 | function createEmptyDirectory(path) { 12 | fs.existsSync(path) && fs.removeSync(path); 13 | fs.mkdirSync(path, { recursive: true }); 14 | } 15 | exports.default = createEmptyDirectory; 16 | -------------------------------------------------------------------------------- /build/system/helpers/displayCommandDone.d.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | export default function displayCommandDone(cmd: Command): void; 3 | -------------------------------------------------------------------------------- /build/system/helpers/displayCommandDone.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const safe_1 = __importDefault(require("colors/safe")); 7 | const displayCommandStep_1 = __importDefault(require("./displayCommandStep")); 8 | function displayCommandDone(cmd) { 9 | displayCommandStep_1.default(cmd, safe_1.default.green('The task was successful')); 10 | } 11 | exports.default = displayCommandDone; 12 | ; 13 | -------------------------------------------------------------------------------- /build/system/helpers/displayCommandGreetings.d.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | export default function displayCommandGreetings(cmd: Command): void; 3 | -------------------------------------------------------------------------------- /build/system/helpers/displayCommandGreetings.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const safe_1 = __importDefault(require("colors/safe")); 7 | function displayCommandGreetings(cmd) { 8 | console.log(`[${safe_1.default.blue(cmd.name())}] ${cmd.description()}`); 9 | } 10 | exports.default = displayCommandGreetings; 11 | ; 12 | -------------------------------------------------------------------------------- /build/system/helpers/displayCommandStep.d.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | export default function displayCommandStep(cmd: Command, message: string): void; 3 | -------------------------------------------------------------------------------- /build/system/helpers/displayCommandStep.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const safe_1 = __importDefault(require("colors/safe")); 7 | const moment_1 = __importDefault(require("moment")); 8 | function displayCommandStep(cmd, message) { 9 | const timestamp = moment_1.default().format('HH:mm:ss'); 10 | console.log(`[${timestamp}] [${safe_1.default.blue(cmd.name())}] ${message}`); 11 | } 12 | exports.default = displayCommandStep; 13 | ; 14 | -------------------------------------------------------------------------------- /build/system/helpers/encodeSpecialChars.d.ts: -------------------------------------------------------------------------------- 1 | export default function encodeSpecialChars(source: string): string; 2 | -------------------------------------------------------------------------------- /build/system/helpers/encodeSpecialChars.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function encodeSpecialChars(source) { 4 | return source 5 | .replace(/&/g, '&') 6 | .replace(/>/g, '>') 7 | .replace(/ { 5 | return { 6 | name: generator.name, 7 | title: generator.documentation.title, 8 | }; 9 | }); 10 | } 11 | exports.default = resolveMenuFromGenerators; 12 | -------------------------------------------------------------------------------- /build/system/helpers/resolvePackagePath.d.ts: -------------------------------------------------------------------------------- 1 | export default function resolvePackagePath(directory: string): string; 2 | -------------------------------------------------------------------------------- /build/system/helpers/resolvePackagePath.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const fs = __importStar(require("fs-extra")); 11 | const path = __importStar(require("path")); 12 | function resolvePackagePath(directory) { 13 | const possible = path.resolve(directory, 'package.json'); 14 | if (!fs.existsSync(possible)) { 15 | const parent = path.dirname(directory); 16 | return resolvePackagePath(parent); 17 | } 18 | return directory; 19 | } 20 | exports.default = resolvePackagePath; 21 | -------------------------------------------------------------------------------- /build/system/helpers/resolveRelativeImports.d.ts: -------------------------------------------------------------------------------- 1 | export default function resolveRelativeImports(source: string, originalPath: string, targetPath: string): string; 2 | -------------------------------------------------------------------------------- /build/system/helpers/resolveRelativeImports.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const path = __importStar(require("path")); 11 | function resolveRelativeImports(source, originalPath, targetPath) { 12 | const { dir: originalDir } = path.parse(originalPath); 13 | const { dir: targetDir } = path.parse(targetPath); 14 | const relative = path.relative(targetDir, originalDir); 15 | const relativeDir = path.dirname(relative); 16 | // please, keep order of the replacements 17 | // this is important to replace `../` first 18 | // and then replace `./` 19 | return source 20 | .replace(/(import\s*["'])(\.\.\/)/g, `$1${relativeDir}/`) 21 | .replace(/(import\s*["'])(\.\/)/g, `$1${relative}/`) 22 | .replace(/(from\s*["'])(\.\.\/)/g, `$1${relativeDir}/`) 23 | .replace(/(from\s*["'])(\.\/)/g, `$1${relative}/`); 24 | } 25 | exports.default = resolveRelativeImports; 26 | -------------------------------------------------------------------------------- /build/system/imports/BaseImport.d.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { BaseModuleSpecifier, Property, MemberExpression } from 'estree'; 3 | import Script from "../models/Script"; 4 | export declare namespace BaseImportSpace { 5 | type Config = { 6 | script: Script; 7 | specifier: BaseModuleSpecifier; 8 | }; 9 | } 10 | export default abstract class BaseImport extends Base { 11 | script: Script; 12 | specifier: BaseModuleSpecifier; 13 | abstract resolveTags(namePath: string[]): string[]; 14 | resolveTagReplacements(name: string, inner: string[]): string[]; 15 | resolveTagReplacementsFromProperty(property: Property, path: string[]): string[]; 16 | resolveTagNestedPath(memberExpression: MemberExpression, suffix?: string[]): string[]; 17 | } 18 | -------------------------------------------------------------------------------- /build/system/imports/BaseImport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const Base_1 = __importDefault(require("../base/Base")); 7 | class BaseImport extends Base_1.default { 8 | resolveTagReplacements(name, inner) { 9 | const path = [name, ...inner]; 10 | let tags = [path.join('.')]; 11 | const declarations = this.script.data.content.body 12 | .filter((node) => node.type === 'VariableDeclaration'); 13 | for (const declaration of declarations) { 14 | for (const declarator of declaration.declarations) { 15 | if (declarator.init) { 16 | if (declarator.init.type === 'Identifier') { 17 | if (declarator.init.name === name) { 18 | if (declarator.id.type === 'ObjectPattern') { 19 | for (const property of declarator.id.properties) { 20 | tags = [...tags, ...this.resolveTagReplacementsFromProperty(property, inner)]; 21 | } 22 | } 23 | } 24 | } 25 | else if (declarator.init.type === 'MemberExpression') { 26 | const nestedPath = this.resolveTagNestedPath(declarator.init); 27 | let valid = true; 28 | for (let i = 0; i < nestedPath.length; i++) { 29 | if (nestedPath[i] !== path[i]) { 30 | valid = false; 31 | break; 32 | } 33 | } 34 | if (valid) { 35 | const declarationPath = path.slice(nestedPath.length - 1); 36 | tags.push(declarationPath.join('.')); 37 | } 38 | } 39 | else { 40 | // TODO 41 | } 42 | } 43 | } 44 | } 45 | return tags; 46 | } 47 | resolveTagReplacementsFromProperty(property, path) { 48 | const base = path[0]; 49 | const key = property.key; 50 | if (key.name === base) { 51 | if (property.value.type === 'ObjectPattern') { 52 | let tags = []; 53 | for (const child of property.value.properties) { 54 | tags = [...tags, ...this.resolveTagReplacementsFromProperty(child, path.slice(1))]; 55 | } 56 | return tags; 57 | } 58 | else if (property.value.type === 'Identifier') { 59 | return [path.join('.')]; 60 | } 61 | else { 62 | throw new Error('todo'); 63 | } 64 | } 65 | return []; 66 | } 67 | resolveTagNestedPath(memberExpression, suffix = []) { 68 | if (!memberExpression.object) { 69 | throw Error('todo'); 70 | } 71 | const propertyIdentifier = memberExpression.property; 72 | const combinedSuffix = [propertyIdentifier.name, ...suffix]; 73 | if (memberExpression.object.type === 'MemberExpression') { // nested expressions 74 | const object = memberExpression.object; 75 | return this.resolveTagNestedPath(object, combinedSuffix); 76 | } 77 | else if (memberExpression.object.type === 'Identifier') { 78 | const id = memberExpression.object; 79 | return [id.name, ...combinedSuffix]; 80 | } 81 | else { 82 | throw Error('todo'); 83 | } 84 | } 85 | } 86 | exports.default = BaseImport; 87 | -------------------------------------------------------------------------------- /build/system/imports/DefaultImport.d.ts: -------------------------------------------------------------------------------- 1 | import { ImportDefaultSpecifier, ImportNamespaceSpecifier } from 'estree'; 2 | import BaseImport from './BaseImport'; 3 | export declare namespace DefaultImportSpace { 4 | type Config = { 5 | specifier: ImportDefaultSpecifier; 6 | }; 7 | } 8 | export default class DefaultImport extends BaseImport { 9 | specifier: ImportNamespaceSpecifier; 10 | resolveTags(pathName: string[]): string[]; 11 | } 12 | -------------------------------------------------------------------------------- /build/system/imports/DefaultImport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BaseImport_1 = __importDefault(require("./BaseImport")); 7 | class DefaultImport extends BaseImport_1.default { 8 | resolveTags(pathName) { 9 | throw new ReferenceError('Not implemented'); 10 | } 11 | } 12 | exports.default = DefaultImport; 13 | -------------------------------------------------------------------------------- /build/system/imports/Import.d.ts: -------------------------------------------------------------------------------- 1 | import { ImportSpecifier } from 'estree'; 2 | import BaseImport from './BaseImport'; 3 | export declare namespace ImportSpace { 4 | type Config = { 5 | specifier: ImportSpecifier; 6 | }; 7 | } 8 | export default class Import extends BaseImport { 9 | specifier: ImportSpecifier; 10 | resolveTags(namePath: string[]): string[]; 11 | } 12 | -------------------------------------------------------------------------------- /build/system/imports/Import.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BaseImport_1 = __importDefault(require("./BaseImport")); 7 | class Import extends BaseImport_1.default { 8 | resolveTags(namePath) { 9 | const base = namePath[0]; 10 | if (this.specifier.imported.name === base) { 11 | return this.resolveTagReplacements(this.specifier.local.name, namePath.slice(1)); 12 | } 13 | return []; 14 | } 15 | } 16 | exports.default = Import; 17 | -------------------------------------------------------------------------------- /build/system/imports/NamespaceImport.d.ts: -------------------------------------------------------------------------------- 1 | import { ImportNamespaceSpecifier } from 'estree'; 2 | import BaseImport from './BaseImport'; 3 | export declare namespace NamespaceImportSpace { 4 | type Config = { 5 | specifier: ImportNamespaceSpecifier; 6 | }; 7 | } 8 | export default class NamespaceImport extends BaseImport { 9 | specifier: ImportNamespaceSpecifier; 10 | resolveTags(namePath: string[]): string[]; 11 | } 12 | -------------------------------------------------------------------------------- /build/system/imports/NamespaceImport.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BaseImport_1 = __importDefault(require("./BaseImport")); 7 | class NamespaceImport extends BaseImport_1.default { 8 | resolveTags(namePath) { 9 | return this.resolveTagReplacements(this.specifier.local.name, namePath); 10 | } 11 | } 12 | exports.default = NamespaceImport; 13 | -------------------------------------------------------------------------------- /build/system/models/Attribute.d.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | export declare namespace AttributeSpace { 3 | type Config = { 4 | name: string; 5 | value: any; 6 | }; 7 | } 8 | export default class Attribute extends Base { 9 | name: string; 10 | value: any; 11 | get raw(): string; 12 | get compiled(): string; 13 | } 14 | -------------------------------------------------------------------------------- /build/system/models/Attribute.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const Base_1 = __importDefault(require("../base/Base")); 7 | const Variable_1 = __importDefault(require("./Variable")); 8 | class Attribute extends Base_1.default { 9 | get raw() { 10 | return `${this.name}=${this.compiled}`; 11 | } 12 | get compiled() { 13 | if (this.value instanceof Variable_1.default) { 14 | return `{${this.value.name}}`; 15 | } 16 | const formatted = this.value 17 | .replace(/\n/g, '\\n') 18 | .replace(/"/g, '\\"'); 19 | return `"${formatted}"`; 20 | } 21 | } 22 | exports.default = Attribute; 23 | -------------------------------------------------------------------------------- /build/system/models/Component.d.ts: -------------------------------------------------------------------------------- 1 | import { ScriptSpace } from './Script'; 2 | import SvelteSource from '../base/SvelteSource'; 3 | export declare namespace ComponentSpace { 4 | type Config = { 5 | path: string; 6 | }; 7 | type Result = { 8 | module: ScriptSpace.Definition | undefined; 9 | instance: ScriptSpace.Definition | undefined; 10 | }; 11 | } 12 | export default class Component extends SvelteSource { 13 | get definition(): ComponentSpace.Result; 14 | } 15 | -------------------------------------------------------------------------------- /build/system/models/Component.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const SvelteSource_1 = __importDefault(require("../base/SvelteSource")); 7 | class Component extends SvelteSource_1.default { 8 | get definition() { 9 | return { 10 | module: this.module 11 | ? this.module.definition : undefined, 12 | instance: this.instance 13 | ? this.instance.definition : undefined 14 | }; 15 | } 16 | } 17 | exports.default = Component; 18 | -------------------------------------------------------------------------------- /build/system/models/Description.d.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | export declare namespace DescriptionSpace { 3 | type Config = { 4 | comments: Data[]; 5 | }; 6 | type Data = { 7 | type: string; 8 | value: string; 9 | }; 10 | } 11 | export default class Description extends Base { 12 | comments: DescriptionSpace.Data[]; 13 | get markdown(): string; 14 | } 15 | -------------------------------------------------------------------------------- /build/system/models/Description.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const Base_1 = __importDefault(require("../base/Base")); 7 | const resolveMarkdownFromComment_1 = __importDefault(require("../helpers/resolveMarkdownFromComment")); 8 | class Description extends Base_1.default { 9 | get markdown() { 10 | const strings = this.comments.map((comment) => comment.value); 11 | return strings.map(resolveMarkdownFromComment_1.default).join(' \n'); 12 | } 13 | } 14 | exports.default = Description; 15 | -------------------------------------------------------------------------------- /build/system/models/Dictionary.d.ts: -------------------------------------------------------------------------------- 1 | import Source from '../base/Source'; 2 | import { ItemType } from '../types/ItemType'; 3 | export declare namespace IndexSpace { 4 | type Config = { 5 | items: ItemType[]; 6 | }; 7 | } 8 | export default class Dictionary extends Source { 9 | items: ItemType[]; 10 | generate(): void; 11 | } 12 | -------------------------------------------------------------------------------- /build/system/models/Dictionary.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const fs = __importStar(require("fs-extra")); 14 | const Source_1 = __importDefault(require("../base/Source")); 15 | class Dictionary extends Source_1.default { 16 | generate() { 17 | const names = this.items.map(({ name }) => name); 18 | const imports = this.items.map(({ name }) => `import ${name} from './${name}';`); 19 | const items = this.items.map(({ name, title }) => { 20 | const slashed = (title || name).replace(/'/g, '\\\''); 21 | return `{ name: '${name}', title: '${slashed}', component: ${name} }`; 22 | }); 23 | const exportDefault = `export default [\n ${items.join(',\n ')}\n];`; 24 | const exportCollection = `export { ${names.join(', ')} };`; 25 | const content = `${imports.join('\n')}\n\n${exportDefault}\n\n${exportCollection}`; 26 | fs.writeFileSync(this.path, content); 27 | } 28 | } 29 | exports.default = Dictionary; 30 | -------------------------------------------------------------------------------- /build/system/models/Documentation.d.ts: -------------------------------------------------------------------------------- 1 | import Component from './Component'; 2 | import SvelteSource from '../base/SvelteSource'; 3 | import Package from './Package'; 4 | import UsagePartial from '../partials/UsagePartial'; 5 | import MainPartial from '../partials/MainPartial'; 6 | import { PartialType } from '../types/PartialType'; 7 | import Variable from './Variable'; 8 | import DescriptionPartial from '../partials/DescriptionPartial'; 9 | export declare namespace DocumentationSpace { 10 | type Config = { 11 | package: Package; 12 | component: Component; 13 | }; 14 | } 15 | export default class Documentation extends SvelteSource { 16 | package: Package; 17 | component: Component; 18 | get title(): string; 19 | get main(): MainPartial | undefined; 20 | get description(): DescriptionPartial | undefined; 21 | get usages(): UsagePartial[]; 22 | get partials(): PartialType[]; 23 | apply(replacement: PartialType): Variable[]; 24 | define(variables: Variable[]): void; 25 | private findPartials; 26 | private findPartial; 27 | private resolveTagAliases; 28 | private resolveTagAliasesFromScript; 29 | private static findInlineComponentByTagAliases; 30 | } 31 | -------------------------------------------------------------------------------- /build/system/models/Generator.d.ts: -------------------------------------------------------------------------------- 1 | import Package from './Package'; 2 | import Documentation from './Documentation'; 3 | import Base from '../base/Base'; 4 | import Variable from './Variable'; 5 | export declare namespace GeneratorSpace { 6 | type Config = { 7 | name: string; 8 | package: Package; 9 | directory: string; 10 | documentation: Documentation; 11 | }; 12 | } 13 | export default class Generator extends Base { 14 | readonly fileNameIndex = "index.js"; 15 | readonly fileNameDocumentation = "Documentation.svelte"; 16 | name: string; 17 | package: Package; 18 | directory: string; 19 | documentation: Documentation; 20 | get pathToIndex(): string; 21 | get pathToDocumentation(): string; 22 | get variables(): Variable[]; 23 | generate(): void; 24 | } 25 | -------------------------------------------------------------------------------- /build/system/models/Generator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const fs = __importStar(require("fs-extra")); 14 | const path = __importStar(require("path")); 15 | const Documentation_1 = __importDefault(require("./Documentation")); 16 | const Base_1 = __importDefault(require("../base/Base")); 17 | const resolveRelativeImports_1 = __importDefault(require("../helpers/resolveRelativeImports")); 18 | const Variable_1 = __importDefault(require("./Variable")); 19 | const constants_1 = require("../constants"); 20 | const encodeSpecialChars_1 = __importDefault(require("../helpers/encodeSpecialChars")); 21 | class Generator extends Base_1.default { 22 | constructor() { 23 | super(...arguments); 24 | this.fileNameIndex = 'index.js'; 25 | this.fileNameDocumentation = 'Documentation.svelte'; 26 | } 27 | get pathToIndex() { 28 | return path.resolve(this.directory, this.fileNameIndex); 29 | } 30 | get pathToDocumentation() { 31 | return path.resolve(this.directory, this.fileNameDocumentation); 32 | } 33 | get variables() { 34 | const variables = []; 35 | // retrieve documentation variables 36 | const raw = encodeSpecialChars_1.default(this.documentation.component.source); 37 | const definition = this.documentation.component.definition; 38 | const initialization = this.documentation.instance.definition; 39 | // create variables 40 | variables.push(new Variable_1.default({ name: constants_1.DOCUMENTATION_VARIABLE_RAW, value: raw })); 41 | variables.push(new Variable_1.default({ name: constants_1.DOCUMENTATION_VARIABLE_DEFINITION, value: definition })); 42 | variables.push(new Variable_1.default({ name: constants_1.DOCUMENTATION_VARIABLE_INITIALIZATION, value: initialization })); 43 | return variables; 44 | } 45 | generate() { 46 | // reset target documentation file if exists 47 | fs.writeFileSync(this.pathToDocumentation, this.documentation.source); 48 | // create documentation clone from cloned file 49 | const path = this.pathToDocumentation; 50 | const that = this.documentation.package; 51 | const component = this.documentation.component; 52 | const clone = new Documentation_1.default({ path, package: that, component }); 53 | // rebind all imports paths and update the file 54 | clone.source = resolveRelativeImports_1.default(clone.source, this.documentation.path, this.pathToDocumentation); 55 | // replace all partials 56 | // with generated source code 57 | // and process variables 58 | let globalVariables = this.variables; 59 | for (let i = 0; i < clone.partials.length; i++) { 60 | const partialVariables = clone.apply(clone.partials[i]); 61 | globalVariables = [...globalVariables, ...partialVariables]; 62 | } 63 | // define variables inside the documentation 64 | clone.define(globalVariables); 65 | // generate index file 66 | const content = `import Component from './${this.fileNameDocumentation}';\n\nexport default Component;`; 67 | fs.writeFileSync(this.pathToIndex, content); 68 | } 69 | } 70 | exports.default = Generator; 71 | -------------------------------------------------------------------------------- /build/system/models/Location.d.ts: -------------------------------------------------------------------------------- 1 | import { SourceLocation } from 'estree'; 2 | import Base from '../base/Base'; 3 | export declare namespace LocationSpace { 4 | type Config = { 5 | data: SourceLocation; 6 | }; 7 | type Result = SourceLocation; 8 | } 9 | export default class Location extends Base { 10 | data: SourceLocation; 11 | get result(): LocationSpace.Result; 12 | } 13 | -------------------------------------------------------------------------------- /build/system/models/Location.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const Base_1 = __importDefault(require("../base/Base")); 7 | class Location extends Base_1.default { 8 | get result() { 9 | return this.data; 10 | } 11 | } 12 | exports.default = Location; 13 | -------------------------------------------------------------------------------- /build/system/models/Package.d.ts: -------------------------------------------------------------------------------- 1 | import Source from '../base/Source'; 2 | export declare namespace PackageSpace { 3 | type Config = { 4 | path: string; 5 | }; 6 | type Data = { 7 | name: string; 8 | version: string; 9 | bin: { 10 | [key: string]: string; 11 | }; 12 | }; 13 | } 14 | export default class Package extends Source { 15 | get data(): PackageSpace.Data; 16 | get name(): string; 17 | get version(): string; 18 | get cli(): string; 19 | } 20 | -------------------------------------------------------------------------------- /build/system/models/Package.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const fs = __importStar(require("fs")); 14 | const Source_1 = __importDefault(require("../base/Source")); 15 | class Package extends Source_1.default { 16 | get data() { 17 | const content = fs.readFileSync(this.path).toString(); 18 | return JSON.parse(content); 19 | } 20 | get name() { 21 | return this.data.name; 22 | } 23 | get version() { 24 | return this.data.version; 25 | } 26 | get cli() { 27 | return this.data.bin[this.name]; 28 | } 29 | } 30 | exports.default = Package; 31 | -------------------------------------------------------------------------------- /build/system/models/Router.d.ts: -------------------------------------------------------------------------------- 1 | import Source from '../base/Source'; 2 | import { ItemType } from '../types/ItemType'; 3 | export declare namespace RouterSpace { 4 | type Config = { 5 | routes: ItemType[]; 6 | }; 7 | } 8 | export default class Router extends Source { 9 | routes: ItemType[]; 10 | generate(): void; 11 | } 12 | -------------------------------------------------------------------------------- /build/system/models/Router.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | var __importDefault = (this && this.__importDefault) || function (mod) { 10 | return (mod && mod.__esModule) ? mod : { "default": mod }; 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const fs = __importStar(require("fs-extra")); 14 | const Source_1 = __importDefault(require("../base/Source")); 15 | class Router extends Source_1.default { 16 | generate() { 17 | const imports = this.routes.map(({ name }) => `import ${name} from './${name}';`); 18 | const items = this.routes.map(({ name, title }) => { 19 | return `{ name: ${JSON.stringify(name)}, title: ${JSON.stringify(title)}, component: ${name} }`; 20 | }); 21 | const content = `${imports.join('\n')}\n\nexport default [\n ${items.join(',\n ')}\n];`; 22 | fs.writeFileSync(this.path, content); 23 | } 24 | } 25 | exports.default = Router; 26 | -------------------------------------------------------------------------------- /build/system/models/Script.d.ts: -------------------------------------------------------------------------------- 1 | import { ImportDeclaration } from 'estree'; 2 | import { Script as SvelteScript } from 'svelte/types/compiler/interfaces'; 3 | import FunctionExport, { FunctionExportSpace } from '../exports/FunctionExport'; 4 | import VariableExport, { VariableExportSpace } from '../exports/VariableExport'; 5 | import ClassExport, { ClassExportSpace } from '../exports/ClassExport'; 6 | import { ExportType } from '../types/ExportType'; 7 | import Source, { SourceSpace } from '../base/Source'; 8 | export declare namespace ScriptSpace { 9 | type Config = { 10 | data: SvelteScript; 11 | }; 12 | type Definition = { 13 | code: string; 14 | variables: { 15 | [key: string]: VariableExportSpace.Result; 16 | }; 17 | functions: { 18 | [key: string]: FunctionExportSpace.Result; 19 | }; 20 | classes: { 21 | [key: string]: ClassExportSpace.Result; 22 | }; 23 | start: SourceSpace.Position; 24 | end: SourceSpace.Position; 25 | }; 26 | } 27 | export default class Script extends Source { 28 | data: SvelteScript; 29 | get exports(): ExportType[]; 30 | get imports(): ImportDeclaration[]; 31 | get variables(): VariableExport[]; 32 | get functions(): FunctionExport[]; 33 | get classes(): ClassExport[]; 34 | get start(): SourceSpace.Position; 35 | get end(): SourceSpace.Position; 36 | get code(): string; 37 | get definition(): ScriptSpace.Definition; 38 | private static filterExports; 39 | private static collectExports; 40 | } 41 | -------------------------------------------------------------------------------- /build/system/models/Script.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const FunctionExport_1 = __importDefault(require("../exports/FunctionExport")); 7 | const VariableExport_1 = __importDefault(require("../exports/VariableExport")); 8 | const ClassExport_1 = __importDefault(require("../exports/ClassExport")); 9 | const Source_1 = __importDefault(require("../base/Source")); 10 | const encodeSpecialChars_1 = __importDefault(require("../helpers/encodeSpecialChars")); 11 | const declarationsToModels = { 12 | VariableDeclaration: VariableExport_1.default, 13 | FunctionDeclaration: FunctionExport_1.default, 14 | ClassDeclaration: ClassExport_1.default 15 | }; 16 | class Script extends Source_1.default { 17 | get exports() { 18 | if (!this.data.content || !this.data.content.body) { 19 | return []; 20 | } 21 | const exports = this.data.content.body 22 | .filter((node) => node.type === 'ExportNamedDeclaration'); 23 | const filtered = exports.filter((node) => node.declaration); 24 | return filtered.map((node) => { 25 | const declaration = node.declaration; 26 | const model = declarationsToModels[declaration.type]; 27 | return new model({ data: node }); 28 | }); 29 | } 30 | get imports() { 31 | return this.data.content.body.filter((node) => node.type === 'ImportDeclaration'); 32 | } 33 | get variables() { 34 | return Script.filterExports(this.exports, VariableExport_1.default); 35 | } 36 | get functions() { 37 | return Script.filterExports(this.exports, FunctionExport_1.default); 38 | } 39 | get classes() { 40 | return Script.filterExports(this.exports, ClassExport_1.default); 41 | } 42 | get start() { 43 | return this.getPosition(this.data.start); 44 | } 45 | get end() { 46 | return this.getPosition(this.data.end); 47 | } 48 | get code() { 49 | return this.source.substr(this.data.start, this.data.end - this.data.start); 50 | } 51 | get definition() { 52 | return { 53 | code: encodeSpecialChars_1.default(this.code), 54 | variables: Script.collectExports(this.variables), 55 | functions: Script.collectExports(this.functions), 56 | classes: Script.collectExports(this.classes), 57 | start: this.start, 58 | end: this.end, 59 | }; 60 | } 61 | static filterExports(exports, type) { 62 | return exports.filter((_export) => _export instanceof type); 63 | } 64 | static collectExports(exports) { 65 | const results = {}; 66 | for (const _export of exports) { 67 | results[_export.name] = _export.result; 68 | } 69 | return results; 70 | } 71 | } 72 | exports.default = Script; 73 | -------------------------------------------------------------------------------- /build/system/models/Variable.d.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | export declare namespace VariableSpace { 3 | type Config = { 4 | name?: string; 5 | value: any; 6 | asPlaceholder?: boolean; 7 | }; 8 | } 9 | export default class Variable extends Base { 10 | private _name; 11 | value: any; 12 | asPlaceholder: boolean; 13 | defaults: { 14 | value: boolean; 15 | asPlaceholder: boolean; 16 | }; 17 | get name(): string; 18 | set name(value: string); 19 | } 20 | -------------------------------------------------------------------------------- /build/system/models/Variable.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const Base_1 = __importDefault(require("../base/Base")); 7 | const generateUniqueIdentifier_1 = __importDefault(require("../helpers/generateUniqueIdentifier")); 8 | class Variable extends Base_1.default { 9 | constructor() { 10 | super(...arguments); 11 | this.defaults = { 12 | value: false, 13 | asPlaceholder: false 14 | }; 15 | } 16 | get name() { 17 | if (!this._name) { 18 | this._name = generateUniqueIdentifier_1.default('var${id}'); 19 | } 20 | return this._name; 21 | } 22 | set name(value) { 23 | this._name = value; 24 | } 25 | } 26 | exports.default = Variable; 27 | -------------------------------------------------------------------------------- /build/system/partials/BasePartial.d.ts: -------------------------------------------------------------------------------- 1 | import SvelteSource from '../base/SvelteSource'; 2 | import InlineComponent from 'svelte/types/compiler/compile/nodes/InlineComponent'; 3 | import AttributeNode from 'svelte/types/compiler/compile/nodes/Attribute'; 4 | import Variable from '../models/Variable'; 5 | import Attribute from '../models/Attribute'; 6 | export declare namespace BasePartialSpace { 7 | type Config = { 8 | node: InlineComponent; 9 | }; 10 | type Generated = { 11 | variables: Variable[]; 12 | code: string; 13 | }; 14 | } 15 | export default abstract class BasePartial extends SvelteSource { 16 | static alias: string; 17 | private _id; 18 | node: InlineComponent; 19 | get id(): string; 20 | get start(): number; 21 | get end(): number; 22 | static get tag(): string; 23 | get code(): string; 24 | get content(): string; 25 | get slot(): string | undefined; 26 | generate(variables?: Variable[], attributes?: Attribute[]): BasePartialSpace.Generated; 27 | generateSlot(content: string): string; 28 | generateTag(customAttributes?: Attribute[]): string; 29 | extractNativeAttribute(name: string): string | undefined; 30 | getNativeAttribute(name: string): AttributeNode | undefined; 31 | getNativeAttributeAsString(name: string): string; 32 | } 33 | -------------------------------------------------------------------------------- /build/system/partials/BasePartial.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const SvelteSource_1 = __importDefault(require("../base/SvelteSource")); 7 | const Variable_1 = __importDefault(require("../models/Variable")); 8 | const Attribute_1 = __importDefault(require("../models/Attribute")); 9 | const encodeSpecialChars_1 = __importDefault(require("../helpers/encodeSpecialChars")); 10 | const generateUniqueIdentifier_1 = __importDefault(require("../helpers/generateUniqueIdentifier")); 11 | class BasePartial extends SvelteSource_1.default { 12 | get id() { 13 | if (!this._id) { 14 | this._id = generateUniqueIdentifier_1.default('${id}'); 15 | } 16 | return this._id; 17 | } 18 | get start() { 19 | return this.node.start; 20 | } 21 | get end() { 22 | return this.node.end; 23 | } 24 | static get tag() { 25 | throw new ReferenceError('Not implemented'); 26 | } 27 | ; 28 | get code() { 29 | if (!this.node.children.length) { 30 | return ''; 31 | } 32 | const start = this.node.children[0].start; 33 | const end = this.node.children[this.node.children.length - 1].end; 34 | return this.source.substr(start, end - start); 35 | } 36 | get content() { 37 | return this.code; 38 | } 39 | get slot() { 40 | return undefined; 41 | } 42 | generate(variables = [], attributes = []) { 43 | const source = encodeSpecialChars_1.default(this.code); 44 | const sourceVariable = new Variable_1.default({ value: source }); 45 | const sourceAttribute = new Attribute_1.default({ name: 'source', value: sourceVariable }); 46 | const tag = this.generateTag([...attributes, sourceAttribute]); 47 | return { 48 | variables: [...variables, sourceVariable], 49 | code: this.slot ? this.generateSlot(tag) : tag 50 | }; 51 | } 52 | generateSlot(content) { 53 | return `
${content}
`; 54 | } 55 | generateTag(customAttributes = []) { 56 | const sourceAttributesCompiled = this.node.attributes 57 | .map((attribute) => this.extractNativeAttribute(attribute.name)); 58 | const customAttributesCompiled = customAttributes 59 | .map((attribute) => attribute.raw); 60 | const attributesString = [ 61 | ...sourceAttributesCompiled, 62 | ...customAttributesCompiled 63 | ].join(' '); 64 | return this.content 65 | ? `<${this.node.name} ${attributesString}>${this.content}` 66 | : `<${this.node.name} ${attributesString} />`; 67 | } 68 | extractNativeAttribute(name) { 69 | const attribute = this.getNativeAttribute(name); 70 | if (!attribute) { 71 | return undefined; 72 | } 73 | return this.source 74 | .substr(attribute.start, attribute.end - attribute.start); 75 | } 76 | getNativeAttribute(name) { 77 | return this.node.attributes 78 | .find((attribute) => attribute.name === name); 79 | } 80 | getNativeAttributeAsString(name) { 81 | const attribute = this.getNativeAttribute(name); 82 | return attribute && attribute.value && attribute.value.length 83 | ? attribute.value[0].data : ''; 84 | } 85 | } 86 | exports.default = BasePartial; 87 | -------------------------------------------------------------------------------- /build/system/partials/DescriptionPartial.d.ts: -------------------------------------------------------------------------------- 1 | import BasePartial from './BasePartial'; 2 | export declare namespace DescriptionPartialSpace { 3 | type Config = {}; 4 | } 5 | export default class DescriptionPartial extends BasePartial { 6 | static get tag(): string; 7 | } 8 | -------------------------------------------------------------------------------- /build/system/partials/DescriptionPartial.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BasePartial_1 = __importDefault(require("./BasePartial")); 7 | class DescriptionPartial extends BasePartial_1.default { 8 | static get tag() { 9 | return 'Component.Description'; 10 | } 11 | } 12 | exports.default = DescriptionPartial; 13 | -------------------------------------------------------------------------------- /build/system/partials/MainPartial.d.ts: -------------------------------------------------------------------------------- 1 | import BasePartial, { BasePartialSpace } from './BasePartial'; 2 | import Variable from '../models/Variable'; 3 | import Attribute from '../models/Attribute'; 4 | export declare namespace MainPartialSpace { 5 | type Config = {}; 6 | } 7 | export default class MainPartial extends BasePartial { 8 | static get tag(): string; 9 | generate(variables?: Variable[], attributes?: Attribute[], withContent?: boolean): BasePartialSpace.Generated; 10 | } 11 | -------------------------------------------------------------------------------- /build/system/partials/MainPartial.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BasePartial_1 = __importDefault(require("./BasePartial")); 7 | const Variable_1 = __importDefault(require("../models/Variable")); 8 | const Attribute_1 = __importDefault(require("../models/Attribute")); 9 | const constants_1 = require("../constants"); 10 | class MainPartial extends BasePartial_1.default { 11 | static get tag() { 12 | return 'Component'; 13 | } 14 | generate(variables = [], attributes = [], withContent = true) { 15 | // use global name to pass source code attribute to the component 16 | const rawVariable = new Variable_1.default({ 17 | name: constants_1.DOCUMENTATION_VARIABLE_RAW, 18 | value: undefined, 19 | asPlaceholder: true 20 | }); 21 | // use global name to pass definitions attribute to the component 22 | const definitionVariable = new Variable_1.default({ 23 | name: constants_1.DOCUMENTATION_VARIABLE_DEFINITION, 24 | value: undefined, 25 | asPlaceholder: true 26 | }); 27 | // use global name to pass initialization attribute to the component 28 | const initializationVariable = new Variable_1.default({ 29 | name: constants_1.DOCUMENTATION_VARIABLE_INITIALIZATION, 30 | value: undefined, 31 | asPlaceholder: true 32 | }); 33 | const rawAttribute = new Attribute_1.default({ name: 'raw', value: rawVariable }); 34 | const definitionAttribute = new Attribute_1.default({ name: 'definition', value: definitionVariable }); 35 | const initializationAttribute = new Attribute_1.default({ name: 'initialization', value: initializationVariable }); 36 | return super.generate([...variables, rawVariable, initializationVariable, definitionVariable], [...attributes, rawAttribute, initializationAttribute, definitionAttribute]); 37 | } 38 | } 39 | exports.default = MainPartial; 40 | -------------------------------------------------------------------------------- /build/system/partials/UsagePartial.d.ts: -------------------------------------------------------------------------------- 1 | import BasePartial from './BasePartial'; 2 | export declare namespace UsagePartialSpace { 3 | type Config = {}; 4 | } 5 | export default class UsagePartial extends BasePartial { 6 | static get tag(): string; 7 | } 8 | -------------------------------------------------------------------------------- /build/system/partials/UsagePartial.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const BasePartial_1 = __importDefault(require("./BasePartial")); 7 | class UsagePartial extends BasePartial_1.default { 8 | static get tag() { 9 | return 'Component.Usage'; 10 | } 11 | } 12 | exports.default = UsagePartial; 13 | -------------------------------------------------------------------------------- /build/system/types/ExportResultType.d.ts: -------------------------------------------------------------------------------- 1 | import { FunctionExportSpace } from '../exports/FunctionExport'; 2 | import { VariableExportSpace } from '../exports/VariableExport'; 3 | import { ClassExportSpace } from '../exports/ClassExport'; 4 | export declare type ExportResultType = FunctionExportSpace.Result | VariableExportSpace.Result | ClassExportSpace.Result; 5 | -------------------------------------------------------------------------------- /build/system/types/ExportResultType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /build/system/types/ExportType.d.ts: -------------------------------------------------------------------------------- 1 | import FunctionExport from '../exports/FunctionExport'; 2 | import VariableDeclaration from '../exports/VariableExport'; 3 | import ClassExport from '../exports/ClassExport'; 4 | export declare type ExportType = FunctionExport | VariableDeclaration | ClassExport; 5 | -------------------------------------------------------------------------------- /build/system/types/ExportType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /build/system/types/ImportType.d.ts: -------------------------------------------------------------------------------- 1 | import NamespaceImport from '../imports/NamespaceImport'; 2 | import Import from '../imports/Import'; 3 | export declare type ImportType = Import | NamespaceImport; 4 | -------------------------------------------------------------------------------- /build/system/types/ImportType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /build/system/types/ItemType.d.ts: -------------------------------------------------------------------------------- 1 | export declare type ItemType = { 2 | name: string; 3 | title: string | undefined; 4 | }; 5 | -------------------------------------------------------------------------------- /build/system/types/ItemType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /build/system/types/PartialType.d.ts: -------------------------------------------------------------------------------- 1 | import UsagePartial from '../partials/UsagePartial'; 2 | import MainPartial from '../partials/MainPartial'; 3 | import DescriptionPartial from '../partials/DescriptionPartial'; 4 | export declare type PartialType = UsagePartial | MainPartial | DescriptionPartial; 5 | export declare type PartialClassType = typeof UsagePartial | typeof MainPartial | typeof DescriptionPartial; 6 | -------------------------------------------------------------------------------- /build/system/types/PartialType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /documentation/screenshots/component-checkbox-group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gustarus/svelte-doc-generator/a16e6d0705821ef3be9d3b21c184636bd31b2f31/documentation/screenshots/component-checkbox-group.png -------------------------------------------------------------------------------- /documentation/screenshots/component-input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gustarus/svelte-doc-generator/a16e6d0705821ef3be9d3b21c184636bd31b2f31/documentation/screenshots/component-input.png -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | const rootSelector = '.bootstrap'; 2 | // const classPrefix = 'bootstrap'; 3 | 4 | const gulp = require('gulp'); 5 | const postcss = require('gulp-postcss'); 6 | const sass = require('gulp-sass'); 7 | const insert = require('gulp-insert'); 8 | const replace = require('gulp-replace'); 9 | const autoprefixer = require('autoprefixer'); 10 | const postcssNamespace = require('postcss-namespace'); 11 | const selectorNamespace = require('postcss-selector-namespace')({ namespace: rootSelector }); 12 | 13 | gulp.task('compile-bootstrap', function () { 14 | const processors = [ 15 | autoprefixer, 16 | postcssNamespace, 17 | selectorNamespace 18 | ]; 19 | 20 | return gulp.src('./node_modules/bootstrap/scss/bootstrap.scss') 21 | .pipe(sass().on('error', sass.logError)) 22 | // .pipe(insert.prepend('@prefix ' + classPrefix + ';\n\n')) 23 | .pipe(insert.append('\n@prefix ;\n')) 24 | .pipe(postcss(processors)) 25 | .pipe(replace(`${rootSelector} html`, rootSelector)) 26 | .pipe(replace(`${rootSelector} body`, rootSelector)) 27 | .pipe(gulp.dest('./build/vendors/bootstrap')); 28 | }); 29 | -------------------------------------------------------------------------------- /interface/components/Application/Application.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 | 66 | 67 | 68 |
69 | 85 | 86 |
87 | {#each routes as route} 88 | 89 | {/each} 90 |
91 |
92 |
93 | 94 | {#if $source} 95 | 96 | {/if} 97 | -------------------------------------------------------------------------------- /interface/components/Application/ApplicationSource/ApplicationSource.svelte: -------------------------------------------------------------------------------- 1 | 23 | 24 | 47 | 48 |
49 |
50 | 51 | 64 |
65 | -------------------------------------------------------------------------------- /interface/components/Application/ApplicationSource/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ApplicationSource.svelte'; 2 | 3 | export default Component; 4 | -------------------------------------------------------------------------------- /interface/components/Application/index.js: -------------------------------------------------------------------------------- 1 | import Application from './Application.svelte'; 2 | 3 | export default Application; 4 | -------------------------------------------------------------------------------- /interface/components/Component/Component.svelte: -------------------------------------------------------------------------------- 1 | 28 | 29 | 43 | 44 |
45 |
46 |
{title} {@html badgeCompiled}
47 | 48 | {#if withDescription} 49 |
50 | 51 | 52 | 53 |
54 | {/if} 55 |
56 | 57 |
58 | {#if withUsages} 59 |
60 | 61 | 62 | 63 |
64 | {/if} 65 | 66 |
67 | {#if withInitialization} 68 |
69 | 70 |
71 | {/if} 72 | 73 | {#if withDefinition} 74 |
75 | 76 |
77 | {/if} 78 |
79 |
80 |
81 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentClasses/ComponentClasses.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentClasses/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentClasses.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentCode/ComponentCode.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentCode/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentCode.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentContext/ComponentContext.svelte: -------------------------------------------------------------------------------- 1 | 23 | 24 | 37 | 38 |
39 |
{title}
40 |
{tag}
41 | 42 |
43 |
44 | 45 |
46 | 47 |
48 | 49 |
50 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentContext/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentContext.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentDefinition/ComponentDefinition.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 15 | 16 |
17 |
{title}
18 | 19 | 20 | 21 | {#if module && instance} 22 |
23 | {/if} 24 | 25 | 26 |
27 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentDefinition/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentDefinition.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentDescription/ComponentDescription.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 |
10 |
11 | 12 |
13 |
14 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentDescription/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentDescription.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentFunctions/ComponentFunctions.svelte: -------------------------------------------------------------------------------- 1 | 27 | 28 |
29 | 30 |
31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | {#each sorted as item} 43 | 44 | 48 | 53 | 54 | 55 | 56 | {/each} 57 | 58 |
NameArgumentsDescriptionNote
45 | {item.name} 46 | (definitions) 47 | 49 | {#each item.arguments as argument} 50 | {@html resolveFunctionArgumentLabel(argument)}  51 | {/each} 52 | {@html md.render(item.description || '')}{@html md.render(item.note || '')}
59 |
60 |
61 |
62 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentFunctions/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentFunctions.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentInitialization/ComponentInitialization.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 17 | 18 |
19 |
{title}
20 |
21 | 22 | {#if decoded} 23 | 24 | {:else} 25 | 28 | {/if} 29 |
30 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentInitialization/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentInitialization.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentProperties/ComponentProperties.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 12 | 13 |
14 |
{title}
15 | 16 | {#if visible} 17 | 18 | {:else} 19 | 22 | {/if} 23 |
24 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentProperties/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentProperties.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentUsage/ComponentUsage.svelte: -------------------------------------------------------------------------------- 1 | 20 | 21 | 71 | 72 |
73 |
{title} {@html badgeCompiled}
74 | 75 |
76 |
77 | 78 |
79 | 80 | {#if decoded} 81 |
82 | 83 |
84 | {/if} 85 |
86 |
87 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentUsage/consntants.js: -------------------------------------------------------------------------------- 1 | export const COMPONENT_USAGE_THEME_LIGHT = 'light'; 2 | export const COMPONENT_USAGE_THEME_DARK = 'dark'; 3 | export const COMPONENT_USAGE_THEME_NEUTRAL = 'neutral'; 4 | export const COMPONENT_USAGE_ACCEPTABLE_THEMES = [ 5 | COMPONENT_USAGE_THEME_LIGHT, 6 | COMPONENT_USAGE_THEME_DARK, 7 | COMPONENT_USAGE_THEME_NEUTRAL 8 | ]; 9 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentUsage/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentUsage.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentUsages/ComponentUsages.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 |
Component usages
10 | 11 | 12 | 15 | 16 |
17 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentUsages/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentUsages.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentVariables/ComponentVariables.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | {#if constants.length} 16 | 17 | {/if} 18 | 19 | {#if constants.length && changable.length} 20 |
21 | {/if} 22 | 23 | {#if changable.length} 24 | 25 | {/if} 26 |
27 |
28 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentVariables/ComponentVariablesTable/ComponentVariablesTable.svelte: -------------------------------------------------------------------------------- 1 | 19 | 20 | 30 | 31 |
32 |
{title} export {type}
33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | {#each data as item} 47 | 48 | 52 | 53 | 54 | 55 | 56 | 57 | {/each} 58 | 59 |
NameTypeDefaultDescriptionNote
49 | {item.name} 50 | (definitions) 51 | {typeof item.default}{JSON.stringify(item.default)}{@html md.render(item.description || '')}{@html md.render(item.note || '')}
60 |
61 |
62 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentVariables/ComponentVariablesTable/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentVariablesTable.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/ComponentVariables/index.js: -------------------------------------------------------------------------------- 1 | import Component from './ComponentVariables.svelte'; 2 | export default Component; 3 | -------------------------------------------------------------------------------- /interface/components/Component/index.js: -------------------------------------------------------------------------------- 1 | import Component from './Component.svelte'; 2 | import ComponentCode from './ComponentCode'; 3 | import ComponentDescription from './ComponentDescription'; 4 | import ComponentUsage from './ComponentUsage'; 5 | 6 | Component.Code = ComponentCode; 7 | Component.Description = ComponentDescription; 8 | Component.Usage = ComponentUsage; 9 | export default Component; 10 | -------------------------------------------------------------------------------- /interface/components/Source/Source.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 | 68 | 69 |
70 |
71 | {#each lines as {indent, source}, index} 72 |
{index + 1}
73 | {/each} 74 |
75 | 76 |
77 | {#each lines as {indent, source}, index} 78 |
79 | {@html getLineIndent(indent)}{@html source} 80 |
81 | {/each} 82 |
83 |
84 | -------------------------------------------------------------------------------- /interface/components/Source/index.js: -------------------------------------------------------------------------------- 1 | import Component from './Source.svelte'; 2 | 3 | export default Component; 4 | -------------------------------------------------------------------------------- /interface/helpers/convertCamelToCode.js: -------------------------------------------------------------------------------- 1 | export default function convertCamelToCode(string) { 2 | const camelCase = string[0].toLowerCase() + string.substr(1); 3 | return camelCase.replace(/[A-Z]/g, a => `-${a.toLowerCase()}`); 4 | } 5 | -------------------------------------------------------------------------------- /interface/helpers/convertCodeToComponent.js: -------------------------------------------------------------------------------- 1 | export default function convertCodeToComponent(string) { 2 | const componentCase = string[0].toUpperCase() + string.substr(1); 3 | return componentCase.replace(/-([a-z])/g, (_, a) => a.toUpperCase()); 4 | } 5 | -------------------------------------------------------------------------------- /interface/helpers/decodeSpecialChars.js: -------------------------------------------------------------------------------- 1 | export default function decodeSpecialChars(source) { 2 | return source 3 | .replace(/&/g, '&') 4 | .replace(/>/g, '>') 5 | .replace(/</g, '<') 6 | .replace(/"/g, '"'); 7 | } 8 | -------------------------------------------------------------------------------- /interface/helpers/filterObject.js: -------------------------------------------------------------------------------- 1 | export default function filterObject(data, filter) { 2 | const names = Object.keys(data); 3 | const filtered = names.filter((name) => filter(name, data[name])); 4 | return filtered.reduce((stack, name) => { 5 | stack[name] = data[name]; 6 | return stack; 7 | }, {}); 8 | } 9 | -------------------------------------------------------------------------------- /interface/helpers/isDeclarationContext.js: -------------------------------------------------------------------------------- 1 | export default function isDeclarationContext({ variables, functions, classes } = {}) { 2 | const isVariables = variables && Object.keys(variables).length; 3 | const isFunctions = functions && Object.keys(functions).length; 4 | const isClasses = classes && Object.keys(classes).length; 5 | return isVariables || isFunctions || isClasses; 6 | } 7 | -------------------------------------------------------------------------------- /interface/helpers/resolveHighlightedSource.js: -------------------------------------------------------------------------------- 1 | const hljs = require('highlight.js'); 2 | 3 | export default function resolveHighlightedSource(source, lang = 'html') { 4 | // highlight source code 5 | const highlighted = hljs.highlight(lang, source).value; 6 | 7 | // split source code into lines with indent value 8 | const lines = highlighted.split('\n').map((line) => { 9 | const match = line.match(/^([\t\s]*)(.*?)$/); 10 | const indent = match[1].length; 11 | const source = match[2]; 12 | return { indent, source }; 13 | }); 14 | 15 | // find minimum indent to offset indents 16 | const filledLines = lines.filter((line) => line.source.replace(/^[\t\s]+/, '').length); 17 | const minimumIndent = Math.min(...filledLines.map((line) => line.indent)); 18 | 19 | // recalculate indents based on offset 20 | const changedLines = lines.map((line) => { 21 | const indent = line.indent > minimumIndent 22 | ? line.indent - minimumIndent : 0; 23 | return { ...line, indent }; 24 | }); 25 | 26 | // mark empty lines at the beginning as empty 27 | for (let i = 0; i < changedLines.length; i++) { 28 | if(!changedLines[i].source) { 29 | changedLines[i] = undefined; 30 | continue; 31 | } 32 | 33 | break; 34 | } 35 | 36 | // mark empty lines at the ending as empty 37 | for (let i = changedLines.length - 1; i > 0; i--) { 38 | if(!changedLines[i].source) { 39 | changedLines[i] = undefined; 40 | continue; 41 | } 42 | 43 | break; 44 | } 45 | 46 | // return only non empty lines 47 | return changedLines.filter((line) => line); 48 | } 49 | -------------------------------------------------------------------------------- /interface/helpers/resolveMenuFromLibrary.js: -------------------------------------------------------------------------------- 1 | import convertCamelToCode from './convertCamelToCode'; 2 | 3 | export default function resolveMenuFromLibrary(index, basePath = '/') { 4 | const menu = index.map(({ name }) => ({ 5 | path: basePath + convertCamelToCode(name) + '/', 6 | label: name, 7 | })); 8 | 9 | menu.sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0)); 10 | 11 | return menu; 12 | } 13 | -------------------------------------------------------------------------------- /interface/index.js: -------------------------------------------------------------------------------- 1 | import convertCamelToCode from './helpers/convertCamelToCode'; 2 | import convertCodeToComponent from './helpers/convertCodeToComponent'; 3 | import decodeSpecialChars from './helpers/decodeSpecialChars'; 4 | import filterObject from './helpers/filterObject'; 5 | import isDeclarationContext from './helpers/isDeclarationContext'; 6 | import resolveHighlightedSource from './helpers/resolveHighlightedSource'; 7 | import resolveMenuFromLibrary from './helpers/resolveMenuFromLibrary'; 8 | 9 | import Application from './components/Application'; 10 | import Component from './components/Component'; 11 | 12 | export { 13 | convertCamelToCode, 14 | convertCodeToComponent, 15 | decodeSpecialChars, 16 | filterObject, 17 | isDeclarationContext, 18 | resolveHighlightedSource, 19 | resolveMenuFromLibrary, 20 | 21 | Application, 22 | Component 23 | }; 24 | -------------------------------------------------------------------------------- /interface/index.pcss: -------------------------------------------------------------------------------- 1 | @import './styles/reset.pcss'; 2 | @import './../build/vendors/bootstrap/bootstrap.css'; 3 | @import 'highlight.js/styles/atom-one-dark.css'; 4 | @import './styles/global.pcss'; 5 | -------------------------------------------------------------------------------- /interface/stores.js: -------------------------------------------------------------------------------- 1 | import { writable } from 'svelte/store'; 2 | 3 | export const source = writable(false); 4 | export const line = writable(false); 5 | -------------------------------------------------------------------------------- /interface/styles/global.pcss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gustarus/svelte-doc-generator/a16e6d0705821ef3be9d3b21c184636bd31b2f31/interface/styles/global.pcss -------------------------------------------------------------------------------- /interface/styles/reset.pcss: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ 2 | v2.0 | 20110126 3 | License: none (public domain) 4 | */ 5 | 6 | html, 7 | body, 8 | div, 9 | span, 10 | applet, 11 | object, 12 | iframe, 13 | h1, 14 | h2, 15 | h3, 16 | h4, 17 | h5, 18 | h6, 19 | p, 20 | blockquote, 21 | pre, 22 | a, 23 | abbr, 24 | acronym, 25 | address, 26 | big, 27 | cite, 28 | code, 29 | del, 30 | dfn, 31 | em, 32 | img, 33 | ins, 34 | kbd, 35 | q, 36 | s, 37 | samp, 38 | small, 39 | strike, 40 | strong, 41 | sub, 42 | sup, 43 | tt, 44 | var, 45 | b, 46 | u, 47 | i, 48 | center, 49 | dl, 50 | dt, 51 | dd, 52 | ol, 53 | ul, 54 | li, 55 | fieldset, 56 | form, 57 | label, 58 | legend, 59 | table, 60 | caption, 61 | tbody, 62 | tfoot, 63 | thead, 64 | tr, 65 | th, 66 | td, 67 | article, 68 | aside, 69 | canvas, 70 | details, 71 | embed, 72 | figure, 73 | figcaption, 74 | footer, 75 | header, 76 | hgroup, 77 | menu, 78 | nav, 79 | output, 80 | ruby, 81 | section, 82 | summary, 83 | time, 84 | mark, 85 | audio, 86 | video, 87 | button { 88 | margin: 0; 89 | padding: 0; 90 | border: 0; 91 | font-size: 100%; 92 | font: inherit; 93 | vertical-align: baseline; 94 | } 95 | 96 | /* HTML5 display-role reset for older browsers */ 97 | article, 98 | aside, 99 | details, 100 | figcaption, 101 | figure, 102 | footer, 103 | header, 104 | hgroup, 105 | menu, 106 | nav, 107 | section { 108 | display: block; 109 | } 110 | 111 | body { 112 | line-height: 1; 113 | } 114 | 115 | ol, 116 | ul { 117 | list-style: none; 118 | } 119 | 120 | blockquote, 121 | q { 122 | quotes: none; 123 | } 124 | 125 | blockquote:before, 126 | blockquote:after, 127 | q:before, 128 | q:after { 129 | content: ''; 130 | content: none; 131 | } 132 | 133 | table { 134 | border-collapse: collapse; 135 | border-spacing: 0; 136 | } 137 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "name": "svelte-doc-generator", 4 | "version": "1.2.1", 5 | "description": "", 6 | "main": "./build/interface/index.js", 7 | "scripts": { 8 | "build": "npm run system:build && npm run interface:build && npm run bootstrap:build", 9 | "check": "./node_modules/.bin/tsc --noEmit", 10 | "check:watch": "npm run check -- --watch", 11 | "interface:build": "rm -rf ./build/interface && node -r esm build.js", 12 | "system:watch": "./node_modules/.bin/tsc -w", 13 | "system:build": "rm -rf ./build/system && ./node_modules/.bin/tsc", 14 | "bootstrap:build": "rm -rf ./build/vendors/bootstrap && ./node_modules/.bin/gulp compile-bootstrap" 15 | }, 16 | "pre-commit": [ 17 | "build" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+ssh://git@github.com:gustarus/svelte-doc-generator.git" 22 | }, 23 | "bugs": { 24 | "url": "https://github.com/gustarus/svelte-doc-generator/issues" 25 | }, 26 | "homepage": "https://github.com/gustarus/svelte-doc-generator", 27 | "bin": { 28 | "svelte-doc-generator": "./build/system/cli.js" 29 | }, 30 | "author": "Pavel Kondratenko ", 31 | "license": "ISC", 32 | "devDependencies": { 33 | "@types/commander": "^2.12.2", 34 | "@types/dom-parser": "^0.1.0", 35 | "@types/estree": "0.0.42", 36 | "@types/fs-extra": "^8.0.1", 37 | "@types/glob-watcher": "^5.0.0", 38 | "@types/md5": "^2.1.33", 39 | "@types/node": "^13.5.0", 40 | "@types/yargs": "^15.0.1", 41 | "autoprefixer": "^9.7.4", 42 | "babel-runtime": "^6.26.0", 43 | "bootstrap": "^4.4.1", 44 | "cssnano": "^4.1.10", 45 | "esm": "^3.2.25", 46 | "gulp": "^4.0.2", 47 | "gulp-insert": "^0.5.0", 48 | "gulp-postcss": "^8.0.0", 49 | "gulp-replace": "^1.0.0", 50 | "gulp-sass": "^4.0.2", 51 | "magic-string": "^0.25.6", 52 | "periscopic": "^2.0.2", 53 | "postcss": "^7.0.18", 54 | "postcss-automath": "^1.0.1", 55 | "postcss-color-mod-function": "^3.0.3", 56 | "postcss-custom-media": "^7.0.8", 57 | "postcss-each": "^0.10.0", 58 | "postcss-for": "^2.1.1", 59 | "postcss-import": "^12.0.1", 60 | "postcss-mixins": "^6.2.2", 61 | "postcss-namespace": "^1.1.1", 62 | "postcss-nested": "^4.1.2", 63 | "postcss-preset-env": "^6.6.0", 64 | "postcss-selector-namespace": "^3.0.1", 65 | "postcss-simple-vars": "^5.0.2", 66 | "svelte-routing": "^1.4.0", 67 | "typescript": "^3.7.5" 68 | }, 69 | "dependencies": { 70 | "colors": "^1.4.0", 71 | "commander": "^4.1.0", 72 | "comment-parser": "^0.7.2", 73 | "deepmerge": "^4.2.2", 74 | "estree-walker": "^1.0.1", 75 | "fs": "0.0.1-security", 76 | "fs-extra": "^8.1.0", 77 | "dom-parser": "^0.1.6", 78 | "highlight.js": "^9.18.0", 79 | "markdown-it": "^10.0.0", 80 | "svelte": "^3.20.1", 81 | "moment": "^2.24.0", 82 | "path": "^0.12.7", 83 | "glob": "^7.1.6", 84 | "glob-watcher": "^5.0.3" 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | const variables = { 2 | font: 'Open Sans, sans-serif', 3 | 4 | white: '#ffffff', 5 | 'dark-white': '#FFFEFE', 6 | black: '#333333', 7 | 'gray-dark': '#5e6366', 8 | 'gray-text': '#6E8490', 9 | gray: '#F2F2F2', 10 | 'gray-disabled': '#C6CACC', 11 | 'cloudy-gray': '#F7F9FA', 12 | 'blue-disabled': '#c1d3f1', 13 | blue: '#4285f4', 14 | 'cloudy-blue': '#E1ECFF', 15 | 'dark-blue': '#0A055F', 16 | 'dark-blue-disabled': '#9DB1D1', 17 | 'dark-blue-hover': '#0A055F', 18 | 'blue-bold': '#2E65BF', 19 | 'blue-hover': '#236add', 20 | 'orange-disabled': 'rgba(255, 102, 51, 0.5)', 21 | orange: '#ff6633', 22 | 'orange-hover': '#f94c13', 23 | red: '#ff4114', 24 | 'yellow-disabled': '#fff18e', 25 | yellow: '#ffe41d', 26 | 'yellow-hover': '#ead430', 27 | 'green-disabled': '#bccb6e', 28 | green: '#33CC66', 29 | }; 30 | 31 | module.exports = { 32 | plugins: [ 33 | require('postcss-for'), 34 | require('postcss-each'), 35 | require('postcss-preset-env')({ stage: 0 }), 36 | require('postcss-import'), 37 | require('postcss-nested'), 38 | require('postcss-mixins'), 39 | require('postcss-simple-vars')({ variables }), 40 | require('postcss-automath'), 41 | require('autoprefixer'), 42 | require('cssnano')({ 43 | preset: 'default' 44 | }) 45 | ] 46 | }; 47 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Svelte documentation generator tool 2 | Do you have a library of svelte components? 3 | You can generate a documentation for whole your library. 4 | 5 | ![example](documentation/screenshots/component-input.png) 6 | 7 | ## Installation 8 | **1. Install the package** 9 | 10 | ```bash 11 | npm install --save-dev svelte-doc-generator 12 | ``` 13 | 14 | **2. Run setup tool** 15 | 16 | This will create `webpack.config.js`, `package.json` and `site` folder inside your project. 17 | You can just copy and paste this files into your project from [template folder](./template). 18 | You you already have `package.json` or `webpack.config.js`, just yours with from template ones. 19 | ```bash 20 | node ./node_modules/.bin/svelte-doc-generator setup --project . 21 | ``` 22 | 23 | **3. Create sample documentation component** 24 | 25 | For every component you want to create document for you have to create `*Documentation.svelte` file inside the component folder. 26 | Imagine that you have folder `./src/components/Input` with component `Input.svelte`. 27 | Inside `./src/components/Input` folder you have to create `InputDocumentation.svelte` like this: 28 | 29 | ```html 30 | 34 | 35 | 36 |
37 | Component to draw inputs easily. 38 |
39 | 40 |
41 | 42 | 43 | 44 |
45 |
46 | ``` 47 | 48 | **4. Generate documentation library** 49 | 50 | This will generate a library from your components. 51 | This tool will include only components with `*Documentation.svelte` files inside. 52 | ```bash 53 | node ./node_modules/.bin/svelte-doc-gnerator generate --library ./src/components --target ./site/library 54 | ``` 55 | 56 | Or run documentation changes watcher to regenerate documentation on every change inside your library documentations components. 57 | ```bash 58 | node ./node_modules/.bin/svelte-doc-gnerator watch --library ./src/components --target ./site/library 59 | ``` 60 | 61 | **5. Run your documentation site** 62 | 63 | This command will start `webpack dev server` to serve your site. 64 | ```bash 65 | node ./node_modules/webpack-dev-server/.bin/webpack-dev-server.js --mode development 66 | ``` 67 | 68 | **6. Open localhost** 69 | 70 | Open `localhost:8080` in your browser and take a look at the result! 71 | 72 | ## Full example 73 | Take a look at the `CheckboxGroupDocumentation.svelte` example below. 74 | Do not take in mind `CheckboxGroup` component. 75 | ```html 76 | 95 | 96 | 97 |
98 | Component to draw grouped checkboxes. 99 |
100 |
101 |
102 | 103 |
104 | 105 | 106 | 107 |
108 |
109 | ``` 110 | 111 | This code will generate the following output. 112 | ![example](documentation/screenshots/component-checkbox-group.png) 113 | 114 | # TODO 115 | - [ ] Create documentation for every exported svelte component. 116 | -------------------------------------------------------------------------------- /system/base/Base.ts: -------------------------------------------------------------------------------- 1 | export default class Base extends Object { 2 | 3 | private _defaults: C; 4 | 5 | public config: C; 6 | 7 | public constructor(config: C) { 8 | super(); 9 | this.configure(config); 10 | } 11 | 12 | public get defaults(): C { 13 | return this._defaults; 14 | } 15 | 16 | public set defaults(config: C) { 17 | this._defaults = { ...this._defaults, ...config }; 18 | } 19 | 20 | private configure(custom: { [key: string]: any } = {}): this { 21 | const config = { ...this.defaults, ...custom }; 22 | for (const name in config) { 23 | if (typeof config[name] !== 'undefined') { 24 | (this as any)[name] = config[name]; 25 | } 26 | } 27 | 28 | return this; 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /system/base/Object.ts: -------------------------------------------------------------------------------- 1 | export default abstract class Object { 2 | 3 | public static create(config: { [key: string]: any }): Object { 4 | throw new ReferenceError('Not implemented yet'); 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /system/base/Source.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import Base from '../base/Base'; 3 | import * as fs from 'fs'; 4 | import DOMParser from 'dom-parser'; 5 | 6 | export namespace SourceSpace { 7 | export type Config = { 8 | path: string; 9 | } 10 | 11 | export type Position = { 12 | line: number; 13 | column: number; 14 | } 15 | } 16 | 17 | export default abstract class Source extends Base { 18 | 19 | private _path: string; 20 | 21 | private _source?: string; 22 | 23 | private _dom?: DOMParser.Dom; 24 | 25 | public set path(value: string) { 26 | this._path = path.resolve(value); 27 | } 28 | 29 | public get path(): string { 30 | return this._path; 31 | } 32 | 33 | public get source(): string { 34 | if (!this._source) { 35 | this._source = fs.readFileSync(this.path).toString(); 36 | } 37 | 38 | return this._source; 39 | } 40 | 41 | public set source(content: string) { 42 | this._source = content; 43 | this.save(); 44 | } 45 | 46 | public get dom(): DOMParser.Dom { 47 | if (!this._dom) { 48 | const parser = new DOMParser(); 49 | this._dom = parser.parseFromString(this.source); 50 | } 51 | 52 | return this._dom; 53 | } 54 | 55 | public save() { 56 | fs.writeFileSync(this.path, this.source); 57 | this.reset(); 58 | } 59 | 60 | public reset() { 61 | delete this._source; 62 | delete this._dom; 63 | } 64 | 65 | public getPosition(position: number): SourceSpace.Position { 66 | const part = this.source.substr(0, position); 67 | const lines = part.split('\n'); 68 | 69 | const line = lines.length; 70 | const column = lines[lines.length - 1].length; 71 | return { line, column }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /system/base/SvelteSource.ts: -------------------------------------------------------------------------------- 1 | import { parse } from 'svelte/compiler'; 2 | import { Ast } from 'svelte/types/compiler/interfaces'; 3 | import Source from './Source'; 4 | import Script from "../models/Script"; 5 | 6 | export namespace SvelteComponentSpace { 7 | export type Config = {} 8 | } 9 | 10 | export default abstract class SvelteSource extends Source { 11 | 12 | private _module: Script; 13 | 14 | private _instance: Script; 15 | 16 | private _tree?: Ast; 17 | 18 | public get tree(): Ast { 19 | if (!this._tree) { 20 | try { 21 | this._tree = parse(this.source); 22 | } catch(error) { 23 | error.message = `Unable to parse svelte component '${this.path}' with an error '${error.message}'`; 24 | throw error; 25 | } 26 | } 27 | 28 | return this._tree; 29 | } 30 | 31 | public get module(): Script { 32 | if (!this._module && this.tree.module) { 33 | this._module = new Script({ path: this.path, data: this.tree.module }); 34 | } 35 | 36 | return this._module; 37 | } 38 | 39 | public get instance(): Script { 40 | if (!this._instance && this.tree.instance) { 41 | this._instance = new Script({ path: this.path, data: this.tree.instance }); 42 | } 43 | 44 | return this._instance; 45 | } 46 | 47 | public reset() { 48 | super.reset(); 49 | delete this._tree; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /system/cli.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import * as path from 'path'; 4 | import program from 'commander'; 5 | import generate from './cli/generate'; 6 | import watch from './cli/watch'; 7 | import setup from './cli/setup'; 8 | import { PATH_ROOT } from './constants'; 9 | import Package from './models/Package'; 10 | 11 | const pathToPackage = path.resolve(PATH_ROOT, 'package.json'); 12 | const that = new Package({ path: pathToPackage }); 13 | 14 | // display description 15 | program 16 | .version(that.version) 17 | .description('Tool to generate svelte documentation'); 18 | 19 | // bind commands 20 | generate(program); 21 | watch(program); 22 | setup(program); 23 | 24 | // parse arguments 25 | program.parse(process.argv); 26 | 27 | // display help command 28 | if (!process.argv.slice(2).length) { 29 | program.help(); 30 | } 31 | -------------------------------------------------------------------------------- /system/cli/setup.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra'; 2 | import * as path from 'path'; 3 | import colors from 'colors'; 4 | import { Command } from 'commander'; 5 | import displayCommandGreetings from './../helpers/displayCommandGreetings'; 6 | import displayCommandDone from '../helpers/displayCommandDone'; 7 | import displayCommandStep from '../helpers/displayCommandStep'; 8 | import { PATH_TEMPLATE } from '../constants'; 9 | 10 | export default function setup(program: Command) { 11 | program 12 | .command('setup') 13 | .description('Setup target project with the template') 14 | .requiredOption('--project ', 'Path to the target project (where you store package.json for your project)') 15 | .action((cmd) => { 16 | displayCommandGreetings(cmd); 17 | 18 | const sourcePath = path.resolve(PATH_TEMPLATE); 19 | const targetPath = path.resolve(cmd.project); 20 | 21 | displayCommandStep(cmd, colors.blue.bold('Setup your project with the documentation site template')); 22 | displayCommandStep(cmd, `${colors.bold('Path to the template')}: ${colors.italic(sourcePath)}`); 23 | displayCommandStep(cmd, `${colors.bold('Path to the project')}: ${colors.italic(targetPath)}`); 24 | 25 | let conflictsCounter = 0; 26 | 27 | function filter(src: string, dest: string): boolean { 28 | const srcStat = fs.statSync(src); 29 | if (srcStat.isFile()) { 30 | displayCommandStep(cmd, ` ${colors.blue('Copy template file...')}`); 31 | displayCommandStep(cmd, ` From '${colors.italic(src)}'`); 32 | displayCommandStep(cmd, ` To '${colors.italic(dest)}'`); 33 | if (fs.existsSync(dest)) { 34 | conflictsCounter++; 35 | displayCommandStep(cmd, ` ${colors.yellow('File already exists: skipped;')}`); 36 | return false; 37 | } 38 | } 39 | 40 | return true; 41 | } 42 | 43 | displayCommandStep(cmd, 'Copy every file from the template...'); 44 | fs.copySync(sourcePath, targetPath, { recursive: true, overwrite: true, filter }); 45 | 46 | if (conflictsCounter) { 47 | displayCommandStep(cmd, colors.yellow(`${colors.bold(conflictsCounter.toString())} conflicts were found: take a look at yellow text above`)); 48 | } 49 | 50 | displayCommandDone(cmd); 51 | }); 52 | }; 53 | -------------------------------------------------------------------------------- /system/cli/watch.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra'; 2 | import * as path from 'path'; 3 | import colors from 'colors'; 4 | import watcher from 'glob-watcher'; 5 | import resolveDocumentationComponentPath from '../helpers/resolveDocumentationComponentPath'; 6 | import resolveDocumentationDirectoryPath from '../helpers/resolveDocumentationDirectoryPath'; 7 | import resolveDocumentationDirectoryComponentPath from '../helpers/resolveDocumentationDirectoryComponentPath'; 8 | import Package from '../models/Package'; 9 | import Component from '../models/Component'; 10 | import Documentation from '../models/Documentation'; 11 | import Generator from '../models/Generator'; 12 | import Dictionary from '../models/Dictionary'; 13 | import resolveIndexFromGenerators from '../helpers/resolveMenuFromGenerators'; 14 | import { PATH_ROOT, WATCH_DELAY, WATCH_TEMPLATES } from '../constants'; 15 | import { Command } from 'commander'; 16 | import displayCommandGreetings from '../helpers/displayCommandGreetings'; 17 | import displayCommandStep from '../helpers/displayCommandStep'; 18 | import displayCommandDone from '../helpers/displayCommandDone'; 19 | import createEmptyDirectory from '../helpers/createEmptyDirectory'; 20 | import { execSync } from "child_process"; 21 | 22 | function trigger(cmd: Command, pathToCli: string, pathToLibrary: string, pathToTarget: string, show: boolean = false) { 23 | try { 24 | const command = `node ${pathToCli} generate --library ${pathToLibrary} --target ${pathToTarget}`; 25 | const result = execSync(command).toString().trim(); 26 | 27 | show && console.log(result); 28 | displayCommandStep(cmd, colors.green('The library successfully updated')); 29 | } catch (error) { 30 | displayCommandStep(cmd, colors.red(error.message)); 31 | displayCommandStep(cmd, colors.yellow('Something bad happened inside the generation tool')); 32 | } 33 | 34 | displayCommandStep(cmd, colors.blue('Waiting for changes...')); 35 | } 36 | 37 | export default function watch(program: Command) { 38 | program 39 | .command('watch') 40 | .description('Watch for documentation changes and generate new documentation library on every change') 41 | .requiredOption('--library ', 'Path to the source library (where you store your components)') 42 | .requiredOption('--target ', 'Path to the target library (where to store generated library documentations)') 43 | .action((cmd) => { 44 | displayCommandGreetings(cmd); 45 | 46 | const pathToPackage = path.resolve(PATH_ROOT, 'package.json'); 47 | const pathToLibrary = path.resolve(cmd.library); 48 | const pathToTarget = path.resolve(cmd.target); 49 | 50 | displayCommandStep(cmd, colors.blue.bold('Watch for documentation for whole library')); 51 | displayCommandStep(cmd, `${colors.bold('Path to watch changes in')}: ${colors.italic(pathToLibrary)}`); 52 | displayCommandStep(cmd, `${colors.bold('Path to the target library documentation')}: ${colors.italic(pathToTarget)}`); 53 | 54 | // create package instance 55 | const that = new Package({ path: pathToPackage }); 56 | 57 | // resolve path to the cli tool 58 | const pathToCli = path.resolve(PATH_ROOT, that.cli); 59 | if (!fs.existsSync(pathToCli)) { 60 | displayCommandStep(cmd, colors.red('Unable to resolve path to the cli tool: looks like tool problem')); 61 | process.exit(0); 62 | } 63 | 64 | // run first time generation 65 | displayCommandStep(cmd, colors.blue('Generate for the first time...')); 66 | trigger(cmd, pathToCli, pathToLibrary, pathToTarget, true); 67 | 68 | // watching for changes 69 | const templatesToWatch = WATCH_TEMPLATES.map((template) => `${pathToLibrary}${template}`); 70 | watcher(templatesToWatch, { delay: WATCH_DELAY }, (done) => { 71 | trigger(cmd, pathToCli, pathToLibrary, pathToTarget); 72 | done(); 73 | }); 74 | }); 75 | }; 76 | -------------------------------------------------------------------------------- /system/constants.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import resolvePackagePath from './helpers/resolvePackagePath'; 3 | import Import from "./imports/Import"; 4 | import DefaultImport from "./imports/DefaultImport"; 5 | import NamespaceImport from "./imports/NamespaceImport"; 6 | import generateUniqueIdentifier from './helpers/generateUniqueIdentifier'; 7 | 8 | export const PATH_ROOT = resolvePackagePath(__dirname); 9 | export const PATH_TEMPLATE = path.resolve(PATH_ROOT, 'template'); 10 | 11 | export const DOCUMENTATION_PATH_SUFFIX = 'Documentation'; 12 | export const DOCUMENTATION_PATH_EXTENSION = 'svelte'; 13 | export const DOCUMENTATION_VARIABLE_RAW = generateUniqueIdentifier(); 14 | export const DOCUMENTATION_VARIABLE_DEFINITION = generateUniqueIdentifier(); 15 | export const DOCUMENTATION_VARIABLE_INITIALIZATION = generateUniqueIdentifier(); 16 | 17 | export const WATCH_DELAY = 1000; 18 | export const WATCH_TEMPLATES = ['/**/*']; 19 | 20 | export const IMPORT_SPECIFIER_TO_MODEL = { 21 | ImportSpecifier: Import, 22 | ImportDefaultSpecifier: DefaultImport, 23 | ImportNamespaceSpecifier: NamespaceImport 24 | }; 25 | -------------------------------------------------------------------------------- /system/exports/BaseExport.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { Declaration, ExportNamedDeclaration, Literal, Node, SourceLocation } from 'estree'; 3 | import Location from '../models/Location'; 4 | 5 | export namespace BaseExportSpace { 6 | export type Config = { 7 | data: ExportNamedDeclaration; 8 | } 9 | 10 | export type Result = {}; 11 | } 12 | 13 | export default abstract class BaseExport extends Base { 14 | 15 | public data: ExportNamedDeclaration; 16 | 17 | public abstract get declaration(): Declaration; 18 | 19 | public abstract get name(): string; 20 | 21 | public abstract get result(): BaseExportSpace.Result; 22 | 23 | public get location(): Location { 24 | const data = this.data.loc as SourceLocation; 25 | return new Location({ data }); 26 | } 27 | 28 | protected static resolveDefaultValue(node: Node): any { 29 | if (node.type === 'Literal') { 30 | const literal = node as Literal; 31 | return literal.value; 32 | } else if (node.type === 'ObjectExpression') { 33 | // TODO Parse properties structure in desired value. 34 | // const objectExpression = assigment.right as ObjectExpression; 35 | return {}; 36 | } 37 | 38 | return undefined; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /system/exports/ClassExport.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { ClassDeclaration, ExportNamedDeclaration, Node } from 'estree'; 3 | import BaseExport, { BaseExportSpace } from './BaseExport'; 4 | import { FunctionExportSpace } from './FunctionExport'; 5 | 6 | export namespace ClassExportSpace { 7 | export type Config = {}; 8 | 9 | export type Result = {}; 10 | } 11 | 12 | export default class ClassExport extends BaseExport { 13 | 14 | public get declaration(): ClassDeclaration { 15 | throw new ReferenceError('Not implemented'); 16 | } 17 | 18 | public get name(): string { 19 | throw new ReferenceError('Not implemented'); 20 | } 21 | 22 | public get result(): BaseExportSpace.Result { 23 | throw new ReferenceError('Not implemented'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /system/exports/FunctionExport.ts: -------------------------------------------------------------------------------- 1 | import parse from 'comment-parser'; 2 | import Base from '../base/Base'; 3 | import { 4 | AssignmentPattern, 5 | ExportNamedDeclaration, 6 | FunctionDeclaration, 7 | Identifier, 8 | Literal, 9 | Node, 10 | ObjectExpression 11 | } from 'estree'; 12 | import BaseExport, { BaseExportSpace } from './BaseExport'; 13 | import Description from '../models/Description'; 14 | import { LocationSpace } from '../models/Location'; 15 | 16 | export namespace FunctionExportSpace { 17 | export type Config = {}; 18 | 19 | export type Result = { 20 | arguments: Argument[]; 21 | description: string | false, 22 | tags: parse.Tag[], 23 | location: LocationSpace.Result 24 | }; 25 | 26 | export type Argument = { 27 | name: string; 28 | default?: any; 29 | }; 30 | } 31 | 32 | export default class FunctionExport extends BaseExport { 33 | 34 | public get declaration(): FunctionDeclaration { 35 | return this.data.declaration as FunctionDeclaration; 36 | } 37 | 38 | public get name(): string { 39 | return (this.declaration.id as Identifier).name; 40 | } 41 | 42 | public get jsdoc(): parse.Comment | false { 43 | if (!this.data.leadingComments) { 44 | return false; 45 | } 46 | 47 | // parse only block comments 48 | const comment = this.data.leadingComments[0]; 49 | if (comment.type !== 'Block') { 50 | return false; 51 | } 52 | 53 | // parse only jsdoc comments 54 | // comment value should be like 55 | // `*\n* Hello!\n* @returns {string}\n` 56 | if (!comment.value.match(/^\*[^*]/)) { 57 | return false; 58 | } 59 | 60 | // make jsdoc comment block 61 | const raw = `/*${comment.value}*/`; 62 | const parsed = parse(raw); 63 | if (!parsed) { 64 | return false; 65 | } 66 | 67 | return parsed[0]; 68 | } 69 | 70 | public get description(): Description | false { 71 | if (!this.jsdoc) { 72 | if (!this.data.leadingComments) { 73 | return false; 74 | } 75 | 76 | return new Description({ comments: this.data.leadingComments }); 77 | } 78 | 79 | const content = this.jsdoc.description; 80 | const data = { type: 'Block', value: content }; 81 | return new Description({ comments: [data] }); 82 | } 83 | 84 | public get tags(): any { 85 | if (!this.jsdoc) { 86 | return []; 87 | } 88 | 89 | return this.jsdoc.tags; 90 | } 91 | 92 | public get arguments(): FunctionExportSpace.Argument[] { 93 | const declaration = this.data.declaration as FunctionDeclaration; 94 | if (!declaration.params) { 95 | return []; 96 | } 97 | 98 | const args: FunctionExportSpace.Argument[] = []; 99 | for (const param of declaration.params) { 100 | let name = '?'; 101 | let value; 102 | if (param.type === 'Identifier') { 103 | const identifier = param as Identifier; 104 | name = identifier.name; 105 | } else if (param.type === 'AssignmentPattern') { 106 | const assigment = param as AssignmentPattern; 107 | const identifier = assigment.left as Identifier; 108 | name = identifier.name; 109 | value = FunctionExport.resolveDefaultValue(assigment.right); 110 | } 111 | 112 | args.push({ name, default: value }); 113 | } 114 | 115 | return args; 116 | } 117 | 118 | public get result(): FunctionExportSpace.Result { 119 | return { 120 | arguments: this.arguments, 121 | description: this.description && this.description.markdown, 122 | tags: this.tags, 123 | location: this.location.result 124 | }; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /system/exports/VariableExport.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import BaseExport, { BaseExportSpace } from './BaseExport'; 3 | import { 4 | FunctionDeclaration, 5 | Identifier, 6 | Literal, 7 | SourceLocation, 8 | VariableDeclaration, 9 | VariableDeclarator 10 | } from 'estree'; 11 | import Description from '../models/Description'; 12 | import Location, { LocationSpace } from '../models/Location'; 13 | 14 | export namespace VariableExportSpace { 15 | export type Config = {}; 16 | 17 | export type Result = { 18 | default: any; 19 | constant: boolean; 20 | description: string | undefined; 21 | note: string | undefined; 22 | location: LocationSpace.Result; 23 | }; 24 | } 25 | 26 | export default class VariableExport extends BaseExport { 27 | 28 | public get declaration(): VariableDeclaration { 29 | return this.data.declaration as VariableDeclaration; 30 | } 31 | 32 | public get declarator(): VariableDeclarator { 33 | return this.declaration.declarations[0] as VariableDeclarator; 34 | } 35 | 36 | public get kind(): string { 37 | return this.declaration.kind; 38 | } 39 | 40 | public get constant(): boolean { 41 | return this.kind === 'const'; 42 | } 43 | 44 | public get name(): string { 45 | return (this.declarator.id as Identifier).name; 46 | } 47 | 48 | public get default(): any { 49 | if (!this.declarator.init) { 50 | return undefined; 51 | } 52 | 53 | return VariableExport.resolveDefaultValue(this.declarator.init); 54 | } 55 | 56 | public get description(): Description | undefined { 57 | if (!this.data.leadingComments) { 58 | return undefined; 59 | } 60 | 61 | return new Description({ comments: this.data.leadingComments }); 62 | } 63 | 64 | public get note(): Description | undefined { 65 | if (!this.data.trailingComments) { 66 | return undefined; 67 | } 68 | 69 | return new Description({ comments: this.data.trailingComments }); 70 | } 71 | 72 | public get result(): VariableExportSpace.Result { 73 | return { 74 | default: this.default, 75 | constant: this.constant, 76 | description: this.description && this.description.markdown, 77 | note: this.note && this.note.markdown, 78 | location: this.location.result 79 | }; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /system/helpers/createEmptyDirectory.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra'; 2 | 3 | export default function createEmptyDirectory(path: string) { 4 | fs.existsSync(path) && fs.removeSync(path); 5 | fs.mkdirSync(path, { recursive: true }); 6 | } 7 | -------------------------------------------------------------------------------- /system/helpers/displayCommandDone.ts: -------------------------------------------------------------------------------- 1 | import colors from 'colors/safe'; 2 | import { Command } from 'commander'; 3 | import displayCommandStep from './displayCommandStep'; 4 | 5 | export default function displayCommandDone(cmd: Command) { 6 | displayCommandStep(cmd, colors.green('The task was successful')); 7 | }; 8 | -------------------------------------------------------------------------------- /system/helpers/displayCommandGreetings.ts: -------------------------------------------------------------------------------- 1 | import colors from 'colors/safe'; 2 | import { Command } from 'commander'; 3 | 4 | export default function displayCommandGreetings(cmd: Command) { 5 | console.log(`[${colors.blue(cmd.name())}] ${cmd.description()}`); 6 | }; 7 | -------------------------------------------------------------------------------- /system/helpers/displayCommandStep.ts: -------------------------------------------------------------------------------- 1 | import colors from 'colors/safe'; 2 | import moment from 'moment'; 3 | import { Command } from 'commander'; 4 | 5 | export default function displayCommandStep(cmd: Command, message: string) { 6 | const timestamp = moment().format('HH:mm:ss'); 7 | console.log(`[${timestamp}] [${colors.blue(cmd.name())}] ${message}`); 8 | }; 9 | -------------------------------------------------------------------------------- /system/helpers/encodeSpecialChars.ts: -------------------------------------------------------------------------------- 1 | export default function encodeSpecialChars(source: string): string { 2 | return source 3 | .replace(/&/g, '&') 4 | .replace(/>/g, '>') 5 | .replace(/ { 6 | return { 7 | name: generator.name, 8 | title: generator.documentation.title, 9 | } 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /system/helpers/resolvePackagePath.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra'; 2 | import * as path from 'path'; 3 | 4 | export default function resolvePackagePath(directory: string): string { 5 | const possible = path.resolve(directory, 'package.json'); 6 | if (!fs.existsSync(possible)) { 7 | const parent = path.dirname(directory); 8 | return resolvePackagePath(parent); 9 | } 10 | 11 | return directory; 12 | } 13 | -------------------------------------------------------------------------------- /system/helpers/resolveRelativeImports.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | export default function resolveRelativeImports(source: string, originalPath: string, targetPath: string) { 4 | const { dir: originalDir } = path.parse(originalPath); 5 | const { dir: targetDir } = path.parse(targetPath); 6 | const relative = path.relative(targetDir, originalDir); 7 | const relativeDir = path.dirname(relative); 8 | 9 | // please, keep order of the replacements 10 | // this is important to replace `../` first 11 | // and then replace `./` 12 | return source 13 | .replace(/(import\s*["'])(\.\.\/)/g, `$1${relativeDir}/`) 14 | .replace(/(import\s*["'])(\.\/)/g, `$1${relative}/`) 15 | .replace(/(from\s*["'])(\.\.\/)/g, `$1${relativeDir}/`) 16 | .replace(/(from\s*["'])(\.\/)/g, `$1${relative}/`); 17 | } 18 | -------------------------------------------------------------------------------- /system/imports/DefaultImport.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { ClassDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier } from 'estree'; 3 | import BaseImport from './BaseImport'; 4 | 5 | export namespace DefaultImportSpace { 6 | export type Config = { 7 | specifier: ImportDefaultSpecifier; 8 | }; 9 | } 10 | 11 | export default class DefaultImport extends BaseImport { 12 | 13 | public specifier: ImportNamespaceSpecifier; 14 | 15 | public resolveTags(pathName: string[]): string[] { 16 | throw new ReferenceError('Not implemented'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /system/imports/Import.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { ImportSpecifier } from 'estree'; 3 | import BaseImport from './BaseImport'; 4 | 5 | export namespace ImportSpace { 6 | export type Config = { 7 | specifier: ImportSpecifier; 8 | }; 9 | } 10 | 11 | export default class Import extends BaseImport { 12 | 13 | public specifier: ImportSpecifier; 14 | 15 | public resolveTags(namePath: string[]): string[] { 16 | const base = namePath[0]; 17 | if (this.specifier.imported.name === base) { 18 | return this.resolveTagReplacements( 19 | this.specifier.local.name, 20 | namePath.slice(1) 21 | ); 22 | } 23 | 24 | return []; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /system/imports/NamespaceImport.ts: -------------------------------------------------------------------------------- 1 | import Base from '../base/Base'; 2 | import { ImportNamespaceSpecifier, ImportSpecifier } from 'estree'; 3 | import BaseImport from './BaseImport'; 4 | 5 | export namespace NamespaceImportSpace { 6 | export type Config = { 7 | specifier: ImportNamespaceSpecifier; 8 | }; 9 | } 10 | 11 | export default class NamespaceImport extends BaseImport { 12 | 13 | public specifier: ImportNamespaceSpecifier; 14 | 15 | public resolveTags(namePath: string[]): string[] { 16 | return this.resolveTagReplacements(this.specifier.local.name, namePath); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /system/models/Attribute.ts: -------------------------------------------------------------------------------- 1 | import { Declaration, ExportNamedDeclaration, Node, SourceLocation } from 'estree'; 2 | import { Script as SvelteScript, Var } from 'svelte/types/compiler/interfaces'; 3 | import Base from '../base/Base'; 4 | import FunctionExport, { FunctionExportSpace } from '../exports/FunctionExport'; 5 | import VariableExport, { VariableExportSpace } from '../exports/VariableExport'; 6 | import ClassExport, { ClassExportSpace } from '../exports/ClassExport'; 7 | import { ExportType } from '../types/ExportType'; 8 | import { BaseExportSpace } from '../exports/BaseExport'; 9 | import { ExportResultType } from '../types/ExportResultType'; 10 | import { ScriptSpace } from './Script'; 11 | import generateUniqueIdentifier from '../helpers/generateUniqueIdentifier'; 12 | import Variable from './Variable'; 13 | 14 | export namespace AttributeSpace { 15 | export type Config = { 16 | name: string; 17 | value: any; 18 | } 19 | } 20 | 21 | export default class Attribute extends Base { 22 | 23 | public name: string; 24 | 25 | public value: any; 26 | 27 | public get raw() { 28 | return `${this.name}=${this.compiled}`; 29 | } 30 | 31 | public get compiled() { 32 | if (this.value instanceof Variable) { 33 | return `{${this.value.name}}`; 34 | } 35 | 36 | const formatted = this.value 37 | .replace(/\n/g, '\\n') 38 | .replace(/"/g, '\\"'); 39 | return `"${formatted}"`; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /system/models/Component.ts: -------------------------------------------------------------------------------- 1 | import Script, { ScriptSpace } from './Script'; 2 | import SvelteSource from '../base/SvelteSource'; 3 | import { SourceSpace } from '../base/Source'; 4 | import { Script as SvelteScript } from 'svelte/types/compiler/interfaces'; 5 | 6 | export namespace ComponentSpace { 7 | export type Config = { 8 | path: string; 9 | } 10 | 11 | export type Result = { 12 | module: ScriptSpace.Definition | undefined; 13 | instance: ScriptSpace.Definition | undefined; 14 | } 15 | } 16 | 17 | export default class Component extends SvelteSource { 18 | 19 | public get definition(): ComponentSpace.Result { 20 | return { 21 | module: this.module 22 | ? this.module.definition : undefined, 23 | instance: this.instance 24 | ? this.instance.definition : undefined 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /system/models/Description.ts: -------------------------------------------------------------------------------- 1 | import { Declaration, ExportNamedDeclaration, Node } from 'estree'; 2 | import { Script as SvelteScript, Var } from 'svelte/types/compiler/interfaces'; 3 | import Base from '../base/Base'; 4 | import FunctionExport, { FunctionExportSpace } from '../exports/FunctionExport'; 5 | import VariableExport, { VariableExportSpace } from '../exports/VariableExport'; 6 | import ClassExport, { ClassExportSpace } from '../exports/ClassExport'; 7 | import { ExportType } from '../types/ExportType'; 8 | import { BaseExportSpace } from '../exports/BaseExport'; 9 | import { ExportResultType } from '../types/ExportResultType'; 10 | import resolveMarkdownFromComment from '../helpers/resolveMarkdownFromComment'; 11 | 12 | export namespace DescriptionSpace { 13 | export type Config = { 14 | comments: Data[]; 15 | } 16 | 17 | export type Data = { 18 | type: string; 19 | value: string; 20 | } 21 | } 22 | 23 | export default class Description extends Base { 24 | 25 | public comments: DescriptionSpace.Data[]; 26 | 27 | public get markdown(): string { 28 | const strings = this.comments.map((comment) => comment.value); 29 | return strings.map(resolveMarkdownFromComment).join(' \n'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /system/models/Dictionary.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra'; 2 | import Source from '../base/Source'; 3 | import { ItemType } from '../types/ItemType'; 4 | 5 | export namespace IndexSpace { 6 | export type Config = { 7 | items: ItemType[]; 8 | } 9 | } 10 | 11 | export default class Dictionary extends Source { 12 | 13 | public items: ItemType[]; 14 | 15 | public generate() { 16 | const names = this.items.map(({ name }) => name); 17 | const imports = this.items.map(({ name }) => `import ${name} from './${name}';`); 18 | 19 | const items = this.items.map(({ name, title }) => { 20 | const slashed = (title || name).replace(/'/g, '\\\''); 21 | return `{ name: '${name}', title: '${slashed}', component: ${name} }`; 22 | }); 23 | 24 | const exportDefault = `export default [\n ${items.join(',\n ')}\n];`; 25 | const exportCollection = `export { ${names.join(', ')} };`; 26 | 27 | const content = `${imports.join('\n')}\n\n${exportDefault}\n\n${exportCollection}`; 28 | fs.writeFileSync(this.path, content); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /system/models/Location.ts: -------------------------------------------------------------------------------- 1 | import { Declaration, ExportNamedDeclaration, Node, SourceLocation } from 'estree'; 2 | import { Script as SvelteScript, Var } from 'svelte/types/compiler/interfaces'; 3 | import Base from '../base/Base'; 4 | import FunctionExport, { FunctionExportSpace } from '../exports/FunctionExport'; 5 | import VariableExport, { VariableExportSpace } from '../exports/VariableExport'; 6 | import ClassExport, { ClassExportSpace } from '../exports/ClassExport'; 7 | import { ExportType } from '../types/ExportType'; 8 | import { BaseExportSpace } from '../exports/BaseExport'; 9 | import { ExportResultType } from '../types/ExportResultType'; 10 | import { ScriptSpace } from './Script'; 11 | 12 | export namespace LocationSpace { 13 | export type Config = { 14 | data: SourceLocation; 15 | } 16 | 17 | export type Result = SourceLocation; 18 | } 19 | 20 | export default class Location extends Base { 21 | 22 | public data: SourceLocation; 23 | 24 | public get result(): LocationSpace.Result { 25 | return this.data; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /system/models/Package.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import Source from '../base/Source'; 3 | 4 | export namespace PackageSpace { 5 | export type Config = { 6 | path: string; 7 | }; 8 | 9 | export type Data = { 10 | name: string; 11 | version: string; 12 | bin: { [key: string]: string }; 13 | } 14 | } 15 | 16 | export default class Package extends Source { 17 | 18 | public get data(): PackageSpace.Data { 19 | const content = fs.readFileSync(this.path).toString(); 20 | return JSON.parse(content); 21 | } 22 | 23 | public get name(): string { 24 | return this.data.name; 25 | } 26 | 27 | public get version(): string { 28 | return this.data.version; 29 | } 30 | 31 | public get cli(): string { 32 | return this.data.bin[this.name]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /system/models/Router.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra'; 2 | import Source from '../base/Source'; 3 | import { ItemType } from '../types/ItemType'; 4 | 5 | export namespace RouterSpace { 6 | export type Config = { 7 | routes: ItemType[]; 8 | } 9 | } 10 | 11 | export default class Router extends Source { 12 | 13 | public routes: ItemType[]; 14 | 15 | public generate() { 16 | const imports = this.routes.map(({ name }) => `import ${name} from './${name}';`); 17 | const items = this.routes.map(({ name, title }) => { 18 | return `{ name: ${JSON.stringify(name)}, title: ${JSON.stringify(title)}, component: ${name} }`; 19 | }); 20 | 21 | const content = `${imports.join('\n')}\n\nexport default [\n ${items.join(',\n ')}\n];`; 22 | fs.writeFileSync(this.path, content); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /system/models/Variable.ts: -------------------------------------------------------------------------------- 1 | import { Declaration, ExportNamedDeclaration, Node, SourceLocation } from 'estree'; 2 | import { Script as SvelteScript, Var } from 'svelte/types/compiler/interfaces'; 3 | import Base from '../base/Base'; 4 | import FunctionExport, { FunctionExportSpace } from '../exports/FunctionExport'; 5 | import VariableExport, { VariableExportSpace } from '../exports/VariableExport'; 6 | import ClassExport, { ClassExportSpace } from '../exports/ClassExport'; 7 | import { ExportType } from '../types/ExportType'; 8 | import { BaseExportSpace } from '../exports/BaseExport'; 9 | import { ExportResultType } from '../types/ExportResultType'; 10 | import { ScriptSpace } from './Script'; 11 | import generateUniqueIdentifier from '../helpers/generateUniqueIdentifier'; 12 | 13 | export namespace VariableSpace { 14 | export type Config = { 15 | name?: string; 16 | value: any; 17 | asPlaceholder?: boolean; 18 | } 19 | } 20 | 21 | export default class Variable extends Base { 22 | 23 | private _name: string; 24 | 25 | public value: any; 26 | 27 | public asPlaceholder: boolean; 28 | 29 | public defaults = { 30 | value: false, 31 | asPlaceholder: false 32 | }; 33 | 34 | public get name(): string { 35 | if (!this._name) { 36 | this._name = generateUniqueIdentifier('var${id}'); 37 | } 38 | 39 | return this._name; 40 | } 41 | 42 | public set name(value: string) { 43 | this._name = value; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /system/partials/DescriptionPartial.ts: -------------------------------------------------------------------------------- 1 | import BasePartial, { BasePartialSpace } from './BasePartial'; 2 | import encodeSpecialChars from '../helpers/encodeSpecialChars'; 3 | import Variable from '../models/Variable'; 4 | import Attribute from '../models/Attribute'; 5 | 6 | export namespace DescriptionPartialSpace { 7 | export type Config = {} 8 | } 9 | 10 | export default class DescriptionPartial extends BasePartial { 11 | 12 | public static get tag(): string { 13 | return 'Component.Description'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /system/partials/MainPartial.ts: -------------------------------------------------------------------------------- 1 | import BasePartial, { BasePartialSpace } from './BasePartial'; 2 | import Variable from '../models/Variable'; 3 | import Attribute from '../models/Attribute'; 4 | import { 5 | DOCUMENTATION_VARIABLE_DEFINITION, 6 | DOCUMENTATION_VARIABLE_INITIALIZATION, 7 | DOCUMENTATION_VARIABLE_RAW 8 | } from '../constants'; 9 | 10 | export namespace MainPartialSpace { 11 | export type Config = {} 12 | } 13 | 14 | export default class MainPartial extends BasePartial { 15 | 16 | public static get tag(): string { 17 | return 'Component'; 18 | } 19 | 20 | public generate(variables: Variable[] = [], attributes: Attribute[] = [], withContent: boolean = true): BasePartialSpace.Generated { 21 | // use global name to pass source code attribute to the component 22 | const rawVariable = new Variable({ 23 | name: DOCUMENTATION_VARIABLE_RAW, 24 | value: undefined, 25 | asPlaceholder: true 26 | }); 27 | 28 | // use global name to pass definitions attribute to the component 29 | const definitionVariable = new Variable({ 30 | name: DOCUMENTATION_VARIABLE_DEFINITION, 31 | value: undefined, 32 | asPlaceholder: true 33 | }); 34 | 35 | // use global name to pass initialization attribute to the component 36 | const initializationVariable = new Variable({ 37 | name: DOCUMENTATION_VARIABLE_INITIALIZATION, 38 | value: undefined, 39 | asPlaceholder: true 40 | }); 41 | 42 | const rawAttribute = new Attribute({ name: 'raw', value: rawVariable }); 43 | const definitionAttribute = new Attribute({ name: 'definition', value: definitionVariable }); 44 | const initializationAttribute = new Attribute({ name: 'initialization', value: initializationVariable }); 45 | 46 | return super.generate( 47 | [...variables, rawVariable, initializationVariable, definitionVariable], 48 | [...attributes, rawAttribute, initializationAttribute, definitionAttribute] 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /system/partials/UsagePartial.ts: -------------------------------------------------------------------------------- 1 | import BasePartial from './BasePartial'; 2 | 3 | export namespace UsagePartialSpace { 4 | export type Config = {} 5 | } 6 | 7 | export default class UsagePartial extends BasePartial { 8 | 9 | public static get tag(): string { 10 | return 'Component.Usage'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /system/types/ExportResultType.ts: -------------------------------------------------------------------------------- 1 | import FunctionExport, { FunctionExportSpace } from '../exports/FunctionExport'; 2 | import VariableDeclaration, { VariableExportSpace } from '../exports/VariableExport'; 3 | import ClassExport, { ClassExportSpace } from '../exports/ClassExport'; 4 | 5 | export type ExportResultType = FunctionExportSpace.Result | VariableExportSpace.Result | ClassExportSpace.Result; 6 | -------------------------------------------------------------------------------- /system/types/ExportType.ts: -------------------------------------------------------------------------------- 1 | import FunctionExport from '../exports/FunctionExport'; 2 | import VariableDeclaration from '../exports/VariableExport'; 3 | import ClassExport from '../exports/ClassExport'; 4 | 5 | export type ExportType = FunctionExport | VariableDeclaration | ClassExport; 6 | -------------------------------------------------------------------------------- /system/types/ImportType.ts: -------------------------------------------------------------------------------- 1 | import FunctionExport from '../exports/FunctionExport'; 2 | import VariableDeclaration from '../exports/VariableExport'; 3 | import ClassExport from '../exports/ClassExport'; 4 | import NamespaceImport from '../imports/NamespaceImport'; 5 | import Import from '../imports/Import'; 6 | 7 | export type ImportType = Import | NamespaceImport; 8 | -------------------------------------------------------------------------------- /system/types/ItemType.ts: -------------------------------------------------------------------------------- 1 | export type ItemType = { 2 | name: string; 3 | title: string | undefined; 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /system/types/PartialType.ts: -------------------------------------------------------------------------------- 1 | import UsagePartial from '../partials/UsagePartial'; 2 | import MainPartial from '../partials/MainPartial'; 3 | import DescriptionPartial from '../partials/DescriptionPartial'; 4 | 5 | export type PartialType = UsagePartial | MainPartial | DescriptionPartial; 6 | 7 | export type PartialClassType = typeof UsagePartial | typeof MainPartial | typeof DescriptionPartial; 8 | -------------------------------------------------------------------------------- /template/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .git 4 | node_modules 5 | build 6 | package-lock.json 7 | 8 | # ignore compiled library 9 | /site/library/ 10 | -------------------------------------------------------------------------------- /template/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /template/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "your-svelte-library", 3 | "version": "0.1.0", 4 | "main": "index.js", 5 | "private": true, 6 | "scripts": { 7 | "start": "npm run docs:generate && npm run webpack:start", 8 | "build": "npm run docs:generate && npm run webpack:build", 9 | "webpack:start": "node ./node_modules/.bin/webpack-dev-server --mode development", 10 | "webpack:build": "node ./node_modules/.bin/webpack --mode production", 11 | "docs:watch": "node ./node_modules/.bin/svelte-doc-generator watch --library ./src/components --target ./site/library", 12 | "docs:generate": "node ./node_modules/.bin/svelte-doc-generator generate --library ./src/components --target ./site/library" 13 | }, 14 | "author": "Ivan", 15 | "license": "ISC", 16 | "devDependencies": { 17 | "clean-webpack-plugin": "3.0.0", 18 | "copy-webpack-plugin": "5.0.3", 19 | "css-loader": "2.1.1", 20 | "cssnano": "4.1.10", 21 | "file-loader": "3.0.1", 22 | "html-webpack-plugin": "3.2.0", 23 | "mini-css-extract-plugin": "0.7.0", 24 | "postcss": "7.0.18", 25 | "postcss-automath": "1.0.1", 26 | "postcss-each": "0.10.0", 27 | "postcss-for": "2.1.1", 28 | "postcss-import": "12.0.1", 29 | "postcss-loader": "3.0.0", 30 | "postcss-mixins": "6.2.2", 31 | "postcss-nested": "4.1.2", 32 | "postcss-preset-env": "6.6.0", 33 | "postcss-simple-vars": "5.0.2", 34 | "raw-loader": "3.1.0", 35 | "style-loader": "0.23.1", 36 | "svelte": "3.12.1", 37 | "svelte-loader": "2.13.4", 38 | "svelte-preprocess": "2.15.0", 39 | "svelte-routing": "1.2.0", 40 | "url-loader": "1.1.2", 41 | "webpack": "4.28.4", 42 | "webpack-cli": "3.3.3", 43 | "webpack-dev-server": "3.7.1" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /template/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PIK-Arenda Frontend team 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /template/site/App.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /template/site/constants.js: -------------------------------------------------------------------------------- 1 | export const URI_TO_COMPONENTS = '/components'; 2 | -------------------------------------------------------------------------------- /template/site/context.js: -------------------------------------------------------------------------------- 1 | let library = []; 2 | try { 3 | library = require('./library').default; 4 | } catch (error) { 5 | if (typeof console !== 'undefined') { 6 | console.error ? console.error(error) : console.log(error); 7 | } 8 | } 9 | 10 | export default library; 11 | -------------------------------------------------------------------------------- /template/site/helpers/addProductionHash.js: -------------------------------------------------------------------------------- 1 | module.exports = function addProductionHash(template, isProduction = false) { 2 | if (!isProduction) { 3 | return template; 4 | } 5 | 6 | const PART_TO_REPLACE = '[name]'; 7 | const PART_TO_APPEND = '[contenthash]'; 8 | if (template.indexOf(PART_TO_REPLACE) < 0) { 9 | throw new Error( 10 | `Unable to find '[name]' part inside file template to add production hash in ${template}` 11 | ); 12 | } 13 | 14 | return template.replace( 15 | PART_TO_REPLACE, 16 | `${PART_TO_REPLACE}.${PART_TO_APPEND}` 17 | ); 18 | }; 19 | -------------------------------------------------------------------------------- /template/site/index.js: -------------------------------------------------------------------------------- 1 | import App from './App.svelte'; 2 | 3 | // import styles 4 | import 'svelte-doc-generator/build/interface/index.css'; 5 | 6 | // create the app 7 | new App({ target: document.body }); 8 | -------------------------------------------------------------------------------- /template/site/pages/ComponentPage.svelte: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /template/site/pages/DefaultPage.svelte: -------------------------------------------------------------------------------- 1 | ← Chose one from the components. 2 | -------------------------------------------------------------------------------- /template/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 5 | const addProductionHash = require('./site/helpers/addProductionHash'); 6 | 7 | const rootDir = path.resolve(__dirname); 8 | 9 | const config = (isProduction, defaultConfig) => ({ 10 | ...defaultConfig, 11 | 12 | entry: { 13 | index: path.resolve(rootDir, 'site', 'index.js') 14 | }, 15 | 16 | output: { 17 | path: path.resolve(rootDir, 'build'), 18 | filename: addProductionHash('[name].js', isProduction), 19 | publicPath: '/' 20 | }, 21 | 22 | resolve: { 23 | // we have to specify absolute path to node modules 24 | // because we want to be able to take index entry from non-project directory 25 | modules: [path.resolve(__dirname, 'node_modules'), 'node_modules'], 26 | extensions: ['.mjs', '.js', '.svelte', '.json'], 27 | alias: { 28 | // something strange happen without thins line and with `npm link pik-arenda-landings-ui-kit` 29 | // webpack uses svelte from `pik-arenda-landings-ui-kit` node modules 30 | // do not touch this line, bro... okay???? 31 | svelte: path.resolve(__dirname, 'node_modules', 'svelte') 32 | } 33 | }, 34 | 35 | module: { 36 | rules: [ 37 | { 38 | test: /\.svelte$/, 39 | exclude: /node_modules\/(?!svelte)/, 40 | use: [ 41 | { 42 | loader: 'svelte-loader', 43 | options: { 44 | preprocess: require('svelte-preprocess')({ postcss: true }), 45 | emitCss: true, 46 | hotReload: true, 47 | dev: !isProduction 48 | } 49 | } 50 | ] 51 | }, 52 | { 53 | test: [/\.css$/, /\.pcss$/], 54 | use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'] 55 | }, 56 | { 57 | test: /\.less$/, 58 | loader: 'less-loader', 59 | }, 60 | { 61 | loader: 'file-loader', 62 | test: [ 63 | /\.svg$/, 64 | /\.jpe?g$/, 65 | /\.png$/, 66 | /\.woff2$/, 67 | /\.woff$/, 68 | /\.ttf$/, 69 | /\.eot$/ 70 | ], 71 | options: { 72 | name: addProductionHash('[name].[ext]', isProduction) 73 | } 74 | } 75 | ] 76 | }, 77 | 78 | plugins: [ 79 | new CleanWebpackPlugin(), 80 | 81 | new MiniCssExtractPlugin({ 82 | filename: addProductionHash('[name].css') 83 | }), 84 | 85 | new HtmlWebpackPlugin({ 86 | inject: true, 87 | template: './public/index.html' 88 | }) 89 | ], 90 | 91 | devServer: { 92 | publicPath: '/', 93 | overlay: true, 94 | compress: true, 95 | historyApiFallback: { 96 | disableDotRule: true 97 | } 98 | } 99 | }); 100 | 101 | module.exports = (_, { mode }) => { 102 | const isProduction = mode === 'production'; 103 | return config(isProduction); 104 | }; 105 | --------------------------------------------------------------------------------