From 10d25de7a1b6808035c658c65e49243597a6f634 Mon Sep 17 00:00:00 2001 From: Fran Guijarro Date: Fri, 24 Nov 2017 11:14:36 -0300 Subject: [PATCH 1/3] Doc generating code refactor - made with typescript - more tests (also typechecked) - better API.md output - reduced dependencies - overall better expressed code --- .gitignore | 2 +- API.md | 145 +++---- README.md | 1 + docs-src/README.md | 21 -- docs-src/absoluteToRelativePathHelper.js | 7 - docs-src/build.js | 47 --- docs-src/commentsHelper.js | 34 -- docs-src/commentsHelper.test.js | 33 -- docs-src/data.js | 55 --- docs-src/fnHelper.js | 44 --- docs-src/fnHelper.test.js | 88 ----- docs-src/helpers.js | 37 -- docs-src/interfaceHelper.js | 56 --- docs-src/interfaceHelper.test.js | 267 ------------- docs-src/itemHelper.js | 32 -- docs-src/itemTitleHelper.js | 15 - docs-src/itemTitleHelper.test.js | 22 -- docs-src/kindStringHelper.js | 9 - docs-src/moduleHelper.js | 14 - docs-src/objectHelper.js | 27 -- docs-src/objectHelper.test.js | 95 ----- docs-src/propertyHelper.js | 7 - docs-src/srcHelper.js | 6 - docs-src/srcHelper.test.js | 20 - docs-src/typeAliasHelper.js | 58 --- docs-src/typeHelper.js | 51 --- docs-src/typeHelper.test.js | 19 - docs-src/typeLiteralHelper.js | 157 -------- docs-src/variableHelper.js | 11 - docs-src/view/API.hbs | 13 - docs-src/view/fn.hbs | 7 - docs-src/view/object.hbs | 9 - .../view/README.hbs => docs/README.tpl.md | 3 +- docs/buildApi.ts | 23 ++ docs/buildReadme.ts | 38 ++ docs/index.ts | 9 + docs/src/Context.ts | 10 + docs/src/components.ts | 355 ++++++++++++++++++ docs/src/helpers.ts | 62 +++ docs/src/preprocessData.ts | 54 +++ docs/src/tests/helperRenderTitle.ts | 27 ++ docs/src/tests/renderFunction.ts | 29 ++ docs/src/tests/renderFunctionFixture.ts | 100 +++++ docs/src/tests/renderInterface.ts | 50 +++ docs/src/tests/renderInterfaceFixture.ts | 43 +++ docs/src/tests/renderInterfaceFixture2.ts | 237 ++++++++++++ docs/src/tests/renderObjectLiteral.ts | 25 ++ docs/src/tests/renderObjectLiteralFixture.ts | 241 ++++++++++++ docs/src/tests/renderType.ts | 23 ++ docs/src/tests/renderTypeAlias.ts | 22 ++ docs/src/tests/renderTypeAliasFixture.ts | 88 +++++ docs/src/tests/renderTypeFixture.ts | 27 ++ docs/src/tests/renderTypeFixture2.ts | 7 + docs/src/types.ts | 38 ++ docs/tsconfig.json | 19 + package.json | 16 +- yarn.lock | 70 +++- 57 files changed, 1661 insertions(+), 1364 deletions(-) delete mode 100644 docs-src/README.md delete mode 100644 docs-src/absoluteToRelativePathHelper.js delete mode 100644 docs-src/build.js delete mode 100644 docs-src/commentsHelper.js delete mode 100644 docs-src/commentsHelper.test.js delete mode 100644 docs-src/data.js delete mode 100644 docs-src/fnHelper.js delete mode 100644 docs-src/fnHelper.test.js delete mode 100644 docs-src/helpers.js delete mode 100644 docs-src/interfaceHelper.js delete mode 100644 docs-src/interfaceHelper.test.js delete mode 100644 docs-src/itemHelper.js delete mode 100644 docs-src/itemTitleHelper.js delete mode 100644 docs-src/itemTitleHelper.test.js delete mode 100644 docs-src/kindStringHelper.js delete mode 100644 docs-src/moduleHelper.js delete mode 100644 docs-src/objectHelper.js delete mode 100644 docs-src/objectHelper.test.js delete mode 100644 docs-src/propertyHelper.js delete mode 100644 docs-src/srcHelper.js delete mode 100644 docs-src/srcHelper.test.js delete mode 100644 docs-src/typeAliasHelper.js delete mode 100644 docs-src/typeHelper.js delete mode 100644 docs-src/typeHelper.test.js delete mode 100644 docs-src/typeLiteralHelper.js delete mode 100644 docs-src/variableHelper.js delete mode 100644 docs-src/view/API.hbs delete mode 100644 docs-src/view/fn.hbs delete mode 100644 docs-src/view/object.hbs rename docs-src/view/README.hbs => docs/README.tpl.md (99%) create mode 100644 docs/buildApi.ts create mode 100644 docs/buildReadme.ts create mode 100644 docs/index.ts create mode 100644 docs/src/Context.ts create mode 100644 docs/src/components.ts create mode 100644 docs/src/helpers.ts create mode 100644 docs/src/preprocessData.ts create mode 100644 docs/src/tests/helperRenderTitle.ts create mode 100644 docs/src/tests/renderFunction.ts create mode 100644 docs/src/tests/renderFunctionFixture.ts create mode 100644 docs/src/tests/renderInterface.ts create mode 100644 docs/src/tests/renderInterfaceFixture.ts create mode 100644 docs/src/tests/renderInterfaceFixture2.ts create mode 100644 docs/src/tests/renderObjectLiteral.ts create mode 100644 docs/src/tests/renderObjectLiteralFixture.ts create mode 100644 docs/src/tests/renderType.ts create mode 100644 docs/src/tests/renderTypeAlias.ts create mode 100644 docs/src/tests/renderTypeAliasFixture.ts create mode 100644 docs/src/tests/renderTypeFixture.ts create mode 100644 docs/src/tests/renderTypeFixture2.ts create mode 100644 docs/src/types.ts create mode 100644 docs/tsconfig.json diff --git a/.gitignore b/.gitignore index 20a3d81..b58aa07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules coverage -docs/ +docsTmp/ docsContent.json diff --git a/API.md b/API.md index d33f04f..e763668 100644 --- a/API.md +++ b/API.md @@ -3,7 +3,6 @@ > Autogenerated from source code # index Module [src](./src/index.ts#L1) - ## Reform Object literal [src](./src/index.ts#L22) `default` export for the entire library. @@ -20,15 +19,14 @@
 {
-core: [./src/core](#user-content-#178)
-reactHelpers: [./src/reactHelpers](#user-content-#201)
-reactMixins: [./src/reactMixins](#user-content-#233)
-types: [./src/types](#user-content-#1)
-validators: [./src/validators](./src/validators)
+  core: [./src/core](#user-content-#178)
+  reactHelpers: [./src/reactHelpers](#user-content-#201)
+  reactMixins: [./src/reactMixins](#user-content-#233)
+  types: [./src/types](#user-content-#1)
+  validators: [./src/validators](./src/validators)
 }
 
# core Module [src](./src/core.ts#L1) - ## fieldIsValid Function [src](./src/core.ts#L73) Evaluate whether a field is valid or not. @@ -128,7 +126,6 @@ validateForm(fieldsValues: [Fields](#user-content-#21), rulesMap: [RulesMap](#us # reactHelpers Module [src](./src/reactHelpers.ts#L1) - ## fieldErrors Function [src](./src/reactHelpers.ts#L242) Another error helper to make displaying field errors easier. Instead of `fieldIfError` which @@ -157,7 +154,7 @@ Tags
-fieldErrors(fieldName: string): Array\
+fieldErrors(fieldName: string): Array\<[string, any]\>
 
## fieldIfError Function [src](./src/reactHelpers.ts#L203) @@ -347,22 +344,21 @@ validateFormFromState(): boolean # reactMixins Module [src](./src/reactMixins.ts#L1) - ## IReform Interface [src](./src/reactMixins.ts#L13) Handy interface that contains attributes corresponding to each `Reform.reactHelpers.*` method.
 {
-fieldErrors: [fieldErrors](#user-content-#227);
-fieldIfError: [fieldIfError](#user-content-#223);
-fieldIsValid: [fieldIsValid](#user-content-#218);
-formIsValid: [formIsValid](#user-content-#221);
-mapFieldErrors: [mapFieldErrors](#user-content-#230);
-validateField: [validateField](#user-content-#206);
-validateFieldFromState: [validateFieldFromState](#user-content-#210);
-validateForm: [validateForm](#user-content-#213);
-validateFormFromState: [validateFormFromState](#user-content-#216)
+  fieldErrors: [fieldErrors](#user-content-#227)
+  fieldIfError: [fieldIfError](#user-content-#223)
+  fieldIsValid: [fieldIsValid](#user-content-#218)
+  formIsValid: [formIsValid](#user-content-#221)
+  mapFieldErrors: [mapFieldErrors](#user-content-#230)
+  validateField: [validateField](#user-content-#206)
+  validateFieldFromState: [validateFieldFromState](#user-content-#210)
+  validateForm: [validateForm](#user-content-#213)
+  validateFormFromState: [validateFormFromState](#user-content-#216)
 }
 
## functionalMixin Function [src](./src/reactMixins.ts#L76) @@ -415,7 +411,6 @@ objectMixin(that: [ValidationAbleInstance](#user-content-#24)): [IReform](#user- # validators Module [src](./src/validators.ts#L1) - ## validatorInterface Object literal [src](./src/validators.ts#L18) Main validator interface. @@ -433,86 +428,86 @@ Use it if you want to add new global custom validators.
 {
-get: get(key: string): [Validator](#user-content-#2)
-set: set(key: string, value: [Validator](#user-content-#2)): void
+  get: get(key: string): [Validator](#user-content-#2)
+  set: set(key: string, value: [Validator](#user-content-#2)): void
 }
 
# types Module [src](./src/types.ts#L1) - ## FieldErrors Interface [src](./src/types.ts#L17)
 {
-\[ruleKey: string\]: boolean
+  \[ruleKey: string\]: boolean
 }
 
## Fields Interface [src](./src/types.ts#L25)
 {
-\[fieldName: string\]: any
+  \[fieldName: string\]: any
 }
 
## FormErrors Interface [src](./src/types.ts#L21)
 {
-\[fieldName: string\]: [FieldErrors](#user-content-#15)
+  \[fieldName: string\]: [FieldErrors](#user-content-#15)
 }
 
## Rules Interface [src](./src/types.ts#L9)
 {
-\[ruleKey: string\]: boolean | string | [Validator](#user-content-#2) | any
+  \[ruleKey: string\]: boolean | string | [Validator](#user-content-#2) | any
 }
 
## RulesMap Interface [src](./src/types.ts#L13)
 {
-\[fieldName: string\]: [Rules](#user-content-#9)
+  \[fieldName: string\]: [Rules](#user-content-#9)
 }
 
## ValidationAbleInstance Interface [src](./src/types.ts#L35)
 {
-setState: any;
-state: {
-  errors: [FormErrors](#user-content-#18);
-  fields: [Fields](#user-content-#21);
-  formIsDirty: boolean
-};
-validationMessages: {
-  \[ruleKey: string\]: [MessageCreator](#user-content-#36)
-};
-validationRules: [RulesMap](#user-content-#12)
+  setState: any
+  state:
+  {
+    errors: [FormErrors](#user-content-#18)
+    fields: [Fields](#user-content-#21)
+    formIsDirty: boolean
+  }
+  validationMessages:
+  {
+    \[ruleKey: string\]: [MessageCreator](#user-content-#36)
+  }
+  validationRules: [RulesMap](#user-content-#12)
 }
 
## Validator Interface [src](./src/types.ts#L1)
 {
-(value: string | number | any, ruleValue: any): boolean
+  (value: string | number | any, ruleValue: any): boolean
 }
 
## ValidatorMap Interface [src](./src/types.ts#L5)
 {
-\[ruleKey: string\]: [Validator](#user-content-#2)
+  \[ruleKey: string\]: [Validator](#user-content-#2)
 }
 
## MessageCreator Type alias [src](./src/types.ts#L29)
 {
-(ruleArgument: any, ruleKey: string, fieldName: string): string
+  (ruleArgument: any, ruleKey: string, fieldName: string): string
 }
 
# officialValidators/index Module [src](./src/officialValidators/index.ts#L1) - ## validatorMap Object literal [src](./src/officialValidators/index.ts#L65) These are all the official validators HTML5 validators. @@ -557,33 +552,32 @@ this.validationRules = {
 {
-maxDate: [maxDate](#user-content-#91)
-maxMonth: [maxMonth](#user-content-#101)
-maxNumber: [maxNumber](#user-content-#81)
-maxTime: [maxTime](#user-content-#111)
-maxWeek: [maxWeek](#user-content-#121)
-minDate: [minDate](#user-content-#86)
-minMonth: [minMonth](#user-content-#96)
-minNumber: [minNumber](#user-content-#76)
-minTime: [minTime](#user-content-#106)
-minWeek: [minWeek](#user-content-#116)
-month: [month](#user-content-#68)
-number: [Validator](#user-content-#2)
-range: [Validator](#user-content-#2)
-time: [time](#user-content-#64)
-url: [url](#user-content-#46)
-week: [week](#user-content-#72)
-color: color(value: any): boolean
-date: date(value: any): boolean
-email: email(value: string): boolean
-maxLength: maxLength(value: string, maxLength: number): boolean
-minLength: minLength(value: string, minLength: number): boolean
-pattern: pattern(value: string, re: RegExp): boolean
-required: required(value: any): boolean
+  maxDate: [maxDate](#user-content-#91)
+  maxMonth: [maxMonth](#user-content-#101)
+  maxNumber: [maxNumber](#user-content-#81)
+  maxTime: [maxTime](#user-content-#111)
+  maxWeek: [maxWeek](#user-content-#121)
+  minDate: [minDate](#user-content-#86)
+  minMonth: [minMonth](#user-content-#96)
+  minNumber: [minNumber](#user-content-#76)
+  minTime: [minTime](#user-content-#106)
+  minWeek: [minWeek](#user-content-#116)
+  month: [month](#user-content-#68)
+  number: [Validator](#user-content-#2)
+  range: [Validator](#user-content-#2)
+  time: [time](#user-content-#64)
+  url: [url](#user-content-#46)
+  week: [week](#user-content-#72)
+  color: color(value: any): boolean
+  date: date(value: any): boolean
+  email: email(value: string): boolean
+  maxLength: maxLength(value: string, maxLength: number): boolean
+  minLength: minLength(value: string, minLength: number): boolean
+  pattern: pattern(value: string, re: RegExp): boolean
+  required: required(value: any): boolean
 }
 
# officialValidators/minMonth Module [src](./src/officialValidators/minMonth.ts#L1) - ## minMonth Function [src](./src/officialValidators/minMonth.ts#L4) @@ -593,7 +587,6 @@ minMonth(value: string, min: string): boolean # officialValidators/minNumber Module [src](./src/officialValidators/minNumber.ts#L1) - ## minNumber Function [src](./src/officialValidators/minNumber.ts#L1) @@ -603,7 +596,6 @@ minNumber(value: number | string, min: number | string): boolean # officialValidators/maxMonth Module [src](./src/officialValidators/maxMonth.ts#L1) - ## maxMonth Function [src](./src/officialValidators/maxMonth.ts#L4) @@ -613,7 +605,6 @@ maxMonth(value: string, max: string): boolean # officialValidators/minWeek Module [src](./src/officialValidators/minWeek.ts#L1) - ## minWeek Function [src](./src/officialValidators/minWeek.ts#L4) @@ -623,7 +614,6 @@ minWeek(value: string, min: string): boolean # officialValidators/minDate Module [src](./src/officialValidators/minDate.ts#L1) - ## minDate Function [src](./src/officialValidators/minDate.ts#L1) @@ -633,7 +623,6 @@ minDate(value: string, min: string): boolean # officialValidators/time Module [src](./src/officialValidators/time.ts#L1) - ## time Function [src](./src/officialValidators/time.ts#L5) @@ -643,7 +632,6 @@ time(value: string): boolean # officialValidators/url Module [src](./src/officialValidators/url.ts#L1) - ## url Function [src](./src/officialValidators/url.ts#L11) @@ -653,7 +641,6 @@ url(value: string): boolean # officialValidators/week Module [src](./src/officialValidators/week.ts#L1) - ## week Function [src](./src/officialValidators/week.ts#L6) @@ -663,7 +650,6 @@ week(value: string): boolean # officialValidators/maxDate Module [src](./src/officialValidators/maxDate.ts#L1) - ## maxDate Function [src](./src/officialValidators/maxDate.ts#L1) @@ -673,7 +659,6 @@ maxDate(value: string, max: string): boolean # officialValidators/maxWeek Module [src](./src/officialValidators/maxWeek.ts#L1) - ## maxWeek Function [src](./src/officialValidators/maxWeek.ts#L4) @@ -683,7 +668,6 @@ maxWeek(value: string, max: string): boolean # officialValidators/maxNumber Module [src](./src/officialValidators/maxNumber.ts#L1) - ## maxNumber Function [src](./src/officialValidators/maxNumber.ts#L1) @@ -693,7 +677,6 @@ maxNumber(value: number | string, max: number | string): boolean # officialValidators/maxTime Module [src](./src/officialValidators/maxTime.ts#L1) - ## maxTime Function [src](./src/officialValidators/maxTime.ts#L3) @@ -703,7 +686,6 @@ maxTime(value: string, max: string): boolean # officialValidators/minTime Module [src](./src/officialValidators/minTime.ts#L1) - ## minTime Function [src](./src/officialValidators/minTime.ts#L3) @@ -713,7 +695,6 @@ minTime(value: string, min: string): boolean # officialValidators/month Module [src](./src/officialValidators/month.ts#L1) - ## month Function [src](./src/officialValidators/month.ts#L4) @@ -723,13 +704,12 @@ month(value: string): boolean # utils Module [src](./src/utils.ts#L1) - ## parseMonth Function [src](./src/utils.ts#L3)
-parseMonth(value: string): undefined
+parseMonth(value: string): Array\
 
## parseTime Function [src](./src/utils.ts#L49) @@ -745,7 +725,7 @@ parseTime(time: string): number
-parseWeek(value: string): undefined
+parseWeek(value: string): Array\
 
## weeksInYear Function [src](./src/utils.ts#L36) @@ -755,4 +735,3 @@ parseWeek(value: string): undefined
 weeksInYear(year: number): number
 
- diff --git a/README.md b/README.md index ac4572c..e02f980 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,7 @@ export default class GettingStarted extends Component { ); } } + ``` ## Validators diff --git a/docs-src/README.md b/docs-src/README.md deleted file mode 100644 index ffbd861..0000000 --- a/docs-src/README.md +++ /dev/null @@ -1,21 +0,0 @@ -## Doc generators - -This is a complete quick and dirty solution for -automatic rendering the libraries API. - -If you check the code you are going to have nightmares but I didn't -have the time to put it all together correctly and it serves it's purpose. - -Contributions and clean up are more than welcome. - -We use the json output of `type-doc` and render some stuff with that. - - -### TODO - -- Instead of passing around several parameters we should have a context object that contains useful value, for example - - level of indentation - - inline - - etc -- Use typescript for better sanity and semantics (only if ...Arr is supported inside an array) -- Move back all the functions to a single file to avoid nasty inline `require` to avoid circular dependencies. The nature of this all is recursive so no need to circle that point diff --git a/docs-src/absoluteToRelativePathHelper.js b/docs-src/absoluteToRelativePathHelper.js deleted file mode 100644 index 3dd932d..0000000 --- a/docs-src/absoluteToRelativePathHelper.js +++ /dev/null @@ -1,7 +0,0 @@ -const path = require('path') - -module.exports = -function absoluteToRelativePathHelper(absolutePath) { - const root = path.resolve(__dirname, '../'); - return './' + path.relative(root, absolutePath) -} diff --git a/docs-src/build.js b/docs-src/build.js deleted file mode 100644 index b2b5c02..0000000 --- a/docs-src/build.js +++ /dev/null @@ -1,47 +0,0 @@ -const fs = require('fs') -const path = require('path') -const Handlebars = require('handlebars'); -require('./helpers') -const docsContent = require('./data'); - -const partialsDir = __dirname + '/view' - -const toCompile = [ - { - tplFileName: '/API.hbs', - outputFileName: '../API.md', - data: docsContent, - }, - { - tplFileName: '/README.hbs', - outputFileName: '../README.md', - }, -] - -partialsBootstrap(); - -toCompile.forEach(config => { - const tplFileName = path.resolve(partialsDir + config.tplFileName); - const outputFileName = path.resolve(__dirname, config.outputFileName); - console.log(`COMPILING ${tplFileName} -> ${outputFileName}`) - - const template = fs.readFileSync(tplFileName, 'utf-8'); - const result = Handlebars.compile(template)(config.data); - fs.writeFileSync(outputFileName, result, 'utf-8'); - //console.log(result); - console.log("SUCCESS") -}) - - -function partialsBootstrap() { - const filenames = fs.readdirSync(partialsDir); - filenames.forEach(function (filename) { - const matches = /^([^.]+).hbs$/.exec(filename); - if (!matches) { - return; - } - const name = matches[1]; - const template = fs.readFileSync(partialsDir + '/' + filename, 'utf8'); - Handlebars.registerPartial(name, template); - }); -} diff --git a/docs-src/commentsHelper.js b/docs-src/commentsHelper.js deleted file mode 100644 index d1cddc3..0000000 --- a/docs-src/commentsHelper.js +++ /dev/null @@ -1,34 +0,0 @@ -const commonTags = require('common-tags'); - -module.exports = -function commentsHelper(comment = {}) { - const { shortText = '', text = ''} = comment; - - - const content = []; - if (comment.shortText && comment.text) { - content.push(comment.shortText); - content.push(''); - content.push(comment.text); - - } else if (comment.shortText) { - content.push(comment.shortText); - } else if (comment.text) { - content.push(comment.text); - } - - const tags = comment.tags || []; - const contentTags = []; - if (tags.length) { - contentTags.push('Tags'); - contentTags.push('\n'); - contentTags.push(tags.map(tag => `- ${tag.tag} ${tag.text}`).join('\n')) - } - - return [ - ...content, - '', - ...contentTags, - ].join('\n') -} - diff --git a/docs-src/commentsHelper.test.js b/docs-src/commentsHelper.test.js deleted file mode 100644 index c1f614a..0000000 --- a/docs-src/commentsHelper.test.js +++ /dev/null @@ -1,33 +0,0 @@ -const test = require('tape'); -const commentsHelper = require('./commentsHelper'); - -const comment = { - shortText: "test 123", - text: " test 456", - tags: [ - { - "tag": "a_tag", - "text": "\n" - } - ] -} - - -test('commentsHelper', function (t) { - t.plan(1); - - const result = commentsHelper(comment); - const expected = ([ - 'test 123', - '', - ' test 456', - '', - 'Tags', - '', - '', - '- a_tag ', - '', - ].join('\n')); - - t.equal(result, expected); -}); diff --git a/docs-src/data.js b/docs-src/data.js deleted file mode 100644 index 0ea229c..0000000 --- a/docs-src/data.js +++ /dev/null @@ -1,55 +0,0 @@ -const fs = require('fs') -const docsContent = require('../docsContent.json'); - - -const FIRST_CHILDREN_ORDER = { - 'index': 1, - 'core': 2, - 'reactHelpers': 3, - 'reactMixins': 5, - 'validators': 6, - 'types': 7, - 'officialValidators/index': 8, - 'utils': 200, -} - -const removeQuotes = str => str.replace(/"/g, '') -function removeQuotesFromName(module) { - module.name = removeQuotes(module.name) - return module; -} - -function ignoredModules(module) { - //TODO dont ignore but push the bottom - //if (module.name.includes('officialValidators') && module.name !== 'officialValidators/index') { - //return false; - //} - - return true -} - -function hiddenDeclarations(dec) { - if (dec.comment && JSON.stringify(dec.comment).includes('@hidden')) { - return false - } - - return true -} - -docsContent.children = docsContent.children - .map(removeQuotesFromName) - .filter(ignoredModules) - .sort((a, b) => { - const a_order = FIRST_CHILDREN_ORDER[a.name] || 100; - const b_order = FIRST_CHILDREN_ORDER[b.name] || 100; - return a_order > b_order ? 1 : -1; - }) - .map(module => { - module.children = (module.children || []) - .filter(hiddenDeclarations) - - return module; - }); - - -module.exports = docsContent; diff --git a/docs-src/fnHelper.js b/docs-src/fnHelper.js deleted file mode 100644 index 37f2a77..0000000 --- a/docs-src/fnHelper.js +++ /dev/null @@ -1,44 +0,0 @@ -const commonTags = require('common-tags'); -const typeHelper = require('./typeHelper'); -const itemTitleHelper = require('./itemTitleHelper'); -const commentsHelper = require('./commentsHelper'); - - -function fnSignatureHelper(item) { - const params = (item.parameters || []).map(param => `${param.name}: ${typeHelper(param.type)}`).join(', '); - const signature = `(${params}): ${typeHelper(item.type)}`; - - // Special case for inline, anonymous function signaruters in interfaces - if (item.name === '__call') { - return signature - } - - return `${item.name}${signature}`; -} - - -function fnHelper(item = {}, inline) { - if (inline) { - return (item.signatures || []).map(sign => `${fnSignatureHelper(sign)}`).join(' | ') - } - - const signatures = item.signatures.map(sign => [ - ``, - `${commentsHelper(sign.comment)}`, - ``, - `
`,
-      `${fnSignatureHelper(sign)}`,
-      `
`, - ``, - ].join('\n') - ); - - return [ - `## ${itemTitleHelper(item)}`, - ...signatures, - ].join('\n') -} - - -fnHelper.fnSignatureHelper = fnSignatureHelper; -module.exports = fnHelper; diff --git a/docs-src/fnHelper.test.js b/docs-src/fnHelper.test.js deleted file mode 100644 index 77ab4c6..0000000 --- a/docs-src/fnHelper.test.js +++ /dev/null @@ -1,88 +0,0 @@ -const test = require('tape'); -const fnHelper = require('./fnHelper'); - - - -test('fnHelper', function (t) { - t.plan(1); - - const result = fnHelper(src); - const expected = ([ - '## formIsValid Function [src](./src/core.ts#L119) ', - '', - 'comments', - '', - '', - '
',
-    'formIsValid(fieldsValues: [Fields](#user-content-#21)): boolean',
-    '
', - '', - '', - 'commentsr2', - '', - '', - '
',
-    'formIsValid(fieldsValues2: [Fields](#user-content-#21)): boolean',
-    '
', - '', - ].join('\n')); - - t.equal(result, expected); -}); - -const src = { - id: 1, - name: "formIsValid", - kindString: "Function", - "signatures": [ - { - "id": 2, - "name": "formIsValid", - "kindString": "Call signature", - "comment": { "shortText": "comments" }, - "parameters": [ - { - "id": 3, - "name": "fieldsValues", - "kindString": "Parameter", - "type": { - "type": "reference", - "name": "Fields", - "id": 21 - } - }, - ], - "type": { - "type": "instrinct", - "name": "boolean" - } - }, - { - "id": 21, - "name": "formIsValid", - "kindString": "Call signature", - "comment": { "shortText": "commentsr2" }, - "parameters": [ - { - "id": 3, - "name": "fieldsValues2", - "kindString": "Parameter", - "type": { - "type": "reference", - "name": "Fields", - "id": 21 - } - }, - ], - "type": { - "type": "instrinct", - "name": "boolean" - } - } - ], - "sources": [{ - "fileName": "core.ts", - "line": 119, - "character": 27 - }] -} diff --git a/docs-src/helpers.js b/docs-src/helpers.js deleted file mode 100644 index d49186b..0000000 --- a/docs-src/helpers.js +++ /dev/null @@ -1,37 +0,0 @@ -const fs = require('fs') -const path = require('path') -const Handlebars = require('handlebars'); -const commonTags = require('common-tags'); -const commentsHelper = require('./commentsHelper'); -const itemTitleHelper = require('./itemTitleHelper'); -const objectHelper = require('./objectHelper'); -const srcHelper = require('./srcHelper'); -const itemHelper = require('./itemHelper'); - -Handlebars.registerHelper({ - ifEqual: function(v1, v2, options) { - if(v1 === v2) { - return options.fn(this); - } - return options.inverse(this); - }, - includeFile: function(filePath) { - const file = fs.readFileSync(filePath, 'utf8'); - return file; - }, - - noNewLines: function(options) { - let str = options.fn(this); - return str.replace(/\n/g, ''); - }, - noWhitespace: function(options) { - let str = options.fn(this); - return str.replace(/\s*/g, 'a'); - }, - trimWhitespace: function(options) { - let str = options.fn(this); - return str.split('\n').map(line => line.trim()).join('\n') - }, - - item: itemHelper, -}); diff --git a/docs-src/interfaceHelper.js b/docs-src/interfaceHelper.js deleted file mode 100644 index a074564..0000000 --- a/docs-src/interfaceHelper.js +++ /dev/null @@ -1,56 +0,0 @@ -const commentsHelper = require('./commentsHelper') -const itemTitleHelper = require('./itemTitleHelper'); -const itemHelper = require('./itemHelper'); -const typeHelper = require('./typeHelper'); -const fnHelper = require('./fnHelper') - - -module.exports = -function interfaceHelper(item = {}, inline){ - - const content = []; - - if (item.children) { - content.push(item.children.map(child => { - return `${require('./itemHelper')(child, true, 2)}` - }) - .join(';\n') - ) - } - - if (item.indexSignature) { - content.push(item.indexSignature.map(ind => { - const params = ind.parameters - const param = params[0] - return `\\[${param.name}: ${typeHelper(param.type, true)}\\]: ${typeHelper(ind.type)}` - }) - .join(';\n') - ) - } - - if (item.signatures) { - content.push(item.signatures.map(sig => { - return `${fnHelper.fnSignatureHelper(sig)}`; - }) - .join(';\n') - ) - } - - const obj = [ - '
',
-    '{',
-    ...content,
-    '}',
-    '
', - ] - - if (inline) { - return obj.join('\n'); - } - - return [ - `## ${itemTitleHelper(item)}`, - `${commentsHelper(item.comment)}`, - ...obj, - ].join('\n'); -} diff --git a/docs-src/interfaceHelper.test.js b/docs-src/interfaceHelper.test.js deleted file mode 100644 index 70c2a70..0000000 --- a/docs-src/interfaceHelper.test.js +++ /dev/null @@ -1,267 +0,0 @@ -const test = require('tape'); -const interfaceHelper = require('./interfaceHelper'); - - - -test('interfaceHelper', function (t) { - t.plan(1); - - const result = interfaceHelper(src); - const expected = ([ - '## ValidationAbleInstance Interface [src](./src/types.ts#L29) ', - '', - '
',
-    '{',
-    'setState: any;',
-    'state: {',
-    '  errors: [FormErrors](#user-content-#18);',
-    '  fields: [Fields](#user-content-#21);',
-    '  formIsDirty: boolean',
-    '};',
-    'validationMessages: {',
-    '  \\[ruleKey: string\\]: [MessageCreator](#user-content-#36)',
-    '};',
-    'validationRules: [RulesMap](#user-content-#12)',
-    '}',
-    '
', - ].join('\n')); - - t.equal(result, expected); -}); - -const src = { - "id": 24, - "name": "ValidationAbleInstance", - "kind": 256, - "kindString": "Interface", - "flags": { - "isExported": true - }, - "children": [ - { - "id": 35, - "name": "setState", - "kind": 1024, - "kindString": "Property", - "flags": { - "isExported": true - }, - "sources": [ - { - "fileName": "types.ts", - "line": 41, - "character": 10 - } - ], - "type": { - "type": "instrinct", - "name": "any" - } - }, - { - "id": 30, - "name": "state", - "kind": 1024, - "kindString": "Property", - "flags": { - "isExported": true - }, - "sources": [ - { - "fileName": "types.ts", - "line": 35, - "character": 7 - } - ], - "type": { - "type": "reflection", - "declaration": { - "id": 31, - "name": "__type", - "kind": 65536, - "kindString": "Type literal", - "flags": {}, - "children": [ - { - "id": 33, - "name": "errors", - "kind": 32, - "kindString": "Variable", - "flags": {}, - "sources": [ - { - "fileName": "types.ts", - "line": 37, - "character": 10 - } - ], - "type": { - "type": "reference", - "name": "FormErrors", - "id": 18 - } - }, - { - "id": 32, - "name": "fields", - "kind": 32, - "kindString": "Variable", - "flags": {}, - "sources": [ - { - "fileName": "types.ts", - "line": 36, - "character": 10 - } - ], - "type": { - "type": "reference", - "name": "Fields", - "id": 21 - } - }, - { - "id": 34, - "name": "formIsDirty", - "kind": 32, - "kindString": "Variable", - "flags": { - "isOptional": true - }, - "sources": [ - { - "fileName": "types.ts", - "line": 38, - "character": 15 - } - ], - "type": { - "type": "instrinct", - "name": "boolean" - } - } - ], - "groups": [ - { - "title": "Variables", - "kind": 32, - "children": [ - 33, - 32, - 34 - ] - } - ], - "sources": [ - { - "fileName": "types.ts", - "line": 35, - "character": 8 - } - ] - } - } - }, - { - "id": 26, - "name": "validationMessages", - "kind": 1024, - "kindString": "Property", - "flags": { - "isExported": true, - "isOptional": true - }, - "sources": [ - { - "fileName": "types.ts", - "line": 31, - "character": 20 - } - ], - "type": { - "type": "reflection", - "declaration": { - "id": 27, - "name": "__type", - "kind": 65536, - "kindString": "Type literal", - "flags": {}, - "indexSignature": [ - { - "id": 28, - "name": "__index", - "kind": 8192, - "kindString": "Index signature", - "flags": {}, - "parameters": [ - { - "id": 29, - "name": "ruleKey", - "kind": 32768, - "kindString": "Parameter", - "flags": {}, - "type": { - "type": "instrinct", - "name": "string" - } - } - ], - "type": { - "type": "reference", - "name": "MessageCreator", - "id": 36 - } - } - ], - "sources": [ - { - "fileName": "types.ts", - "line": 31, - "character": 22 - } - ] - } - } - }, - { - "id": 25, - "name": "validationRules", - "kind": 1024, - "kindString": "Property", - "flags": { - "isExported": true - }, - "sources": [ - { - "fileName": "types.ts", - "line": 30, - "character": 17 - } - ], - "type": { - "type": "reference", - "name": "RulesMap", - "id": 12 - } - } - ], - "groups": [ - { - "title": "Properties", - "kind": 1024, - "children": [ - 35, - 30, - 26, - 25 - ] - } - ], - "sources": [ - { - "fileName": "types.ts", - "line": 29, - "character": 39 - } - ] -} diff --git a/docs-src/itemHelper.js b/docs-src/itemHelper.js deleted file mode 100644 index 5f66d9f..0000000 --- a/docs-src/itemHelper.js +++ /dev/null @@ -1,32 +0,0 @@ -const fnHelper = require('./fnHelper'); -const variableHelper = require('./variableHelper'); -const moduleHelper = require('./moduleHelper'); -const objectHelper = require('./objectHelper'); -const interfaceHelper = require('./interfaceHelper'); -const propertyHelper = require('./propertyHelper'); -const typeLiteralHelper = require('./typeLiteralHelper'); - - -module.exports = -function itemHelper(item, inline = false, indent = 0) { - switch (item.kindString) { - case 'Function': - return fnHelper(item, inline) - case 'Object literal': - return require('./objectHelper')(item, inline) - case 'Variable': - return variableHelper(item, inline) - case "External module": - return moduleHelper(item, inline) - case 'Interface': - return require('./interfaceHelper')(item, inline) - case 'Property': - return propertyHelper(item, inline, indent) - case 'Type literal': - return typeLiteralHelper(item, inline, indent) - case 'Type alias': - return require('./typeAliasHelper')(item, inline) - default: - return '' - } -} diff --git a/docs-src/itemTitleHelper.js b/docs-src/itemTitleHelper.js deleted file mode 100644 index 71e4dec..0000000 --- a/docs-src/itemTitleHelper.js +++ /dev/null @@ -1,15 +0,0 @@ -const commonTags = require('common-tags'); -const srcHelper = require('./srcHelper'); -const kindStringHelper = require('./kindStringHelper'); - - -module.exports = -function itemTitleHelper(item) { - const kindString = kindStringHelper(item.kindString); - - return commonTags.oneLine` - ${item.name} - ${kindString} [src](${srcHelper(item.sources)}) - ${item.id ? `` : '' } - `; -} diff --git a/docs-src/itemTitleHelper.test.js b/docs-src/itemTitleHelper.test.js deleted file mode 100644 index a17bff4..0000000 --- a/docs-src/itemTitleHelper.test.js +++ /dev/null @@ -1,22 +0,0 @@ -const test = require('tape'); -const itemTitleHelper = require('./itemTitleHelper'); - -const src = { - id: 1, - name: 'myItem', - kindString: 'Variable', - sources: [{ - "fileName": "core.ts", - "line": 69, - "character": 28 - }], -} - -test('itemTitleHelper', function (t) { - t.plan(1); - - const result = itemTitleHelper(src); - const expected = 'myItem Variable [src](./src/core.ts#L69) ' - - t.equal(result, expected); -}); diff --git a/docs-src/kindStringHelper.js b/docs-src/kindStringHelper.js deleted file mode 100644 index 4842f48..0000000 --- a/docs-src/kindStringHelper.js +++ /dev/null @@ -1,9 +0,0 @@ - -module.exports = -function kindStringHelper(kindString) { - if (kindString === 'External module') { - return 'Module'; - } - - return kindString; -} diff --git a/docs-src/moduleHelper.js b/docs-src/moduleHelper.js deleted file mode 100644 index 3e08df6..0000000 --- a/docs-src/moduleHelper.js +++ /dev/null @@ -1,14 +0,0 @@ -const commonTags = require('common-tags'); -const absoluteToRelativePathHelper = require('./absoluteToRelativePathHelper'); -const itemTitleHelper = require('./itemTitleHelper') - - -module.exports = -function moduleHelper(item = {}, inline) { - const filePath = absoluteToRelativePathHelper(item.originalName); - - return commonTags.stripIndent` - # ${itemTitleHelper(item)} - - `; -} diff --git a/docs-src/objectHelper.js b/docs-src/objectHelper.js deleted file mode 100644 index cef5878..0000000 --- a/docs-src/objectHelper.js +++ /dev/null @@ -1,27 +0,0 @@ -const commonTags = require('common-tags'); -const itemHelper = require('./itemHelper'); -const itemTitleHelper = require('./itemTitleHelper'); -const commentsHelper = require('./commentsHelper'); - -module.exports = -function objectHelper(item = {}, inline) { - const obj = [ - '
',
-    '{',
-    item.children
-      .map(child => `${child.name}: ${require('./itemHelper')(child, true).replace(/\n/g, '')}`)
-      .join('\n'),
-    '}',
-    '
', - ] - - if (inline) { - return obj.join('\n'); - } - - return [ - `## ${itemTitleHelper(item)}`, - `${commentsHelper(item.comment)}`, - ...obj, - ].join('\n'); -} diff --git a/docs-src/objectHelper.test.js b/docs-src/objectHelper.test.js deleted file mode 100644 index bd71c8c..0000000 --- a/docs-src/objectHelper.test.js +++ /dev/null @@ -1,95 +0,0 @@ -const test = require('tape'); -const objectHelper = require('./objectHelper'); - -const src = { - id: 1, - name: "myObject", - kindString: "Object literal", - flags: { - "isExported": true - }, - "children": [ - { - "id": 162, - "name": "maxDate", - "kind": 32, - "kindString": "Variable", - "flags": { - "isExported": true - }, - "sources": [ - { - "fileName": "officialValidators/index.ts", - "line": 41, - "character": 9 - } - ], - "type": { - "type": "reference", - "name": "(Anonymous function)", - "id": 91 - } - }, - { - "id": 162, - "name": "minDate", - "kind": 32, - "kindString": "Variable", - "flags": { - "isExported": true - }, - "sources": [ - { - "fileName": "officialValidators/index.ts", - "line": 41, - "character": 9 - } - ], - "type": { - "type": "reference", - "name": "(Anonymous function)", - "id": 91 - } - } - ], - "groups": [ - { - "title": "Functions", - "kind": 64, - "children": [ - 171, - 174 - ] - } - ], - "sources": [ - { - "fileName": "validators.ts", - "line": 4, - "character": 24 - } - ], - "type": { - "type": "instrinct", - "name": "object" - } -} - - -test('objectHelper', function (t) { - t.plan(1); - - const result = objectHelper(src, false); - const expected = ([ - '## myObject Object literal [src](./src/validators.ts#L4) ', - '', - '
',
-    '{',
-    'maxDate: Function',
-    'minDate: Function',
-    '}',
-    '
', - ].join('\n')); - - t.equal(result, expected); -}); diff --git a/docs-src/propertyHelper.js b/docs-src/propertyHelper.js deleted file mode 100644 index 940a3aa..0000000 --- a/docs-src/propertyHelper.js +++ /dev/null @@ -1,7 +0,0 @@ -const typeHelper = require('./typeHelper'); - - -module.exports = -function propertyHelper(item = {}, inline, indent) { - return `${item.name}: ${require('./typeHelper')(item.type, true, indent)}` -} diff --git a/docs-src/srcHelper.js b/docs-src/srcHelper.js deleted file mode 100644 index 72bf69f..0000000 --- a/docs-src/srcHelper.js +++ /dev/null @@ -1,6 +0,0 @@ - -module.exports = -function srcHelper(sources) { - const src = sources[0]; - return `./src/${src.fileName}#L${src.line}` -} diff --git a/docs-src/srcHelper.test.js b/docs-src/srcHelper.test.js deleted file mode 100644 index f754859..0000000 --- a/docs-src/srcHelper.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const test = require('tape'); -const srcHelper = require('./srcHelper'); - -const sources = [ - { - "fileName": "validators.ts", - "line": 4, - "character": 24 - } -]; - - -test('srcHelper', function (t) { - t.plan(1); - - const result = srcHelper(sources); - const expected = './src/validators.ts#L4'; - - t.equal(result, expected); -}); diff --git a/docs-src/typeAliasHelper.js b/docs-src/typeAliasHelper.js deleted file mode 100644 index f0853b9..0000000 --- a/docs-src/typeAliasHelper.js +++ /dev/null @@ -1,58 +0,0 @@ -const commentsHelper = require('./commentsHelper') -const itemTitleHelper = require('./itemTitleHelper'); -const itemHelper = require('./itemHelper'); -const typeHelper = require('./typeHelper'); -const fnHelper = require('./fnHelper') - - -module.exports = -function typeAliasHelper(item = {}, inline){ - - const content = []; - - if (item.type) { - content.push(`${typeHelper(item.type, true)}`) - } - - //if (item.children) { - //content.push(item.children.map(child => { - //return `${require('./itemHelper')(child, true, 2)}` - //}) - //.join(';\n') - //) - //} - - //if (item.indexSignature) { - //content.push(item.indexSignature.map(ind => { - //const params = ind.parameters - //const param = params[0] - //return `\\[${param.name}: ${typeHelper(param.type, true)}\\]: ${typeHelper(ind.type)}` - //}) - //.join(';\n') - //) - //} - - //if (item.signatures) { - //content.push(item.signatures.map(sig => { - //return `${fnHelper.fnSignatureHelper(sig)}`; - //}) - //.join(';\n') - //) - //} - - const obj = [ - '
',
-    ...content,
-    '
', - ] - - if (inline) { - return obj.join('\n'); - } - - return [ - `## ${itemTitleHelper(item)}`, - `${commentsHelper(item.comment)}`, - ...obj, - ].join('\n'); -} diff --git a/docs-src/typeHelper.js b/docs-src/typeHelper.js deleted file mode 100644 index 736d7bf..0000000 --- a/docs-src/typeHelper.js +++ /dev/null @@ -1,51 +0,0 @@ -const absoluteToRelativePathHelper = require('./absoluteToRelativePathHelper.js'); -const itemHelper = require('./itemHelper') - - - -module.exports = -function typeHelper(type = {}, inline, indent = 0) { - //Special case for re exported modules - if (type.type === 'reference' && type.name.includes('/src/')) { - const name = absoluteToRelativePathHelper(type.name.replace(/"/g,'')) - return `[${name}](#user-content-#${type.id})` - } - - if (type.type === 'union') { - return type.types.map(t => typeHelper(t)).join(' | '); - } - - if (type.type === 'stringLiteral') { - return 'String' - } - - if (type.name === "(Anonymous function)") { - return 'Function' - } - - // Inline Type literal declarations - if (type.type === 'reflection' && type.declaration && type.declaration.kindString === 'Type literal') { - return require('./itemHelper')(type.declaration, inline, indent); - } - - // sums are broken - //if (type.type === 'unknown' && type.name.includes('&')) { - //return type.name.split('&').map(s => s.trim()).map(t => typeHelper(t)).join(' & '); - //} - - let typeStr; - if (type.id) { - typeStr = `[${type.name}](#user-content-#${type.id})` - } else { - typeStr = `${type.name}` - } - - if (type.typeArguments || type.typeParameters) { - const tas = (type.typeArguments || type.typeParameters).map(ta => typeHelper(ta)).join(', ') - - typeStr += `\\<${tas}\\>` - } - - - return typeStr; -} diff --git a/docs-src/typeHelper.test.js b/docs-src/typeHelper.test.js deleted file mode 100644 index 7d366d0..0000000 --- a/docs-src/typeHelper.test.js +++ /dev/null @@ -1,19 +0,0 @@ -const test = require('tape'); -const typeHelper = require('./typeHelper'); - -const type1 = { - "type": "reference", - "name": "Validator", - "id": 2 -} - - -// TODO add more test cases -test('typeHelper', function (t) { - t.plan(1); - - const result = typeHelper(type1); - const expected = "[Validator](#user-content-#2)" - - t.equal(result, expected); -}); diff --git a/docs-src/typeLiteralHelper.js b/docs-src/typeLiteralHelper.js deleted file mode 100644 index 2d43e23..0000000 --- a/docs-src/typeLiteralHelper.js +++ /dev/null @@ -1,157 +0,0 @@ -const typeHelper = require('./typeHelper'); -const commentsHelper = require('./commentsHelper') -const itemTitleHelper = require('./itemTitleHelper'); -const fnHelper = require('./fnHelper') - -module.exports = -function typeLiteralHelper(item = {}, inline, indent = 0) { - - if (item.name === '__type') { - inline = true; - } - - const content = []; - - if (item.children) { - content.push(item.children.map(child => { - const value = require('./itemHelper')(child, true); - return `${child.name}: ${value}` - }) - .join(';\n') - ) - } - - if (item.indexSignature) { - content.push(item.indexSignature.map(ind => { - const params = ind.parameters - const param = params[0] - return `\\[${param.name}: ${require('./typeHelper')(param.type, true)}\\]: ${require('./typeHelper')(ind.type)}` - }) - .join(';\n') - ) - } - - if (item.signatures) { - content.push(item.signatures.map(sig => { - return `${fnHelper.fnSignatureHelper(sig)}`; - }) - .join(';\n') - ) - } - - - if (inline) { - return [ - '{', - ...content, - '}', - ] - .join('\n') - .split('\n') - .map((s, i, arr) => i === 0 || i + 1 === arr.length ? s : `${" ".repeat(indent)}${s}`) - .join('\n'); - } - - const obj = [ - '
',
-    '{',
-    indices,
-    children,
-    '}',
-    '
', - ] - - return [ - `## ${itemTitleHelper(item)}`, - `${commentsHelper(item.comment)}`, - ...obj, - ].join('\n'); -} - - - - //{ - //"id": 31, - //"name": "__type", - //"kind": 65536, - //"kindString": "Type literal", - //"flags": {}, - //"children": [ - //{ - //"id": 33, - //"name": "errors", - //"kind": 32, - //"kindString": "Variable", - //"flags": {}, - //"sources": [ - //{ - //"fileName": "types.ts", - //"line": 37, - //"character": 10 - //} - //], - //"type": { - //"type": "reference", - //"name": "FormErrors", - //"id": 18 - //} - //}, - //{ - //"id": 32, - //"name": "fields", - //"kind": 32, - //"kindString": "Variable", - //"flags": {}, - //"sources": [ - //{ - //"fileName": "types.ts", - //"line": 36, - //"character": 10 - //} - //], - //"type": { - //"type": "reference", - //"name": "Fields", - //"id": 21 - //} - //}, - //{ - //"id": 34, - //"name": "formIsDirty", - //"kind": 32, - //"kindString": "Variable", - //"flags": { - //"isOptional": true - //}, - //"sources": [ - //{ - //"fileName": "types.ts", - //"line": 38, - //"character": 15 - //} - //], - //"type": { - //"type": "instrinct", - //"name": "boolean" - //} - //} - //], - //"groups": [ - //{ - //"title": "Variables", - //"kind": 32, - //"children": [ - //33, - //32, - //34 - //] - //} - //], - //"sources": [ - //{ - //"fileName": "types.ts", - //"line": 35, - //"character": 8 - //} - //] - //} diff --git a/docs-src/variableHelper.js b/docs-src/variableHelper.js deleted file mode 100644 index 47deba0..0000000 --- a/docs-src/variableHelper.js +++ /dev/null @@ -1,11 +0,0 @@ -const typeHelper = require('./typeHelper'); - - -module.exports = -function variableHelper(item = {}) { - if (item.name === 'validators') { - return '[./src/validators](./src/validators)' - } - - return `${require('./typeHelper')(item.type)}` -} diff --git a/docs-src/view/API.hbs b/docs-src/view/API.hbs deleted file mode 100644 index 8b76613..0000000 --- a/docs-src/view/API.hbs +++ /dev/null @@ -1,13 +0,0 @@ -# Reform API docs - -> Autogenerated from source code - -{{#each children}} -{{#item this false}}{{/item}} - -{{#each children }} -{{#item this false}} -{{/item}} - -{{/each}} -{{/each}} diff --git a/docs-src/view/fn.hbs b/docs-src/view/fn.hbs deleted file mode 100644 index e49f647..0000000 --- a/docs-src/view/fn.hbs +++ /dev/null @@ -1,7 +0,0 @@ -{{#each signatures }} - -{{#comments comment }} -{{/comments}} - -{{#fnSignature this ~}}{{/fnSignature ~}} -{{/each}} diff --git a/docs-src/view/object.hbs b/docs-src/view/object.hbs deleted file mode 100644 index b66fe5e..0000000 --- a/docs-src/view/object.hbs +++ /dev/null @@ -1,9 +0,0 @@ -{{#each children }} - - //TODO improve the way we display de Functions/variables etc - {{#comments comment}}{{/comments}} - - - - {{name}}: {{#type type}}{{/type}} - -{{/each}} diff --git a/docs-src/view/README.hbs b/docs/README.tpl.md similarity index 99% rename from docs-src/view/README.hbs rename to docs/README.tpl.md index c80371e..9ae4c9d 100644 --- a/docs-src/view/README.hbs +++ b/docs/README.tpl.md @@ -116,8 +116,7 @@ yarn add @franleplant/reform This is a complete working example of a React Form plus Reform validation ```javascript -{{#includeFile './examples/src/GettingStarted.js'}} -{{/includeFile}} +{{includeFile './examples/src/GettingStarted.js'}} ``` ## Validators diff --git a/docs/buildApi.ts b/docs/buildApi.ts new file mode 100644 index 0000000..74321a5 --- /dev/null +++ b/docs/buildApi.ts @@ -0,0 +1,23 @@ +import { writeFileSync } from "fs"; +import * as path from "path"; +import preprocessData from "./src/preprocessData"; +import Context from "./src/Context"; +import { renderNodes } from "./src/components"; + +export default function buildApi(apiFileName: string) { + const rawSrc = require("../docsContent.json"); + const src = preprocessData(rawSrc); + const res = renderNodes(src.children, new Context()); + + const content = [ + "# Reform API docs", + "", + "> Autogenerated from source code", + "", + ...res, + ].join("\n"); + + const fileRoute = path.resolve(__dirname, apiFileName); + writeFileSync(fileRoute, content); + console.log(`BUILD API: generated ${fileRoute}`); +} diff --git a/docs/buildReadme.ts b/docs/buildReadme.ts new file mode 100644 index 0000000..cac8331 --- /dev/null +++ b/docs/buildReadme.ts @@ -0,0 +1,38 @@ +import * as fs from "fs"; +import * as path from "path"; +import * as assert from "assert"; + +export default function includeFile(inputFile: string, outputFile: string) { + const template = fs.readFileSync(path.resolve(__dirname, inputFile), { + encoding: "utf-8", + }); + const match = template.match(/{{includeFile ([^}]*)}}/); + assert(match.length > 1, "includeFile: bad match"); + const includeDirective = match[0]; + const includeFileName = match[1]; + assert( + includeFileName[0] === "'", + "includeFile: unexpected file name delimitator" + ); + assert( + includeFileName[includeFileName.length - 1] === "'", + "includeFile: unexpected file name delimitator" + ); + const includeFilePath = path.resolve( + __dirname, + "../", + includeFileName.slice(1, -1) + ); + console.log(`BUILD README: found includeFile: ${includeFilePath}`); + + const includeFileContent = fs.readFileSync(includeFilePath, { + encoding: "utf-8", + }); + const outputFileContent = template.replace( + includeDirective, + includeFileContent + ); + const outputFilePath = path.resolve(__dirname, outputFile); + fs.writeFileSync(outputFilePath, outputFileContent, { encoding: "utf-8" }); + console.log(`BUILD README: wrote successfully ${outputFilePath}`); +} diff --git a/docs/index.ts b/docs/index.ts new file mode 100644 index 0000000..b5d3423 --- /dev/null +++ b/docs/index.ts @@ -0,0 +1,9 @@ +import buildApi from "./buildApi"; +import buildReadme from "./buildReadme"; + +const README_TEMPLATE = "./README.tpl.md"; +const README_OUTPUT = "../README.md"; +const API_OUTPUT = "../API.md"; + +buildApi(API_OUTPUT); +buildReadme(README_TEMPLATE, README_OUTPUT); diff --git a/docs/src/Context.ts b/docs/src/Context.ts new file mode 100644 index 0000000..ce8a50d --- /dev/null +++ b/docs/src/Context.ts @@ -0,0 +1,10 @@ +// CoW style of context container +export default class Context { + inline: boolean = false; + + setInline(inline: boolean): Context { + const newInstance = new Context(); + newInstance.inline = inline; + return newInstance; + } +} diff --git a/docs/src/components.ts b/docs/src/components.ts new file mode 100644 index 0000000..2817cd0 --- /dev/null +++ b/docs/src/components.ts @@ -0,0 +1,355 @@ +import * as ts from "typescript"; +import * as helpers from "./helpers"; +import { TypeNode, Node } from "./types"; +import Context from "./Context"; + +//TODO renderSection and renderTypeOfNode + +const KIND_FUNCTION = 64; +const KIND_STRING_OBJECT_LITERAL = "Object literal"; +const KIND_STRING_VARIABLE = "Variable"; +const KIND_STRING_EXTERNAL_MODULE = "External module"; +const KIND_STRING_INTERFACE = "Interface"; +const KIND_STRING_PROPERTY = "Property"; +const KIND_STRING_TYPE_LITERAL = "Type literal"; +const KIND_STRING_TYPE_ALIAS = "Type alias" + +export function renderNode(node: Node, context: Context): Array { + //console.log(ts.SyntaxKind.PropertyDeclaration, ts.SyntaxKind.PropertyAssignment, ts.SyntaxKind.PropertySignature ) + //console.log(node.kind, node.kindString ) + switch (node.kind) { + case KIND_FUNCTION: + return renderFunction(node, context); + case ts.SyntaxKind.VariableDeclaration: + return renderVariable(node, context); + default: { + switch (node.kindString) { + case KIND_STRING_EXTERNAL_MODULE: + return renderExternalModule(node, context); + case KIND_STRING_INTERFACE: + return renderInterface(node, context); + case KIND_STRING_OBJECT_LITERAL: + return renderObjectLiteral(node, context); + case KIND_STRING_VARIABLE: + return renderVariable(node, context); + case KIND_STRING_PROPERTY: + return renderProperty(node, context); + case KIND_STRING_TYPE_LITERAL: + return renderTypeLiteral(node, context); + case KIND_STRING_TYPE_ALIAS: + return renderTypeAlias(node, context); + } + return []; + } + } +} + +export function renderNodes( + nodes: Array, + context: Context +): Array { + // TODO probably we need to start freezing context in different renders + //return nodes.map(node => renderNode(node, context)) + + let lines: Array = []; + nodes.forEach(node => { + lines = lines.concat(renderNode(node, context)); + }); + + return lines; +} + +export function renderFunctionSignature(node: Node, context: Context): string { + const params = (node.parameters || []) + .map(param => `${param.name}: ${renderType(param.type, context)}`) + .join(", "); + + const signature = `(${params}): ${renderType(node.type, context)}`; + + // Special case for inline, anonymous function signaruters in interfaces + if (node.name === "__call") { + return signature; + } + + return `${node.name}${signature}`; +} + +export function renderFunction(node: Node, context: Context): Array { + if (context.inline) { + return (node.signatures || []).map( + sign => `${renderFunctionSignature(sign, context)}` + ); + } + + let signatureStrings: Array = [] as any; + (node.signatures || []).forEach(signatureNode => { + const signature = [ + ``, + `${helpers.renderComments(signatureNode)}`, + ``, + `
`,
+      renderFunctionSignature(signatureNode, context),
+      `
`, + ``, + ]; + + signatureStrings = signatureStrings.concat(signature); + }); + + return [`## ${helpers.renderTitle(node)}`, ...signatureStrings]; +} + +export function renderExternalModule( + node: Node, + context: Context +): Array { + return [ + `# ${helpers.renderTitle(node)}`, + ...renderNodes(node.children, context), + ]; +} + +export function renderType( + typeNode: TypeNode, + context: Context +): Array { + //console.log('TYPE', node) + + switch (typeNode.type) { + case "array": { + if (typeNode.elementType) { + return [ + `Array\\<${renderType( + typeNode.elementType, + context.setInline(true) + )}\\>`, + ]; + } + break; + } + case "intrinsic": { + return [typeNode.name]; + } + case "tuple": { + const elements = (typeNode.elements || []) + .map(element => renderType(element, context)) + .join(", "); + + return [`[${elements}]`]; + } + case "reference": { + if (typeNode.name.includes("/src/")) { + const name = helpers.absoluteToRelativePathHelper( + typeNode.name.replace(/"/g, "") + ); + return [`[${name}](#user-content-#${typeNode.id})`]; + } + break; + } + case "reflection": + // Inline Type literal declarations + if ( + typeNode.declaration && + typeNode.declaration.kindString === "Type literal" + ) { + return renderNode(typeNode.declaration, context); + } + break; + + case "union": + const content = (typeNode.types || []) + .map(t => renderType(t, context).join(" ")) + .join(" | "); + return [content]; + case "stringLiteral": + return ["String"]; + + default: + if (typeNode.name === "(Anonymous function)") { + return ["Function"]; + } + } + // sums are broken + //if (type.type === 'unknown' && type.name.includes('&')) { + //return type.name.split('&').map(s => s.trim()).map(t => typeHelper(t)).join(' & '); + //} + + let typeStr; + if (typeNode.id) { + typeStr = `[${typeNode.name}](#user-content-#${typeNode.id})`; + } else { + typeStr = `${typeNode.name}`; + } + + if (typeNode.typeArguments || typeNode.typeParameters) { + const tas = (typeNode.typeArguments || typeNode.typeParameters) + .map((ta: TypeNode) => renderType(ta, context)) + .join(", "); + + typeStr += `\\<${tas}\\>`; + } + + return [typeStr]; +} + +export function renderObjectLiteral( + node: Node, + context: Context +): Array { + const children = (node.children || []).map( + child => + `${child.name}: ${renderNode(child, context.setInline(true)).join(" ")}` + ); + + const lines = ["
", "{", ...indent(children), "}", "
"]; + + if (context.inline) { + return lines; + } + + return [ + `## ${helpers.renderTitle(node)}`, + `${helpers.renderComments(node)}`, + ...lines, + ]; +} + +export function renderInterface(node: Node, context: Context): Array { + let children: Array = [] as any; + (node.children || []).forEach(child => { + const childContent = renderNode(child, context.setInline(true)); + let content; + if (childContent.length === 1) { + content = [`${child.name}: ${childContent.join("")}`]; + } else { + content = [`${child.name}:`, ...childContent]; + } + + children = children.concat(content); + }); + + //TODO can we use the same as the function signature? + const indexSignatures = (node.indexSignature || []).map(sig => { + const params = sig.parameters; + const param = params[0]; + return `\\[${param.name}: ${renderType( + param.type, + context + )}\\]: ${renderType(sig.type, context)}`; + }); + + const signatures = (node.signatures || []).map(sig => + renderFunctionSignature(sig, context) + ); + + const content = [ + "
",
+    "{",
+    ...indent(children),
+    ...indent(indexSignatures),
+    ...indent(signatures),
+    "}",
+    "
", + ]; + + // TODO do we really need inline interfaces? + //if (inline) { + //return content.join('\n'); + //} + + return [ + `## ${helpers.renderTitle(node)}`, + helpers.renderComments(node), + ...content, + ]; +} + +export function renderVariable(node: Node, context: Context): Array { + // Special case + if (node.name === "validators") { + return ["[./src/validators](./src/validators)"]; + } + + return renderType(node.type, context); +} + +export function renderProperty(node: Node, context: Context): Array { + if (context.inline) { + return renderType(node.type, context); + } + return [`${node.name}: ${renderType(node.type, context).join("TODO")}`]; +} + +export function renderTypeLiteral(node: Node, _context: Context): Array { + let context = _context + if (node.name === "__type") { + context = context.setInline(true) + } + + let children: Array = [] as any; + (node.children || []).forEach(child => { + const childContent = renderNode(child, context.setInline(true)); + let content; + if (childContent.length === 1) { + content = [`${child.name}: ${childContent.join("")}`]; + } else { + content = [`${child.name}:`, ...indent(childContent)]; + } + + children = children.concat(content); + }); + + //TODO can we use the same as the function signature? + const indexSignatures = (node.indexSignature || []).map(sig => { + const params = sig.parameters; + const param = params[0]; + return `\\[${param.name}: ${renderType( + param.type, + context.setInline(true) + )}\\]: ${renderType(sig.type, context.setInline(true))}`; + }); + + const signatures = (node.signatures || []).map(sig => + renderFunctionSignature(sig, context.setInline(true)) + ); + + const content = [...children, ...indexSignatures, ...signatures]; + + if (context.inline) { + return ["{", ...indent(content), "}"]; + } + + return [ + `## ${helpers.renderTitle(node)}`, + `${helpers.renderComments(node)}`, + "
",
+    "{",
+    ...indent(content),
+    "}",
+    "
", + ]; +} + +export function renderTypeAlias(node: Node, context: Context): Array { + let content: Array = [] as any; + + if (node.type) { + content = content.concat(renderType(node.type, context)); + } + + const obj = ["
", ...content, "
"]; + + if (context.inline) { + return obj; + } + + return [ + `## ${helpers.renderTitle(node)}`, + `${helpers.renderComments(node)}`, + ...obj, + ]; +} + +export function indent(lines: Array): Array { + return lines.map(line => ` ${line}`); +} diff --git a/docs/src/helpers.ts b/docs/src/helpers.ts new file mode 100644 index 0000000..db1e30c --- /dev/null +++ b/docs/src/helpers.ts @@ -0,0 +1,62 @@ +import * as path from "path"; +import { Node, CommentTag } from "./types"; + +export function renderKindString(node: Node): string { + if (node.kindString === "External module") { + return "Module"; + } + + return node.kindString; +} + +export function renderSrc(node: Node): string { + const src = node.sources[0]; + return `./src/${src.fileName}#L${src.line}`; +} + +export function renderTitle(node: Node): string { + const kindString = renderKindString(node); + + // TODO probably move this to renderSRc? + let src = ""; + //console.log(node) + if (node.sources) { + src = `[src](${renderSrc(node)})`; + } + return [ + node.name, + `${kindString} ${src}`, + node.id ? `` : "", + ].join(" "); +} + +export function renderComments(node: Node): string { + const comment = node.comment || ({} as any); + const content = []; + if (comment.shortText && comment.text) { + content.push(comment.shortText); + content.push(""); + content.push(comment.text); + } else if (comment.shortText) { + content.push(comment.shortText); + } else if (comment.text) { + content.push(comment.text); + } + + const tags = comment.tags || []; + const contentTags = []; + if (tags.length) { + contentTags.push("Tags"); + contentTags.push("\n"); + contentTags.push( + tags.map((tag: CommentTag) => `- ${tag.tag} ${tag.text}`).join("\n") + ); + } + + return [...content, "", ...contentTags].join("\n"); +} + +export function absoluteToRelativePathHelper(absolutePath: string): string { + const root = path.resolve(__dirname, "../../"); + return "./" + path.relative(root, absolutePath); +} diff --git a/docs/src/preprocessData.ts b/docs/src/preprocessData.ts new file mode 100644 index 0000000..689561e --- /dev/null +++ b/docs/src/preprocessData.ts @@ -0,0 +1,54 @@ +import { Node } from "./types"; + +const FIRST_CHILDREN_ORDER = { + index: 1, + core: 2, + reactHelpers: 3, + reactMixins: 5, + validators: 6, + types: 7, + "officialValidators/index": 8, + utils: 200, +}; + +const removeQuotes = (str: string) => str.replace(/"/g, ""); + +function removeQuotesFromName(module: Node) { + module.name = removeQuotes(module.name); + return module; +} + +function ignoredModules(_module: Node) { + //TODO dont ignore but push the bottom + //if (module.name.includes('officialValidators') && module.name !== 'officialValidators/index') { + //return false; + //} + + return true; +} + +function hiddenDeclarations(dec: Node) { + if (dec.comment && JSON.stringify(dec.comment).includes("@hidden")) { + return false; + } + + return true; +} + +export default function preprocessData(docsContent: Node): Node { + docsContent.children = docsContent.children + .map(removeQuotesFromName) + .filter(ignoredModules) + .sort((a: Node, b: Node) => { + const a_order = FIRST_CHILDREN_ORDER[a.name] || 100; + const b_order = FIRST_CHILDREN_ORDER[b.name] || 100; + return a_order > b_order ? 1 : -1; + }) + .map((module: Node) => { + module.children = (module.children || []).filter(hiddenDeclarations); + + return module; + }); + + return docsContent as Node; +} diff --git a/docs/src/tests/helperRenderTitle.ts b/docs/src/tests/helperRenderTitle.ts new file mode 100644 index 0000000..2fb6867 --- /dev/null +++ b/docs/src/tests/helperRenderTitle.ts @@ -0,0 +1,27 @@ +import * as test from "tape"; +import { renderTitle } from "../helpers"; +//import node from "./objectLiteralFixture"; + +const node = { + id: 1, + name: "myItem", + kind: 0, + kindString: "Variable", + sources: [ + { + fileName: "core.ts", + line: 69, + character: 28, + }, + ], +}; + +test("renderTitlte", function(t) { + t.plan(1); + + const actual = renderTitle(node); + const expected = + 'myItem Variable [src](./src/core.ts#L69) '; + + t.equal(actual, expected); +}); diff --git a/docs/src/tests/renderFunction.ts b/docs/src/tests/renderFunction.ts new file mode 100644 index 0000000..4f16eeb --- /dev/null +++ b/docs/src/tests/renderFunction.ts @@ -0,0 +1,29 @@ +import * as test from "tape"; +import Context from "../Context"; +import { renderFunction } from "../components"; +import node from "./renderFunctionFixture"; + +test("renderFunction", function(t) { + t.plan(1); + + const actual = renderFunction(node, new Context()); + const expected = [ + '## fieldIsValid Function [src](./src/core.ts#L73) ', + "", + "", + "", + "
",
+    "fieldIsValid(value: string | number, rules: [Rules](#user-content-#9)): boolean",
+    "
", + "", + "", + "", + "", + "
",
+    "fieldIsValid(fieldErrors: [FieldErrors](#user-content-#15)): boolean",
+    "
", + "", + ]; + + t.deepEqual(actual, expected); +}); diff --git a/docs/src/tests/renderFunctionFixture.ts b/docs/src/tests/renderFunctionFixture.ts new file mode 100644 index 0000000..9e8b451 --- /dev/null +++ b/docs/src/tests/renderFunctionFixture.ts @@ -0,0 +1,100 @@ +export default { + id: 185, + name: "fieldIsValid", + kind: 64, + kindString: "Function", + flags: { + isExported: true, + isExternal: true, + }, + signatures: [ + { + id: 186, + name: "fieldIsValid", + kind: 4096, + kindString: "Call signature", + flags: {}, + comment: {}, + parameters: [ + { + id: 187, + name: "value", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "union", + types: [ + { + type: "intrinsic", + name: "string", + }, + { + type: "intrinsic", + name: "number", + }, + ], + }, + }, + { + id: 188, + name: "rules", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "reference", + name: "Rules", + id: 9, + }, + }, + ], + type: { + type: "intrinsic", + name: "boolean", + }, + }, + { + id: 189, + name: "fieldIsValid", + kind: 4096, + kindString: "Call signature", + flags: {}, + parameters: [ + { + id: 190, + name: "fieldErrors", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "reference", + name: "FieldErrors", + id: 15, + }, + }, + ], + type: { + type: "intrinsic", + name: "boolean", + }, + }, + ], + sources: [ + { + fileName: "core.ts", + line: 73, + character: 28, + }, + { + fileName: "core.ts", + line: 74, + character: 28, + }, + { + fileName: "core.ts", + line: 75, + character: 28, + }, + ], +}; diff --git a/docs/src/tests/renderInterface.ts b/docs/src/tests/renderInterface.ts new file mode 100644 index 0000000..7ab8828 --- /dev/null +++ b/docs/src/tests/renderInterface.ts @@ -0,0 +1,50 @@ +import * as test from "tape"; +import Context from "../Context"; +import { renderInterface } from "../components"; +import node from "./renderInterfaceFixture"; +import node2 from "./renderInterfaceFixture2"; + +test("renderInterface", function(t) { + t.plan(1); + + const actual = renderInterface(node, new Context()); + const expected = [ + '## FieldErrors Interface [src](./src/types.ts#L17) ', + "", + "
",
+    "{",
+    "  \\[ruleKey: string\\]: boolean",
+    "}",
+    "
", + ]; + + t.deepEqual(actual, expected); +}); + +test("renderInterface2", function(t) { + t.plan(1); + + const actual = renderInterface(node2, new Context()); + const expected = [ + '## ValidationAbleInstance Interface [src](./src/types.ts#L35) ', + "", + "
",
+    "{",
+    "  setState: any",
+    "  state:",
+    "  {",
+    "    errors: [FormErrors](#user-content-#18)",
+    "    fields: [Fields](#user-content-#21)",
+    "    formIsDirty: boolean",
+    "  }",
+    "  validationMessages:",
+    "  {",
+    "    \\[ruleKey: string\\]: [MessageCreator](#user-content-#36)",
+    "  }",
+    "  validationRules: [RulesMap](#user-content-#12)",
+    "}",
+    "
", + ]; + + t.deepEqual(actual, expected); +}); diff --git a/docs/src/tests/renderInterfaceFixture.ts b/docs/src/tests/renderInterfaceFixture.ts new file mode 100644 index 0000000..c22d35a --- /dev/null +++ b/docs/src/tests/renderInterfaceFixture.ts @@ -0,0 +1,43 @@ +export default { + id: 15, + name: "FieldErrors", + kind: 256, + kindString: "Interface", + flags: { + isExported: true, + isExternal: true, + }, + indexSignature: [ + { + id: 16, + name: "__index", + kind: 8192, + kindString: "Index signature", + flags: {}, + parameters: [ + { + id: 17, + name: "ruleKey", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "intrinsic", + name: "string", + }, + }, + ], + type: { + type: "intrinsic", + name: "boolean", + }, + }, + ], + sources: [ + { + fileName: "types.ts", + line: 17, + character: 28, + }, + ], +}; diff --git a/docs/src/tests/renderInterfaceFixture2.ts b/docs/src/tests/renderInterfaceFixture2.ts new file mode 100644 index 0000000..35067d6 --- /dev/null +++ b/docs/src/tests/renderInterfaceFixture2.ts @@ -0,0 +1,237 @@ +export default { + id: 24, + name: "ValidationAbleInstance", + kind: 256, + kindString: "Interface", + flags: { + isExported: true, + isExternal: true, + }, + children: [ + { + id: 35, + name: "setState", + kind: 1024, + kindString: "Property", + flags: { + isExported: true, + isExternal: true, + }, + sources: [ + { + fileName: "types.ts", + line: 47, + character: 10, + }, + ], + type: { + type: "intrinsic", + name: "any", + }, + }, + { + id: 30, + name: "state", + kind: 1024, + kindString: "Property", + flags: { + isExported: true, + isExternal: true, + }, + sources: [ + { + fileName: "types.ts", + line: 41, + character: 7, + }, + ], + type: { + type: "reflection", + declaration: { + id: 31, + name: "__type", + kind: 65536, + kindString: "Type literal", + flags: {}, + children: [ + { + id: 33, + name: "errors", + kind: 32, + kindString: "Variable", + flags: { + isExternal: true, + }, + sources: [ + { + fileName: "types.ts", + line: 43, + character: 10, + }, + ], + type: { + type: "reference", + name: "FormErrors", + id: 18, + }, + }, + { + id: 32, + name: "fields", + kind: 32, + kindString: "Variable", + flags: { + isExternal: true, + }, + sources: [ + { + fileName: "types.ts", + line: 42, + character: 10, + }, + ], + type: { + type: "reference", + name: "Fields", + id: 21, + }, + }, + { + id: 34, + name: "formIsDirty", + kind: 32, + kindString: "Variable", + flags: { + isExternal: true, + isOptional: true, + }, + sources: [ + { + fileName: "types.ts", + line: 44, + character: 15, + }, + ], + type: { + type: "intrinsic", + name: "boolean", + }, + }, + ], + groups: [ + { + title: "Variables", + kind: 32, + children: [33, 32, 34], + }, + ], + sources: [ + { + fileName: "types.ts", + line: 41, + character: 8, + }, + ], + }, + }, + }, + { + id: 26, + name: "validationMessages", + kind: 1024, + kindString: "Property", + flags: { + isExported: true, + isExternal: true, + isOptional: true, + }, + sources: [ + { + fileName: "types.ts", + line: 37, + character: 20, + }, + ], + type: { + type: "reflection", + declaration: { + id: 27, + name: "__type", + kind: 65536, + kindString: "Type literal", + flags: {}, + indexSignature: [ + { + id: 28, + name: "__index", + kind: 8192, + kindString: "Index signature", + flags: {}, + parameters: [ + { + id: 29, + name: "ruleKey", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "intrinsic", + name: "string", + }, + }, + ], + type: { + type: "reference", + name: "MessageCreator", + id: 36, + }, + }, + ], + sources: [ + { + fileName: "types.ts", + line: 37, + character: 22, + }, + ], + }, + }, + }, + { + id: 25, + name: "validationRules", + kind: 1024, + kindString: "Property", + flags: { + isExported: true, + isExternal: true, + }, + sources: [ + { + fileName: "types.ts", + line: 36, + character: 17, + }, + ], + type: { + type: "reference", + name: "RulesMap", + id: 12, + }, + }, + ], + groups: [ + { + title: "Properties", + kind: 1024, + children: [35, 30, 26, 25], + }, + ], + sources: [ + { + fileName: "types.ts", + line: 35, + character: 39, + }, + ], +}; diff --git a/docs/src/tests/renderObjectLiteral.ts b/docs/src/tests/renderObjectLiteral.ts new file mode 100644 index 0000000..e318da1 --- /dev/null +++ b/docs/src/tests/renderObjectLiteral.ts @@ -0,0 +1,25 @@ +import * as test from "tape"; +import { renderObjectLiteral } from "../components"; +import Context from "../Context"; +import node from "./renderObjectLiteralFixture"; + +test("renderObjectLiteral", function(t) { + t.plan(1); + + const actual = renderObjectLiteral(node, new Context()); + const expected = [ + '## Reform Object literal [src](./src/index.ts#L22) ', + "", + "
",
+    "{",
+    "  core: [./src/core](#user-content-#178)",
+    "  reactHelpers: [./src/reactHelpers](#user-content-#201)",
+    "  reactMixins: [./src/reactMixins](#user-content-#233)",
+    "  types: [./src/types](#user-content-#1)",
+    "  validators: [./src/validators](./src/validators)",
+    "}",
+    "
", + ]; + + t.deepEqual(actual, expected); +}); diff --git a/docs/src/tests/renderObjectLiteralFixture.ts b/docs/src/tests/renderObjectLiteralFixture.ts new file mode 100644 index 0000000..0b9ce0a --- /dev/null +++ b/docs/src/tests/renderObjectLiteralFixture.ts @@ -0,0 +1,241 @@ +export default { + id: 252, + name: "Reform", + kind: 2097152, + kindString: "Object literal", + flags: { + isExported: true, + }, + comment: {}, + sources: [ + { + fileName: "index.ts", + line: 22, + character: 12, + }, + ], + children: [ + { + id: 254, + name: "core", + kind: 32, + kindString: "Variable", + flags: { + isExported: true, + }, + sources: [ + { + fileName: "index.ts", + line: 24, + character: 6, + }, + ], + type: { + type: "reference", + name: '"/Users/flp/code/reform/src/core"', + id: 178, + }, + }, + { + id: 264, + name: "reactHelpers", + kind: 32, + kindString: "Variable", + flags: { + isExported: true, + }, + sources: [ + { + fileName: "index.ts", + line: 26, + character: 14, + }, + ], + type: { + type: "reference", + name: '"/Users/flp/code/reform/src/reactHelpers"', + id: 201, + }, + }, + { + id: 265, + name: "reactMixins", + kind: 32, + kindString: "Variable", + flags: { + isExported: true, + }, + sources: [ + { + fileName: "index.ts", + line: 27, + character: 13, + }, + ], + type: { + type: "reference", + name: '"/Users/flp/code/reform/src/reactMixins"', + id: 233, + }, + }, + { + id: 253, + name: "types", + kind: 32, + kindString: "Variable", + flags: { + isExported: true, + }, + sources: [ + { + fileName: "index.ts", + line: 23, + character: 7, + }, + ], + type: { + type: "reference", + name: '"/Users/flp/code/reform/src/types"', + id: 1, + }, + }, + { + id: 255, + name: "validators", + kind: 32, + kindString: "Variable", + flags: { + isExported: true, + }, + sources: [ + { + fileName: "index.ts", + line: 25, + character: 12, + }, + ], + type: { + type: "reflection", + declaration: { + id: 256, + name: "__type", + kind: 65536, + kindString: "Type literal", + flags: { + isExported: true, + }, + children: [ + { + id: 257, + name: "get", + kind: 64, + kindString: "Function", + flags: { + isExported: true, + }, + signatures: [ + { + id: 258, + name: "get", + kind: 4096, + kindString: "Call signature", + flags: {}, + parameters: [ + { + id: 259, + name: "key", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "intrinsic", + name: "string", + }, + }, + ], + type: { + type: "reference", + name: "Validator", + id: 2, + }, + }, + ], + sources: [ + { + fileName: "validators.ts", + line: 19, + character: 5, + }, + ], + }, + { + id: 260, + name: "set", + kind: 64, + kindString: "Function", + flags: { + isExported: true, + }, + signatures: [ + { + id: 261, + name: "set", + kind: 4096, + kindString: "Call signature", + flags: {}, + parameters: [ + { + id: 262, + name: "key", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "intrinsic", + name: "string", + }, + }, + { + id: 263, + name: "value", + kind: 32768, + kindString: "Parameter", + flags: {}, + type: { + type: "reference", + name: "Validator", + id: 2, + }, + }, + ], + type: { + type: "intrinsic", + name: "void", + }, + }, + ], + sources: [ + { + fileName: "validators.ts", + line: 28, + character: 5, + }, + ], + }, + ], + groups: [ + { + title: "Functions", + kind: 64, + children: [257, 260], + }, + ], + }, + }, + }, + ], + type: { + type: "intrinsic", + name: "object", + }, +}; diff --git a/docs/src/tests/renderType.ts b/docs/src/tests/renderType.ts new file mode 100644 index 0000000..9369f44 --- /dev/null +++ b/docs/src/tests/renderType.ts @@ -0,0 +1,23 @@ +import * as test from "tape"; +import { renderType } from "../components"; +import Context from "../Context"; +import node from "./renderTypeFixture"; +import typeNode from "./renderTypeFixture2"; + +test("renderType", function(t) { + t.plan(1); + + const actual = renderType(node.type, new Context()); + const expected = ["Array\\<[string, any]\\>"]; + + t.deepEqual(actual, expected); +}); + +test("renderType2", function(t) { + t.plan(1); + + const actual = renderType(typeNode, new Context()); + const expected = ["Array\\"]; + + t.deepEqual(actual, expected); +}); diff --git a/docs/src/tests/renderTypeAlias.ts b/docs/src/tests/renderTypeAlias.ts new file mode 100644 index 0000000..5c4098b --- /dev/null +++ b/docs/src/tests/renderTypeAlias.ts @@ -0,0 +1,22 @@ +import * as test from "tape"; +import { renderNode } from "../components"; +import Context from "../Context"; +import node from "./renderTypeAliasFixture"; + +test("renderTypeAlias", function(t) { + t.plan(1); + + const actual = renderNode(node, new Context()); + const expected = [ + '## MessageCreator Type alias [src](./src/types.ts#L29) ', + '', + '
',
+    '{',
+    '  (ruleArgument: any, ruleKey: string, fieldName: string): string',
+    '}',
+    '
' + ] + + + t.deepEqual(actual, expected); +}); diff --git a/docs/src/tests/renderTypeAliasFixture.ts b/docs/src/tests/renderTypeAliasFixture.ts new file mode 100644 index 0000000..bebef20 --- /dev/null +++ b/docs/src/tests/renderTypeAliasFixture.ts @@ -0,0 +1,88 @@ +export default { + "id": 36, + "name": "MessageCreator", + "kind": 4194304, + "kindString": "Type alias", + "flags": { + "isExported": true, + "isExternal": true + }, + "sources": [ + { + "fileName": "types.ts", + "line": 29, + "character": 26 + } + ], + "type": { + "type": "reflection", + "declaration": { + "id": 37, + "name": "__type", + "kind": 65536, + "kindString": "Type literal", + "flags": {}, + "signatures": [ + { + "id": 38, + "name": "__call", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "parameters": [ + { + "id": 39, + "name": "ruleArgument", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isOptional": true + }, + "type": { + "type": "intrinsic", + "name": "any" + } + }, + { + "id": 40, + "name": "ruleKey", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isOptional": true + }, + "type": { + "type": "intrinsic", + "name": "string" + } + }, + { + "id": 41, + "name": "fieldName", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isOptional": true + }, + "type": { + "type": "intrinsic", + "name": "string" + } + } + ], + "type": { + "type": "intrinsic", + "name": "string" + } + } + ], + "sources": [ + { + "fileName": "types.ts", + "line": 29, + "character": 28 + } + ] + } + } + } diff --git a/docs/src/tests/renderTypeFixture.ts b/docs/src/tests/renderTypeFixture.ts new file mode 100644 index 0000000..9d9b841 --- /dev/null +++ b/docs/src/tests/renderTypeFixture.ts @@ -0,0 +1,27 @@ +export default { + id: 228, + name: "fieldErrors", + kind: 4096, + kindString: "Call signature", + flags: {}, + comment: {}, + type: { + type: "reference", + name: "Array", + typeArguments: [ + { + type: "tuple", + elements: [ + { + type: "intrinsic", + name: "string", + }, + { + type: "intrinsic", + name: "any", + }, + ], + }, + ], + }, +}; diff --git a/docs/src/tests/renderTypeFixture2.ts b/docs/src/tests/renderTypeFixture2.ts new file mode 100644 index 0000000..5d6b561 --- /dev/null +++ b/docs/src/tests/renderTypeFixture2.ts @@ -0,0 +1,7 @@ +export default { + type: "array", + elementType: { + type: "intrinsic", + name: "number", + }, +}; diff --git a/docs/src/types.ts b/docs/src/types.ts new file mode 100644 index 0000000..5ad2088 --- /dev/null +++ b/docs/src/types.ts @@ -0,0 +1,38 @@ +export type TypeNode = { + type: string; + types?: Array; + name?: string; + id?: number; + declaration?: Node; + typeArguments?: Array; + typeParameters?: Array; + elements?: Array; + elementType?: TypeNode; +}; + +export type Node = { + id: number; + name: string; + kind: number; + kindString: string; + children?: Array; + parameters?: Array; + signatures?: Array; + indexSignature?: Array; + type?: TypeNode; + comment?: { + shortText: string; + text: string; + tags: Array; + }; + sources: Array<{ + fileName: string; + line: number; + character: number; + }>; +}; + +export interface CommentTag { + tag: string; + text: string; +} diff --git a/docs/tsconfig.json b/docs/tsconfig.json new file mode 100644 index 0000000..b695833 --- /dev/null +++ b/docs/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "declaration": true, + "sourceMap": true, + "noImplicitAny": true, + "module": "commonjs", + "target": "es5", + "jsx": "react", + "noUnusedParameters": true, + "noUnusedLocals": true, + "types": ["node"], + "suppressImplicitAnyIndexErrors": true + }, + + "include": ["src/**/*"], + + "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"] +} diff --git a/package.json b/package.json index df1dcb5..78db809 100644 --- a/package.json +++ b/package.json @@ -8,18 +8,22 @@ "types": "./build/src/@franleplant/reform.d.ts", "scripts": { "pre:publish": "npm run test:travis && npm run build:docs && npm run build", + "prettier:src": "prettier --write \"src/**/*.{ts,.test.ts}\"", + "prettier:json": "prettier --write --no-config \"*.json\"", + "prettier:docs": "prettier --write \"docs/**/*.ts\"", "prettier": - "prettier --write \"src/**/*.{ts,.test.ts}\" && prettier --write --no-config \"*.json\" ", + "npm run prettier:src && npm run prettier:json && npm run prettier:docs", "build:typedefs": "dts-bundle --name @franleplant/reform --main build/src/index.d.ts", "build": "webpack && npm run build:typedefs", "start": "webpack --watch", "test": "jest --watch", - "test:docs": "tape docs-src/**/*.test.js", + "test:docs": "ts-node node_modules/tape/bin/tape docs/src/tests/*.ts", "test:travis": "npm run test:typecheck && jest --coverage && npm run test:docs", - "build:docs": - "typedoc --ignoreCompilerErrors --tsconfig ./typedocconfig.json --out ./docs --name Reform --module commonjs --json docsContent.json src/index.ts && node docs-src/build.js", + "build:gather-docs": + "typedoc --ignoreCompilerErrors --tsconfig ./typedocconfig.json --out ./docsTmp --name Reform --module commonjs --json docsContent.json src/index.ts", + "build:docs": "npm run build:gather-docs && ts-node docs/index.ts", "link-examples": "./scripts/link-examples.sh", "test:typecheck": "tsc -p tsconfig.test.json", "examples-js": "npm run link-examples && cd ./examples && npm run start", @@ -31,16 +35,16 @@ "devDependencies": { "@types/jest": "^21.1.6", "@types/node": "6.0.51", - "common-tags": "^1.4.0", + "@types/tape": "^4.2.31", "coveralls": "^2.11.15", "dts-bundle": "0.6.1", - "handlebars": "^4.0.6", "jest": "^21.2.1", "prettier": "^1.8.2", "source-map-loader": "0.1.5", "tape": "^4.6.3", "ts-jest": "^21.2.3", "ts-loader": "^3.1.1", + "ts-node": "^3.3.0", "tslint": "4.0.2", "tslint-loader": "3.2.0", "typedoc": "^0.9.0", diff --git a/yarn.lock b/yarn.lock index 3ef5308..2158b0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -42,6 +42,12 @@ dependencies: "@types/node" "*" +"@types/tape@^4.2.31": + version "4.2.31" + resolved "https://registry.yarnpkg.com/@types/tape/-/tape-4.2.31.tgz#d2cd0f2e410d2c288a5eb54c01c04e6b8a301fd2" + dependencies: + "@types/node" "*" + Base64@~0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/Base64/-/Base64-0.2.1.tgz#ba3a4230708e186705065e66babdd4c35cf60028" @@ -561,7 +567,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.1, chalk@^2.3.0: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" dependencies: @@ -854,11 +860,7 @@ detect-libc@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.2.tgz#71ad5d204bf17a6a6ca8f450c61454066ef461e1" -diff@^3.0.1: - version "3.1.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-3.1.0.tgz#9406c73a401e6c2b3ba901c5e2c44eb6a60c5385" - -diff@^3.2.0: +diff@^3.0.1, diff@^3.1.0, diff@^3.2.0: version "3.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c" @@ -1399,6 +1401,12 @@ home-or-tmp@^2.0.0: os-homedir "^1.0.0" os-tmpdir "^1.0.1" +homedir-polyfill@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc" + dependencies: + parse-passwd "^1.0.0" + hosted-git-info@^2.1.4: version "2.1.5" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.1.5.tgz#0ba81d90da2e25ab34a332e6ec77936e1598118b" @@ -2149,6 +2157,10 @@ lru-cache@^4.0.1: pseudomap "^1.0.2" yallist "^2.1.2" +make-error@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.0.tgz#52ad3a339ccf10ce62b4040b708fe707244b8b96" + makeerror@1.0.x: version "1.0.11" resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c" @@ -2519,6 +2531,10 @@ parse-json@^2.1.0, parse-json@^2.2.0: dependencies: error-ex "^1.2.0" +parse-passwd@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" + parse5@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/parse5/-/parse5-1.5.1.tgz#9b7f3b0de32be78dc2401b17573ccaf0f6f59d94" @@ -3055,7 +3071,7 @@ source-map-loader@0.1.5: loader-utils "~0.2.2" source-map "~0.1.33" -source-map-support@^0.4.15: +source-map-support@^0.4.0, source-map-support@^0.4.15: version "0.4.18" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" dependencies: @@ -3197,14 +3213,14 @@ strip-eof@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" +strip-json-comments@^2.0.0, strip-json-comments@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + strip-json-comments@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" -strip-json-comments@~2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" - subarg@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2" @@ -3370,6 +3386,28 @@ ts-loader@^3.1.1: loader-utils "^1.0.2" semver "^5.0.1" +ts-node@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-3.3.0.tgz#c13c6a3024e30be1180dd53038fc209289d4bf69" + dependencies: + arrify "^1.0.0" + chalk "^2.0.0" + diff "^3.1.0" + make-error "^1.1.1" + minimist "^1.2.0" + mkdirp "^0.5.1" + source-map-support "^0.4.0" + tsconfig "^6.0.0" + v8flags "^3.0.0" + yn "^2.0.0" + +tsconfig@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-6.0.0.tgz#6b0e8376003d7af1864f8df8f89dd0059ffcd032" + dependencies: + strip-bom "^3.0.0" + strip-json-comments "^2.0.0" + tslint-loader@3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/tslint-loader/-/tslint-loader-3.2.0.tgz#de6f842a8ea4aa1c4ab995b670b95a1f54845821" @@ -3526,6 +3564,12 @@ uuid@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" +v8flags@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-3.0.1.tgz#dce8fc379c17d9f2c9e9ed78d89ce00052b1b76b" + dependencies: + homedir-polyfill "^1.0.1" + validate-npm-package-license@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" @@ -3763,3 +3807,7 @@ yargs@~3.10.0: cliui "^2.1.0" decamelize "^1.0.0" window-size "0.1.0" + +yn@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a" From 08046ed8afe02aceaccbd13576e495221a63abf8 Mon Sep 17 00:00:00 2001 From: Fran Guijarro Date: Fri, 24 Nov 2017 18:12:37 -0300 Subject: [PATCH 2/3] attempt to fix travis 1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78db809..07bcdf1 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "build": "webpack && npm run build:typedefs", "start": "webpack --watch", "test": "jest --watch", - "test:docs": "ts-node node_modules/tape/bin/tape docs/src/tests/*.ts", + "test:docs": "ts-node ./node_modules/tape/bin/tape ./docs/src/tests/*.ts", "test:travis": "npm run test:typecheck && jest --coverage && npm run test:docs", "build:gather-docs": From b6cb0bb8bde6de40a1c5b16fdda8319718ff426c Mon Sep 17 00:00:00 2001 From: Fran Guijarro Date: Fri, 24 Nov 2017 18:34:11 -0300 Subject: [PATCH 3/3] fix travis build 2 --- docs/src/components.ts | 11 +- .../helperAbsoluteToRelativePathHelper.ts | 12 ++ docs/src/tests/renderObjectLiteralFixture.ts | 14 +- docs/src/tests/renderTypeAlias.ts | 15 +- docs/src/tests/renderTypeAliasFixture.ts | 174 +++++++++--------- 5 files changed, 123 insertions(+), 103 deletions(-) create mode 100644 docs/src/tests/helperAbsoluteToRelativePathHelper.ts diff --git a/docs/src/components.ts b/docs/src/components.ts index 2817cd0..03e7e32 100644 --- a/docs/src/components.ts +++ b/docs/src/components.ts @@ -12,7 +12,7 @@ const KIND_STRING_EXTERNAL_MODULE = "External module"; const KIND_STRING_INTERFACE = "Interface"; const KIND_STRING_PROPERTY = "Property"; const KIND_STRING_TYPE_LITERAL = "Type literal"; -const KIND_STRING_TYPE_ALIAS = "Type alias" +const KIND_STRING_TYPE_ALIAS = "Type alias"; export function renderNode(node: Node, context: Context): Array { //console.log(ts.SyntaxKind.PropertyDeclaration, ts.SyntaxKind.PropertyAssignment, ts.SyntaxKind.PropertySignature ) @@ -280,10 +280,13 @@ export function renderProperty(node: Node, context: Context): Array { return [`${node.name}: ${renderType(node.type, context).join("TODO")}`]; } -export function renderTypeLiteral(node: Node, _context: Context): Array { - let context = _context +export function renderTypeLiteral( + node: Node, + _context: Context +): Array { + let context = _context; if (node.name === "__type") { - context = context.setInline(true) + context = context.setInline(true); } let children: Array = [] as any; diff --git a/docs/src/tests/helperAbsoluteToRelativePathHelper.ts b/docs/src/tests/helperAbsoluteToRelativePathHelper.ts new file mode 100644 index 0000000..e6e8bd7 --- /dev/null +++ b/docs/src/tests/helperAbsoluteToRelativePathHelper.ts @@ -0,0 +1,12 @@ +import * as test from "tape"; +import { absoluteToRelativePathHelper } from "../helpers"; + +test("absoluteToRelativePathHelper", function(t) { + t.plan(1); + + const input = "/Users/flp/code/reform/src/reactMixins"; + const actual = absoluteToRelativePathHelper(input); + const expected = "./src/reactMixins"; + + t.equal(actual, expected); +}); diff --git a/docs/src/tests/renderObjectLiteralFixture.ts b/docs/src/tests/renderObjectLiteralFixture.ts index 0b9ce0a..f2b86cd 100644 --- a/docs/src/tests/renderObjectLiteralFixture.ts +++ b/docs/src/tests/renderObjectLiteralFixture.ts @@ -1,3 +1,9 @@ +import * as path from "path"; + +export function fakeAbsolutePath(fileUnderSrc: string): string { + return path.resolve(__dirname, "../../../", fileUnderSrc); +} + export default { id: 252, name: "Reform", @@ -32,7 +38,7 @@ export default { ], type: { type: "reference", - name: '"/Users/flp/code/reform/src/core"', + name: `"${fakeAbsolutePath("src/core")}"`, id: 178, }, }, @@ -53,7 +59,7 @@ export default { ], type: { type: "reference", - name: '"/Users/flp/code/reform/src/reactHelpers"', + name: `"${fakeAbsolutePath("src/reactHelpers")}"`, id: 201, }, }, @@ -74,7 +80,7 @@ export default { ], type: { type: "reference", - name: '"/Users/flp/code/reform/src/reactMixins"', + name: `"${fakeAbsolutePath("src/reactMixins")}"`, id: 233, }, }, @@ -95,7 +101,7 @@ export default { ], type: { type: "reference", - name: '"/Users/flp/code/reform/src/types"', + name: `"${fakeAbsolutePath("src/types")}"`, id: 1, }, }, diff --git a/docs/src/tests/renderTypeAlias.ts b/docs/src/tests/renderTypeAlias.ts index 5c4098b..f7a0fee 100644 --- a/docs/src/tests/renderTypeAlias.ts +++ b/docs/src/tests/renderTypeAlias.ts @@ -9,14 +9,13 @@ test("renderTypeAlias", function(t) { const actual = renderNode(node, new Context()); const expected = [ '## MessageCreator Type alias [src](./src/types.ts#L29) ', - '', - '
',
-    '{',
-    '  (ruleArgument: any, ruleKey: string, fieldName: string): string',
-    '}',
-    '
' - ] - + "", + "
",
+    "{",
+    "  (ruleArgument: any, ruleKey: string, fieldName: string): string",
+    "}",
+    "
", + ]; t.deepEqual(actual, expected); }); diff --git a/docs/src/tests/renderTypeAliasFixture.ts b/docs/src/tests/renderTypeAliasFixture.ts index bebef20..d0ce049 100644 --- a/docs/src/tests/renderTypeAliasFixture.ts +++ b/docs/src/tests/renderTypeAliasFixture.ts @@ -1,88 +1,88 @@ export default { - "id": 36, - "name": "MessageCreator", - "kind": 4194304, - "kindString": "Type alias", - "flags": { - "isExported": true, - "isExternal": true - }, - "sources": [ - { - "fileName": "types.ts", - "line": 29, - "character": 26 - } - ], - "type": { - "type": "reflection", - "declaration": { - "id": 37, - "name": "__type", - "kind": 65536, - "kindString": "Type literal", - "flags": {}, - "signatures": [ - { - "id": 38, - "name": "__call", - "kind": 4096, - "kindString": "Call signature", - "flags": {}, - "parameters": [ - { - "id": 39, - "name": "ruleArgument", - "kind": 32768, - "kindString": "Parameter", - "flags": { - "isOptional": true - }, - "type": { - "type": "intrinsic", - "name": "any" - } - }, - { - "id": 40, - "name": "ruleKey", - "kind": 32768, - "kindString": "Parameter", - "flags": { - "isOptional": true - }, - "type": { - "type": "intrinsic", - "name": "string" - } - }, - { - "id": 41, - "name": "fieldName", - "kind": 32768, - "kindString": "Parameter", - "flags": { - "isOptional": true - }, - "type": { - "type": "intrinsic", - "name": "string" - } - } - ], - "type": { - "type": "intrinsic", - "name": "string" - } - } - ], - "sources": [ - { - "fileName": "types.ts", - "line": 29, - "character": 28 - } - ] - } - } - } + id: 36, + name: "MessageCreator", + kind: 4194304, + kindString: "Type alias", + flags: { + isExported: true, + isExternal: true, + }, + sources: [ + { + fileName: "types.ts", + line: 29, + character: 26, + }, + ], + type: { + type: "reflection", + declaration: { + id: 37, + name: "__type", + kind: 65536, + kindString: "Type literal", + flags: {}, + signatures: [ + { + id: 38, + name: "__call", + kind: 4096, + kindString: "Call signature", + flags: {}, + parameters: [ + { + id: 39, + name: "ruleArgument", + kind: 32768, + kindString: "Parameter", + flags: { + isOptional: true, + }, + type: { + type: "intrinsic", + name: "any", + }, + }, + { + id: 40, + name: "ruleKey", + kind: 32768, + kindString: "Parameter", + flags: { + isOptional: true, + }, + type: { + type: "intrinsic", + name: "string", + }, + }, + { + id: 41, + name: "fieldName", + kind: 32768, + kindString: "Parameter", + flags: { + isOptional: true, + }, + type: { + type: "intrinsic", + name: "string", + }, + }, + ], + type: { + type: "intrinsic", + name: "string", + }, + }, + ], + sources: [ + { + fileName: "types.ts", + line: 29, + character: 28, + }, + ], + }, + }, +};