Skip to content

Commit

Permalink
More info and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed Jul 23, 2018
1 parent 10aefb6 commit ad79ddd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
9 changes: 4 additions & 5 deletions schemas/json-schemas.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@
"renovate.json": "0d101a938bfe5b02a182d77d982aada0f848e61164b77166b5b312f9f1db581f",
"resjson.json": "f268c7820133f09c68c0599a1adce555255aa93e27f0ddb8c54c69da1e254f3f",
"resume.json": "eb8a83b073f722118788c1f631d82e0adb5207268475582c340469be71e5e395",
"sarif-1.0.0-beta.4.json": "51d6126ec481cf6928036d239c44289cc7de78b592d6e8ae05c1bdc1cad6d42a",
"sarif-1.0.0-beta.5.json": "9f9bcdbfcc83d160b3e16a7c030b5418bd88d481bf08097916fd6c1c765bf9a0",
"sarif-1.0.0.json": "3d381606211e14da54498868bce849356d45f52b3fbb2495e49c24477d8f735c",
"sarif.json": "3d381606211e14da54498868bce849356d45f52b3fbb2495e49c24477d8f735c",
"sarif-2.0.0.json": "cd1a636e7d8bedca54a48f6b4c3215f4509fccd7b4dbe11229864f106d3f4537",
"sarif.json": "cd1a636e7d8bedca54a48f6b4c3215f4509fccd7b4dbe11229864f106d3f4537",
"schema-catalog.json": "b7ba9aea97d38e0dbf9a52153627d4339c73efd1e8865749fadf4eb236c9c321",
"schema-draft-v4.json": "4ac3fdcf0206cb602f566289543696bd37655c6596b07677d139d9475583a8d5",
"schema-org-action.json": "3d724ac446abd13c22804d9fa3d00725ce3f7464309a1527423f917c3e7e6e47",
Expand All @@ -116,10 +115,10 @@
"templatesources.json": "67d9444da899b52138b8491f871ee5f513eede337a3aaf964d2fac3ad68a5e22",
"toolinfo.1.1.0.json": "2ac8092b86a5a4a11b00b04fad8df9e037d8e077a6a5a8be9494574085bfe55a",
"travis.json": "70fcefb4308f7f0ce6e448ad8aab5e2f2468c4ddfe4c233d784ea4e8be09770b",
"tsconfig.json": "85a35207c2d5748450a9cddf91215bae3fc995fe8c51737715b4129e288f326c",
"tsconfig.json": "28ccf425d1f1e91aff349fe85e0fd204ce3976d7ee865e7d81cdcf477d12b559",
"tsd.json": "c34d6febcf996c2462470c24aa7279637c3f9f3280ebf6e6791aff1e04732540",
"tsdrc.json": "e7fb85d7bceeeaf481f3fad0c950fda6cc54ad007391c6c9f776e846ff910765",
"tslint.json": "80792be00ca3d8a831ce349ada70f2edc1ac6b769d2234f329091ceac04a5e2e",
"tslint.json": "47681a35cd504955afbe712ff1c910b4c3c70d585d1495f18053e95a7349159f",
"typewiz.json": "747458f24c4d9146c57de79f971705164b22eaeefc3642ba364b3c6c770492e1",
"typings.json": "0f32f8d1be86efb73afa8ee5bb936884bcabe9f2411a06a87aa26995b25c4143",
"typingsrc.json": "776174b3533248323c84af0df8b2b3a951d1c8a01a204eeea3b5470ab3db3175",
Expand Down
2 changes: 0 additions & 2 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
"project-1.0.0-rc2.json",
"project.json",
"proxies.json",
"sarif-1.0.0-beta.4.json",
"sarif-1.0.0-beta.5.json",
"schema-org-action.json",
"schema-org-contact-point.json",
"schema-org-place.json",
Expand Down
33 changes: 24 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SchemaGenerator {
});
}

private async generateSchemas(jsonData: SchemaHashes) {
private async generateSchemas(jsonData: SchemaHashes): Promise<string[]> {
const disabledSchemas = [];
for (const fileName in jsonData) {
const fileNameResolved = path.resolve(this.jsonSchemasDir, fileName);
Expand All @@ -53,7 +53,7 @@ class SchemaGenerator {
} catch (error) {
this.logger.error(`Can't process "${fileName}". Adding to the list of disabled schemas.`)
disabledSchemas.push(fileName);
break;
continue;
}
const schemaDirResolved = path.resolve(
'schemas',
Expand All @@ -66,20 +66,29 @@ class SchemaGenerator {
{ encoding: 'utf8' }
);
}
return { disabledSchemas };

return disabledSchemas;
}

async start() {
private async removeAndClone() {
await promisify(rimraf)(this.schemaStoreDirResolved);
await this.git.clone(this.schemaStoreRepo, this.schemaStoreDirResolved, [
'--depth=1'
]);
}

async start() {
await this.removeAndClone();

const jsonFiles = (await fs.readdir(this.jsonSchemasDir)).filter(
fileName =>
fileName.endsWith('.json') && !this.disabledSchemas.includes(fileName)
fileName => {
const schemaIsDisabled = this.disabledSchemas ? this.disabledSchemas.includes(fileName) : false;
return fileName.endsWith('.json') && !schemaIsDisabled;
}
);
this.logger.info(`Loaded ${jsonFiles.length} schemas.`);

this.logger.info(`Loaded ${jsonFiles.length} schemas and ${this.disabledSchemas.length} disabled schemas.`);

const jsonData: SchemaHashes = {};
for (const fileName of jsonFiles) {
const fileNameResolved = path.resolve(this.jsonSchemasDir, fileName);
Expand All @@ -94,10 +103,12 @@ class SchemaGenerator {
jsonData[fileName] = sha256;
}

let disabledSchemas = [];
if (!fs.existsSync(this.lockFile)) {
this.logger.info(`No lockfile exists yet. Writing lockfile to "${this.lockFile}" ..`)
await this.generateSchemas(jsonData);

await this.generateLockFile(this.lockFile, jsonData);
disabledSchemas = await this.generateSchemas(jsonData);
} else {
const lockFileData = await fs.readFile(this.lockFile, { encoding: 'utf8' });
const lockFileParsed = JSON.parse(lockFileData);
Expand All @@ -111,7 +122,11 @@ class SchemaGenerator {
updatedHashes[fileName] = jsonData[fileName];
}
}
await this.generateSchemas(updatedHashes);
disabledSchemas = await this.generateSchemas(updatedHashes);
}

if (disabledSchemas.length) {
this.logger.info(`You should consider disabling these schemas: ${disabledSchemas.join(', ')}`)
}
}
}
Expand Down

0 comments on commit ad79ddd

Please sign in to comment.