Skip to content
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

Feat/template #10

Merged
merged 30 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a24a361
create json template
Si3rr4wow Nov 23, 2022
9d56f70
write json and yaml to bin postbuild
Si3rr4wow Nov 23, 2022
da193b4
Merge branch 'main' into feat/template
Si3rr4wow Nov 24, 2022
cc8be87
Update src/write-yaml-template.ts
Si3rr4wow Nov 24, 2022
64186f3
Update src/write-yaml-template.ts
Si3rr4wow Nov 24, 2022
7c9d32a
fix engines and declaration. neater build
Si3rr4wow Nov 25, 2022
e05074a
Merge branch 'main' into feat/template
robmorgan-tab Nov 28, 2022
a710e3c
it's alive!
Si3rr4wow Nov 28, 2022
4e05cc5
Merge branch 'feat/template' of github.com:theappbusiness/patios into…
Si3rr4wow Nov 28, 2022
35ea45f
deconflictify ts and eslint
Si3rr4wow Nov 28, 2022
73b77d4
Fix YAML content conversion
robmorgan-tab Nov 28, 2022
5362824
Remote TS definitions for old prompt library
robmorgan-tab Nov 28, 2022
611ef73
Make eslint ignore bin files
robmorgan-tab Nov 28, 2022
4e9072d
ditch post build, link yaml correctly
Si3rr4wow Nov 28, 2022
09a8245
Merge branch 'feat/template' of github.com:theappbusiness/patios into…
Si3rr4wow Nov 29, 2022
687877e
validate templates pre push
Si3rr4wow Nov 29, 2022
64a8126
banish fs and path to top
Si3rr4wow Dec 1, 2022
f5e2f10
remove spool, I didn't like that name
Si3rr4wow Dec 2, 2022
3e93353
Use import type for TS definition imports
robmorgan-tab Dec 19, 2022
fe9745d
Move node stub TS definitions
robmorgan-tab Dec 19, 2022
f264935
Fix cross-platform issues with validate-templates
robmorgan-tab Dec 20, 2022
ce4f7db
Add tests for mockify
robmorgan-tab Dec 20, 2022
e8d1c18
Separate format assertions for getTemplateFileStrings
robmorgan-tab Dec 20, 2022
de04a44
Ensure pretty output of JSON from getTemplateFileStrings
robmorgan-tab Dec 20, 2022
7990792
Reduce repetition in writeFileToBinFactory
robmorgan-tab Dec 20, 2022
219cd79
Merge pull request #15 from theappbusiness/dev/hexagonal-refactor
robmorgan-tab Dec 20, 2022
29917bb
Tidy up of write-file-to-bin
robmorgan-tab Dec 20, 2022
37fcd45
Add dev:quick command to bypass the wizard
robmorgan-tab Dec 20, 2022
15eab1f
Amend BinTargetPaths type for consistency
robmorgan-tab Dec 20, 2022
c314e4d
Write the boilerplate templates to a src directory
robmorgan-tab Dec 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions json-to-pretty-yaml.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'json-to-pretty-yaml' {
function stringify(json: string): string
}
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
},
"scripts": {
"test": "jest",
"dev": "node-dev src/index.ts",
"dev": "node-dev src/write-yaml-template.ts",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be removed in a later commit, I just didn't wanna have to run the wizard over and over to test this

"build": "tsc",
"postbuild": "node bin/write-yaml-template.js",
"format": "prettier -w .",
"lint": "eslint --ignore-path .prettierignore \"**/*.ts\"",
"lint:fix": "eslint --fix --ignore-path .prettierignore \"**/*.ts\"",
Expand Down Expand Up @@ -44,6 +45,7 @@
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.2",
"jest": "^29.3.1",
"json-to-pretty-yaml": "^1.2.2",
"lint-staged": "^13.0.3",
"node-dev": "^7.4.3",
"prettier": "^2.7.1",
Expand All @@ -55,7 +57,7 @@
},
"lint-staged": {
"*.{js,ts}": [
"npm run typecheck",
"npm run typecheck -- --lib ESNext",
robmorgan-tab marked this conversation as resolved.
Show resolved Hide resolved
"npm run format",
"npm run lint:fix"
]
Expand Down
45 changes: 45 additions & 0 deletions src/write-yaml-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as fs from 'fs'
import * as path from 'path'
import { stringify } from 'json-to-pretty-yaml'

const walk = (dir: string, prevResults?: string[]): string[] => {
const list = fs.readdirSync(dir)
const results = prevResults || []
list.forEach((file) => {
file = path.resolve(dir, file)
const stat = fs.statSync(file)
if (stat && stat.isDirectory()) {
walk(file, results)
} else {
results.push(file)
}
})
return results
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sense this would be more testable if I removed the dependency on fs

Copy link
Contributor

@robmorgan-tab robmorgan-tab Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could use one of the many libraries which have this functionality built in. ;)

Then you have no need to write tests for the file system functionality - trust the library :D


;((): void => {
fs.mkdirSync('./bin/templates')
const jsonPaths = walk('./templates/json')
jsonPaths.forEach((jsonPath) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const json = require(jsonPath)
Si3rr4wow marked this conversation as resolved.
Show resolved Hide resolved
const data = stringify(json)
const binJsonTemplatesPath = jsonPath.replace(
'/templates/',
'/bin/templates/',
)
const binYamlTemplatesPath = binJsonTemplatesPath.replaceAll('json', 'yaml')
const jsonDirname = path.dirname(binJsonTemplatesPath)
const yamlDirname = path.dirname(binYamlTemplatesPath)
const jsonStat = fs.statSync(jsonDirname, { throwIfNoEntry: false })
const yamlStat = fs.statSync(jsonDirname, { throwIfNoEntry: false })
Si3rr4wow marked this conversation as resolved.
Show resolved Hide resolved
if (!jsonStat?.isDirectory()) {
fs.mkdirSync(jsonDirname)
}
if (!yamlStat?.isDirectory()) {
fs.mkdirSync(yamlDirname)
}
fs.writeFileSync(binJsonTemplatesPath, data)
fs.writeFileSync(binYamlTemplatesPath, data)
})
})()
14 changes: 14 additions & 0 deletions templates/json/[entryPoint].json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"openapi": "3.0.2",
"info": {
"title": "Welcome to PATIOS",
"description": "Manage large Open API specifications and automatically generate TypeScript definitions",
"version": "1.0"
},
"servers": [{ "url": "https://github.com/theappbusiness/patios/" }],
"paths": {
"/v1/information": {
"$ref": "./paths/information.json"
}
}
}
8 changes: 8 additions & 0 deletions templates/json/attributes/heading.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "object",
"properties": {
"heading": {
"type": "string"
}
}
}
3 changes: 3 additions & 0 deletions templates/json/examples/content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"heading": "Welcome to PATIOS"
}
10 changes: 10 additions & 0 deletions templates/json/paths/information.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"get": {
"description": "An example path providing information about PATIOS",
"responses": {
"200": {
"$ref": "../responses/informationSuccess.json"
}
}
}
}
10 changes: 10 additions & 0 deletions templates/json/responses/informationSuccess.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/information.json"
}
}
}
}
16 changes: 16 additions & 0 deletions templates/json/schemas/information.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "object",
"properties": {
"content": {
"type": "object",
"allOf": [
{
"$ref": "../attributes/heading.json"
}
],
"example": {
"$ref": "../examples/content.json"
}
}
}
}