-
Notifications
You must be signed in to change notification settings - Fork 42
Extract docs #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Extract docs #70
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
1da1cac
deps
tmlayton 4ed814a
Add script to generate READMEs
iainmcampbell ba24ed7
improve docs and add examples
tmlayton 98447d3
render js and react examples
tmlayton b5247a9
proper code formatting
tmlayton 3cfaf56
fix void type
tmlayton 9945818
support params
tmlayton 874cdf6
more types
tmlayton 041d7fc
updates for content and getting started
tmlayton b030433
yamlFrontMatter function
iainmcampbell 0da5844
Replace hardcoded paths in components()
iainmcampbell 2e7ae4e
Genericize renderExamples
iainmcampbell 3b86bf2
genericize getAdditionalContentFor, renaming
iainmcampbell 722baba
typescript
iainmcampbell 4e95c86
Parse and output tsdoc tags in PropertySignature nodes
iainmcampbell 532bd57
fix table formatting
tmlayton 2ac9d4f
fix up doc content output
tmlayton 2a8bb48
update taxonomy and more clean-up
tmlayton 56eab05
Wrap example code in `{% raw %}` so liquid doesn't barf
iainmcampbell 9a95609
Render additionalPropsTables with <h3>
iainmcampbell 972a21a
Sort components alphabetically
iainmcampbell 650370b
Add yarn run docs command
iainmcampbell 5555812
Handle Responsive type
iainmcampbell 73336a0
Cool that fixed View too
iainmcampbell df01ecb
fix linting
tmlayton f0099b9
Add argo-admin generate-docs script entry
iainmcampbell cdadaf2
Add support for interface extends
iainmcampbell 71d782b
Move shopify dev renderer into own folder, begin to componentize
iainmcampbell 45194bb
add skipLibCheck to base tsconfig
iainmcampbell c76b383
Scripts get its own tsconfig
iainmcampbell 0202003
fix rendering bugs, output proper yaml frontmatter description
iainmcampbell 7a84f77
double quotes around yaml frontmatter description
iainmcampbell 8af05c7
move to repo tsconfig
iainmcampbell 3563335
fix resolve bug
iainmcampbell fe402ce
Remove scripts tsconfig
iainmcampbell 82eaf78
Replace showdown with markdown-table
iainmcampbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Debug current file", | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node", | ||
"runtimeArgs": ["--extensions", ".ts,.tsx,.mjs,.js,.json", "${file}"], | ||
"sourceMaps": true, | ||
"env": { | ||
"BABEL_ENV": "debug" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", {"targets": {"node": true}}], | ||
"@babel/preset-typescript" | ||
], | ||
"env": { | ||
"debug": { | ||
"sourceMaps": "inline", | ||
"retainLines": true | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {components, extensionPoints} from './typedoc/shopify-dev-renderer'; | ||
|
||
const paths = { | ||
inputRoot: './packages/argo-admin', | ||
packages: { | ||
JavaScript: './packages/argo-admin', | ||
React: './packages/argo-admin-react', | ||
}, | ||
outputRoot: '../shopify-dev/content/tools/argo-admin', | ||
shopifyDevUrl: '/tools/argo-admin', | ||
}; | ||
|
||
components(paths); | ||
extensionPoints(paths); | ||
iainmcampbell marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {renderForShopifyDev} from './typedoc'; | ||
|
||
const paths = { | ||
inputRoot: '../checkout-web/packages/argo-checkout', | ||
packages: { | ||
JS: '../checkout-web/packages/argo-checkout', | ||
React: '../checkout-web/packages/argo-checkout-react', | ||
}, | ||
outputRoot: '../shopify-dev/content/docs/checkout-extensions', | ||
shopifyDevUrl: '/docs/checkout-extensions', | ||
}; | ||
|
||
renderForShopifyDev(paths); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {renderForShopifyDev} from './shopify-dev-renderer'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import {resolve, extname} from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
import type { | ||
Paths, | ||
Packages, | ||
} from '../types'; | ||
|
||
import {createDependencyGraph} from '../utilities/dependency-graph'; | ||
|
||
import {renderYamlFrontMatter, findUuid, dedupe, propsTable, strip, firstSentence} from './shared'; | ||
import type {Node} from './shared'; | ||
|
||
const additionalPropsTables: string[] = []; | ||
|
||
export async function components(paths: Paths) { | ||
const componentIndex = resolve(`${paths.inputRoot}/src/components/index.ts`); | ||
const {nodes, components} = await buildComponentGraph(componentIndex); | ||
|
||
const outputRoot = resolve(`${paths.outputRoot}`); | ||
const componentDocsPath = resolve(`${paths.outputRoot}/components`); | ||
|
||
if (!fs.existsSync(outputRoot)) { | ||
fs.mkdirSync(outputRoot); | ||
} | ||
|
||
if (!fs.existsSync(componentDocsPath)) { | ||
fs.mkdirSync(componentDocsPath); | ||
} | ||
|
||
const indexFile = resolve(`${paths.outputRoot}/components/index.md`); | ||
let index = renderYamlFrontMatter({ | ||
gid: findUuid(indexFile), | ||
url: `${paths.shopifyDevUrl}/components/index`, | ||
title: 'Components for checkout extensions', | ||
description: 'A list of components for checkout extensions.', | ||
hidden: true, | ||
}); | ||
|
||
index += `Argo provides many powerful UI components that a | ||
[rendering extension](${paths.shopifyDevUrl}/extension-points#rendering) can | ||
use to build an interface. This UI is rendered natively by Shopify, so you | ||
can depend on it to be performant, accessible, and work in all of Checkout’s | ||
supported browsers. \n\nThe following components are available as part of Argo | ||
for Checkout, but make sure that you check the documentation for your | ||
[extension point](${paths.shopifyDevUrl}/extension-points#extension-points) | ||
to ensure the component is available in the extension points you are | ||
targeting.\n\n`; | ||
|
||
index += '<ul style="column-count: auto;column-width: 12rem;">'; | ||
|
||
components.forEach(({value: {name, docs, props}}: any) => { | ||
const outputFile = `${componentDocsPath}/${name.toLowerCase()}.md`; | ||
|
||
const docsContent = docs ? strip(docs.content).trim() : ''; | ||
|
||
const componentUrl = `${ | ||
paths.shopifyDevUrl | ||
}/components/${name.toLowerCase()}`; | ||
|
||
let markdown = renderYamlFrontMatter({ | ||
gid: findUuid(outputFile), | ||
url: componentUrl, | ||
title: `${name}`, | ||
description: `"${firstSentence(docsContent)}"`, | ||
hidden: true, | ||
}); | ||
markdown += docsContent ? `${docsContent}\n\n` : ''; | ||
|
||
const examples = renderComponentExamplesFor(name, paths.packages); | ||
if (examples.length > 0) { | ||
markdown += examples; | ||
} | ||
|
||
const face = nodes.find(({value}: any) => value.name === props.name); | ||
if ( | ||
face && | ||
face.value.kind === 'InterfaceType' && | ||
face.value.properties.length > 0 | ||
) { | ||
markdown += '## Props\noptional = ?\n'; | ||
markdown += propsTable( | ||
name, | ||
docs, | ||
face.value.properties, | ||
nodes, | ||
componentIndex, | ||
additionalPropsTables, | ||
false, | ||
undefined, | ||
); | ||
} | ||
|
||
markdown += dedupe(additionalPropsTables).reverse().join(''); | ||
|
||
const contentFolder = resolve( | ||
`${paths.inputRoot}/src/components/${name}/content`, | ||
); | ||
markdown += getAdditionalContentFor(contentFolder); | ||
|
||
fs.writeFile(outputFile, markdown, function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
additionalPropsTables.length = 0; | ||
index += `<li><a href="${componentUrl}">${name}</a></li>`; | ||
}); | ||
|
||
index += '</ul>'; | ||
|
||
// Write the component table of contents | ||
fs.writeFile(indexFile, index, function (err) { | ||
if (err) throw err; | ||
}); | ||
} | ||
|
||
async function buildComponentGraph(componentIndex: string) { | ||
const graph = await createDependencyGraph(componentIndex); | ||
|
||
const nodes: Node[] = []; | ||
|
||
graph.forEach((value) => { | ||
value.locals.forEach((value: any, key) => { | ||
if (value.kind !== 'Imported') { | ||
if (value.name == null) { | ||
value.name = key; | ||
} | ||
nodes.push({value, module: undefined}); | ||
} | ||
}); | ||
}); | ||
|
||
const components = [ | ||
...new Set(nodes.filter(({value}: any) => value.kind === 'Component')), | ||
]; | ||
|
||
// console.log(JSON.stringify(nodes)) | ||
|
||
// Sort alphabetically (tsdoc seems to get this confused) | ||
components.sort((aa: any, bb: any) => { | ||
if (aa.value.name > bb.value.name) { | ||
return 1; | ||
} else if (aa.value.name < bb.value.name) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
}); | ||
|
||
return {nodes, components}; | ||
} | ||
|
||
function renderComponentExamplesFor(name: string, packages: Packages): string { | ||
const examples: any = {}; | ||
|
||
Object.keys(packages).forEach((packageName) => { | ||
const packagePath = packages[packageName]; | ||
const folder = resolve(`${packagePath}/src/components/${name}/examples`); | ||
|
||
if (fs.existsSync(folder)) { | ||
fs.readdirSync(folder).forEach((file) => { | ||
const extension = extname(file).split('.').pop(); | ||
examples[packageName] = `{% highlight ${extension} %}{% raw %}\n`; | ||
examples[packageName] += fs.readFileSync(`${folder}/${file}`, 'utf8'); | ||
examples[packageName] += '\n{% endraw %}{% endhighlight %}\n\n'; | ||
}); | ||
} | ||
}); | ||
|
||
let markdown = ''; | ||
|
||
const exampleCount = Object.keys(examples).length; | ||
|
||
if (exampleCount > 1) { | ||
const sections = Object.keys(examples).join(', '); | ||
markdown += `{% sections "${sections}" %}\n\n`; | ||
markdown += Object.values(examples).join('\n\n----\n\n'); | ||
markdown += '{% endsections %}\n\n'; | ||
} else if (exampleCount > 0) { | ||
markdown += Object.values(examples).join('\n\n----\n\n'); | ||
} | ||
|
||
return markdown; | ||
} | ||
|
||
function getAdditionalContentFor(contentFolder: string) { | ||
let markdown = ''; | ||
|
||
if (fs.existsSync(contentFolder)) { | ||
fs.readdirSync(contentFolder).forEach((file) => { | ||
markdown += fs.readFileSync(`${contentFolder}/${file}`, 'utf8'); | ||
}); | ||
} | ||
|
||
return markdown; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {resolve} from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
import type { | ||
Paths, | ||
InterfaceType, | ||
} from '../types'; | ||
|
||
import {createDependencyGraph} from '../utilities/dependency-graph'; | ||
import {renderYamlFrontMatter, findUuid, dedupe, propsTable} from './shared'; | ||
import type {Node} from './shared'; | ||
|
||
const additionalPropsTables: string[] = []; | ||
|
||
export async function extensionPoints(paths: Paths) { | ||
const extensionsIndex = resolve(`${paths.inputRoot}/src/index.ts`); | ||
|
||
const graph = await createDependencyGraph(extensionsIndex); | ||
|
||
const allInterfaces: InterfaceType[] = []; | ||
|
||
for (const value of graph.values()) { | ||
const localValues = [...value.locals.values()]; | ||
allInterfaces.push( | ||
...(localValues.filter( | ||
({kind}) => kind === 'InterfaceType', | ||
) as InterfaceType[]), | ||
); | ||
} | ||
|
||
const nodes: Node[] = []; | ||
|
||
graph.forEach((value) => { | ||
value.locals.forEach((value: any, key) => { | ||
if (value.kind !== 'Imported') { | ||
if (value.name == null) { | ||
value.name = key; | ||
} | ||
nodes.push({value, module: undefined}); | ||
} | ||
}); | ||
}); | ||
|
||
const interfaceEntryPoints = ['ExtensionPoints']; | ||
|
||
const interfaces = allInterfaces.filter(({name}) => | ||
interfaceEntryPoints.includes(name), | ||
); | ||
|
||
const rootFolder = resolve(paths.outputRoot) | ||
if (!fs.existsSync(rootFolder)) { | ||
fs.mkdirSync(rootFolder); | ||
} | ||
|
||
const folder = resolve(`${paths.outputRoot}/extension-points`); | ||
if (!fs.existsSync(folder)) { | ||
fs.mkdirSync(folder); | ||
} | ||
|
||
const apiFile = resolve(`${paths.outputRoot}/extension-points/api.md`); | ||
|
||
let markdown = renderYamlFrontMatter({ | ||
gid: findUuid(apiFile), | ||
url: `${paths.shopifyDevUrl}/extension-points/api`, | ||
title: 'Extension points API', | ||
hidden: true, | ||
}); | ||
|
||
interfaces.forEach(({name, docs, properties}) => { | ||
markdown += propsTable( | ||
name, | ||
docs, | ||
properties, | ||
nodes, | ||
extensionsIndex, | ||
additionalPropsTables, | ||
undefined, | ||
undefined, | ||
); | ||
}); | ||
|
||
markdown += dedupe(additionalPropsTables).reverse().join(''); | ||
|
||
fs.writeFile(apiFile, markdown, function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
additionalPropsTables.length = 0; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not put these docs in the same place as Checkout like
docs/admin-extensions
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably yes, haven't finalized this yet. not concerned about this right now.