chore: Repository cleanup and re-structure

This commit is contained in:
Britton Hayes 2021-12-24 14:13:55 -08:00
parent 298a8f153c
commit 77cf0d80af
No known key found for this signature in database
GPG key ID: 922B4F3652980643
16 changed files with 623 additions and 688 deletions

View file

@ -1,4 +1,3 @@
dist/ dist/
lib/
node_modules/ node_modules/
jest.config.js jest.config.js

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Dependency directory # Dependency directory
node_modules node_modules
dist
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore # Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs # Logs

View file

@ -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

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

BIN
dist/sourcemap-register.js generated vendored

Binary file not shown.

BIN
dist/validate.js generated vendored Normal file

Binary file not shown.

View file

@ -1,13 +1,13 @@
{ {
"name": "validate-yaml", "name": "validate-yaml",
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": false,
"description": "Validate YAML against a schema using github actions", "description": "Validate YAML against a schema using github actions",
"main": "lib/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"format": "prettier --write **/*.ts", "format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts", "format:check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts", "lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt", "package": "ncc build --source-map --license licenses.txt",
"test": "jest", "test": "jest",
@ -15,13 +15,13 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/brittonhayes/wails-build-action.git" "url": "git+https://github.com/brittonhayes/validate-yaml.git"
}, },
"keywords": [ "keywords": [
"actions", "actions",
"node", "node",
"go", "typescript",
"wails" "yaml"
], ],
"author": "Britton Hayes", "author": "Britton Hayes",
"license": "MIT", "license": "MIT",

View 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)
})

View file

@ -1,12 +1,14 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {validateYAML} from './validate' import {Validator} from './lib/validate'
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
const files: string[] = core.getMultilineInput('files') const validator = new Validator({
const schemaPath: string = core.getInput('schemaPath') files: core.getMultilineInput('files'),
schemaPath: core.getInput('schemaPath')
})
await validateYAML(files, schemaPath) await validator.ValidateYAML()
} catch (error) { } catch (error) {
core.setFailed((error as Error).message) core.setFailed((error as Error).message)
} }

33
src/lib/validate.ts Normal file
View 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())
})
}
}

View file

@ -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())
})
}

View file

@ -1,12 +1,14 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "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'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */ "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. */ "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. */ "strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ "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'. */ "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",
]
} }

1190
yarn.lock

File diff suppressed because it is too large Load diff