diff --git a/nx.json b/nx.json index 02177e07..b8bb282c 100644 --- a/nx.json +++ b/nx.json @@ -14,11 +14,11 @@ "cache": true }, "compile-executable-examples": { - "dependsOn": ["test:ci","format"], + "dependsOn": ["test:ci", "format"], "cache": true }, "build:typedoc": { - "dependsOn": ["^build","^compile-executable-examples"], + "dependsOn": ["^build", "^compile-executable-examples"], "cache": true, "outputs": ["{projectRoot}/static/reference"] }, diff --git a/packages/docs/docs/350-examples.md b/packages/docs/docs/350-examples.md index b740a5ed..4e993eb6 100644 --- a/packages/docs/docs/350-examples.md +++ b/packages/docs/docs/350-examples.md @@ -1,19 +1,18 @@ # Examples - ## Find all users with ids in the list +## Find all users with ids in the list Finds all records in the `users` table where the `id` is in the list of ids. - ```ts const q = from('users') .columns('id', 'name') .where({ id: { in: ids } }) .many(); -const result: UseQueryResult< - Array<{ id: string; name: string }> -> = useSynthql(q); - - -``` \ No newline at end of file +const result: UseQueryResult> = useSynthql< + DB, + 'users', + typeof q +>(q); +``` diff --git a/packages/react/tsconfig.json b/packages/react/tsconfig.json index 3e19ccb9..f434b062 100644 --- a/packages/react/tsconfig.json +++ b/packages/react/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "./build/types", "emitDeclarationOnly": true, - "jsx": "preserve" + "jsx": "preserve", }, "include": ["src"], "exclude": ["./build/*", "./node_modules/*"], diff --git a/scripts/compile-executable-examples.cjs b/scripts/compile-executable-examples.cjs index 9accb1ed..e6dcdbe7 100644 --- a/scripts/compile-executable-examples.cjs +++ b/scripts/compile-executable-examples.cjs @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); // Command line arguments -const [,, testFilePath] = process.argv; +const [, , testFilePath] = process.argv; // Check if the test file path is provided if (!testFilePath) { @@ -12,8 +12,8 @@ if (!testFilePath) { // Function to parse the test file and extract examples /** - * - * @param {string} filePath + * + * @param {string} filePath * @returns {Array<{ title: string, description: string, code: string }> */ function parseTestFile(filePath) { @@ -25,14 +25,19 @@ function parseTestFile(filePath) { for (const line of lines) { if (line.includes('@@start-example@@')) { - currentExample = { title: line.split('@@start-example@@')[1].trim(), description: '', code: '' }; + currentExample = { + title: line.split('@@start-example@@')[1].trim(), + description: '', + code: '', + }; collectingDescription = true; } else if (line.includes('@@end-example@@')) { examples.push(currentExample); currentExample = null; collectingDescription = false; } else if (collectingDescription && line.includes('@@desc@@')) { - currentExample.description += line.split('@@desc@@')[1].trim() + '\n'; + currentExample.description += + line.split('@@desc@@')[1].trim() + '\n'; } else if (currentExample) { currentExample.code += line + '\n'; } @@ -47,52 +52,62 @@ function parseTestFile(filePath) { /** * Takes a string of code and fixes the indentation by removing the common leading whitespace - * - * @param {string} code + * + * @param {string} code * @returns {string} */ function fixIdentation(code) { const lines = code.split('\n'); const leadingWhitespace = lines - .filter(line => line.trim().length > 0) - .map(line => line.match(/^\s*/)[0]) + .filter((line) => line.trim().length > 0) + .map((line) => line.match(/^\s*/)[0]) .reduce((acc, whitespace) => { if (acc === null) { return whitespace; } let i = 0; - while (i < acc.length && i < whitespace.length && acc[i] === whitespace[i]) { + while ( + i < acc.length && + i < whitespace.length && + acc[i] === whitespace[i] + ) { i++; } return acc.slice(0, i); }, null); - return lines.map(line => line.replace(leadingWhitespace, '')).join('\n'); + return lines.map((line) => line.replace(leadingWhitespace, '')).join('\n'); } /** - * + * * @param {Array<{ title: string, description: string, code: string }>} examples * @returns {string} */ function generateMarkdown(examples) { - return examples.map(example => { - return [ - `## ${example.title}`, - `${example.description}`, - "```ts\n"+example.code+"\n```", - ] - .filter(x => x.length>0) + return examples + .map((example) => { + return [ + `## ${example.title}`, + `${example.description}`, + '```ts\n' + example.code + '\n```', + ] + .filter((x) => x.length > 0) + .join('\n\n'); + }) .join('\n\n'); - }).join('\n\n'); } // Main function to process the test file and generate markdown function main() { const examples = parseTestFile(testFilePath); const markdown = `# Examples\n\n ${generateMarkdown(examples)}`; - const outputFilePath = path.join(__dirname,'../packages/docs/docs', '350-examples.md'); + const outputFilePath = path.join( + __dirname, + '../packages/docs/docs', + '350-examples.md', + ); fs.writeFileSync(outputFilePath, markdown); console.log(`Markdown generated at ${outputFilePath}`); } -main(); \ No newline at end of file +main();