-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from sketch-hq/chore/update-schema-build-process
Simplify schema build process
- Loading branch information
Showing
18 changed files
with
84 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@sketch-hq/sketch-file-format': patch | ||
--- | ||
|
||
Reorganised source code and simplified build process |
This file contains 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 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 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 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 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,55 @@ | ||
/** | ||
* Build all distributable schemas into the `dist` folder. | ||
*/ | ||
|
||
import process from 'process' | ||
|
||
import { writeFileSync } from 'fs' | ||
import { execSync } from 'child_process' | ||
import { basename } from 'path' | ||
|
||
import { assemble } from './assemble' | ||
|
||
const build = async (entry: string) => { | ||
const schema = await assemble(entry) | ||
writeFileSync( | ||
`src/${basename(entry, '.yaml')}.json`, | ||
JSON.stringify(schema, null, 2), | ||
{ encoding: 'utf8' }, | ||
) | ||
} | ||
|
||
/** | ||
* Both paths for the directory containing the schemas, as well as the directory | ||
* the generated JSON Schema should be written to must be provided as a | ||
* command-line argument. | ||
* | ||
* ts-node build-schemas.ts <schema-dir> <output-dir> | ||
*/ | ||
const main = async (args: string[]) => { | ||
const [schemaDir, outDir] = args.slice(2, 4) // user defined args start at index 2 | ||
if (!schemaDir) { | ||
console.error('missing path to directory containing schemas') | ||
process.exit(1) | ||
} | ||
if (!outDir) { | ||
console.error('missing path to output directory for generated JSON Schema') | ||
process.exit(1) | ||
} | ||
|
||
try { | ||
await Promise.all([ | ||
build(`${schemaDir}/file-format.schema.yaml`), | ||
build(`${schemaDir}/document.schema.yaml`), | ||
build(`${schemaDir}/meta.schema.yaml`), | ||
build(`${schemaDir}/user.schema.yaml`), | ||
build(`${schemaDir}/layers/page.schema.yaml`), | ||
]) | ||
execSync(`yarn prettier --write "${outDir}/*.json"`) | ||
} catch (e) { | ||
console.error(e) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
main(process.argv) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{ | ||
"extends": "@tsconfig/recommended/tsconfig.json", | ||
"include": ["src/*.ts"], | ||
"exclude": ["node_modules", "dist"], | ||
"include": ["src/index.ts"], | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"outDir": "dist", | ||
"baseUrl": "src", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
"resolveJsonModule": true, | ||
"declaration": true, | ||
"declarationMap": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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