mirror of
https://github.com/brittonhayes/validate-yaml.git
synced 2024-11-23 05:30:56 -05:00
chore: Repository cleanup and re-structure
This commit is contained in:
parent
298a8f153c
commit
77cf0d80af
16 changed files with 623 additions and 688 deletions
|
@ -1,4 +1,3 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
jest.config.js
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
# Dependency directory
|
||||
node_modules
|
||||
dist
|
||||
|
||||
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import {validateYAML} from '../src/validate'
|
||||
import {expect, test} from '@jest/globals'
|
||||
|
||||
test('valid yaml files', async () => {
|
||||
const files: string[] = ['__tests__/valid.yaml']
|
||||
const schemaPath: string = '__tests__/schema.json'
|
||||
|
||||
await expect(validateYAML(files, schemaPath)).resolves.toBe(0)
|
||||
})
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
BIN
dist/sourcemap-register.js
generated
vendored
BIN
dist/sourcemap-register.js
generated
vendored
Binary file not shown.
BIN
dist/validate.js
generated
vendored
Normal file
BIN
dist/validate.js
generated
vendored
Normal file
Binary file not shown.
12
package.json
12
package.json
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "validate-yaml",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"private": false,
|
||||
"description": "Validate YAML against a schema using github actions",
|
||||
"main": "lib/index.js",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"format:check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build --source-map --license licenses.txt",
|
||||
"test": "jest",
|
||||
|
@ -15,13 +15,13 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/brittonhayes/wails-build-action.git"
|
||||
"url": "git+https://github.com/brittonhayes/validate-yaml.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"go",
|
||||
"wails"
|
||||
"typescript",
|
||||
"yaml"
|
||||
],
|
||||
"author": "Britton Hayes",
|
||||
"license": "MIT",
|
||||
|
|
12
src/__tests__/main.test.ts
Normal file
12
src/__tests__/main.test.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
// eslint-disable-next-line filenames/match-regex
|
||||
import * as t from '@jest/globals'
|
||||
import {Validator} from '../lib/validate'
|
||||
|
||||
t.test('valid yaml files', async () => {
|
||||
const validator = new Validator({
|
||||
files: ['src/__tests__/valid.yaml'],
|
||||
schemaPath: 'src/__tests__/schema.json'
|
||||
})
|
||||
|
||||
await t.expect(validator.ValidateYAML()).resolves.toBe(0)
|
||||
})
|
10
src/index.ts
10
src/index.ts
|
@ -1,12 +1,14 @@
|
|||
import * as core from '@actions/core'
|
||||
import {validateYAML} from './validate'
|
||||
import {Validator} from './lib/validate'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const files: string[] = core.getMultilineInput('files')
|
||||
const schemaPath: string = core.getInput('schemaPath')
|
||||
const validator = new Validator({
|
||||
files: core.getMultilineInput('files'),
|
||||
schemaPath: core.getInput('schemaPath')
|
||||
})
|
||||
|
||||
await validateYAML(files, schemaPath)
|
||||
await validator.ValidateYAML()
|
||||
} catch (error) {
|
||||
core.setFailed((error as Error).message)
|
||||
}
|
||||
|
|
33
src/lib/validate.ts
Normal file
33
src/lib/validate.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import YamlValidator from 'yaml-validator'
|
||||
import fs from 'fs'
|
||||
|
||||
export interface ValidatorProps {
|
||||
files: string[]
|
||||
schemaPath: string
|
||||
|
||||
}
|
||||
|
||||
export class Validator {
|
||||
props: ValidatorProps
|
||||
|
||||
constructor(props: ValidatorProps) {
|
||||
this.props = props
|
||||
}
|
||||
|
||||
async ValidateYAML(): Promise<Number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const structure = fs.readFileSync(this.props.schemaPath, { encoding: 'utf-8' })
|
||||
const validator = new YamlValidator({
|
||||
log: 'validator.log',
|
||||
structure: JSON.parse(structure),
|
||||
writeJson: false,
|
||||
onWarning: (err, file) => {
|
||||
reject(new Error(`File: ${file} - ${err.message}`))
|
||||
},
|
||||
})
|
||||
|
||||
validator.validate((this.props.files))
|
||||
resolve(validator.report())
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
import YamlValidator, {IYamlValidatorOptions} from 'yaml-validator'
|
||||
import fs from 'fs'
|
||||
|
||||
export async function validateYAML(
|
||||
files: string[],
|
||||
schemaPath: string
|
||||
): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const structure = fs.readFileSync(schemaPath, {encoding: 'utf-8'})
|
||||
const options: IYamlValidatorOptions = {
|
||||
log: 'validator.log',
|
||||
onWarning: (err, file) => {
|
||||
reject(new Error(`File: ${file} - ${err.message}`))
|
||||
},
|
||||
structure: JSON.parse(structure),
|
||||
writeJson: false
|
||||
}
|
||||
|
||||
const validator = new YamlValidator(options)
|
||||
validator.validate(files)
|
||||
resolve(validator.report())
|
||||
})
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue