-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/template #10
Changes from 3 commits
a24a361
9d56f70
da193b4
cc8be87
64186f3
7c9d32a
e05074a
a710e3c
4e05cc5
35ea45f
73b77d4
5362824
611ef73
4e9072d
09a8245
687877e
64a8126
f5e2f10
3e93353
fe9745d
f264935
ce4f7db
e8d1c18
de04a44
7990792
219cd79
29917bb
37fcd45
15eab1f
c314e4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
;((): 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) | ||
}) | ||
})() |
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" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"heading": { | ||
"type": "string" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"heading": "Welcome to PATIOS" | ||
} |
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" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "../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" | ||
} | ||
} | ||
} | ||
} |
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.
to be removed in a later commit, I just didn't wanna have to run the wizard over and over to test this