Skip to content

Commit

Permalink
fix: Don't throw on invalid versions, more info
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed Jul 5, 2019
1 parent d2df9a1 commit 063a077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/SchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class SchemaGenerator {
: path.join('temp/schemastore');
this.jsonSchemasDir = path.join(this.schemaStoreDirResolved, 'src/schemas/json');
this.lockFile = path.resolve(this.options.lockFile);
this.logFile = path.join(__dirname, '../schemastore.log');
this.updatedFilesFile = path.join(__dirname, '../updated_files');
this.logFile = path.resolve('schemagenerator.log');
this.updatedFilesFile = path.resolve('updated_files');
this.logger = logdown('schemastore-updater/SchemaGenerator', {
logger: console,
markdown: false,
Expand Down Expand Up @@ -67,7 +67,8 @@ export class SchemaGenerator {
}
}

private async generateLockFile(fileName: string, data: SchemaHashes): Promise<void> {
private async writeLockFile(fileName: string, data: SchemaHashes): Promise<void> {
this.logger.info(`Writing lockfile "${fileName}" ...`);
const sortedData = jsonAbc.sortObj(data, true);
await fs.writeJson(path.resolve(fileName), sortedData, {spaces: 2});
}
Expand Down Expand Up @@ -216,7 +217,7 @@ Files were exported from https://github.com/ffflorian/schemastore-updater/tree/m
}

if (invalidEntries.length) {
throw new Error(`Invalid version entries: "${invalidEntries.join('", "')}".`);
this.logger.error(`Invalid version entries: "${invalidEntries.join('", "')}".`);
}
}

Expand Down Expand Up @@ -313,7 +314,7 @@ Files were exported from https://github.com/ffflorian/schemastore-updater/tree/m
}
}

await this.generateLockFile(this.lockFile, lockFileData);
await this.writeLockFile(this.lockFile, updatedHashes);

return {
disabledSchemas,
Expand Down
11 changes: 7 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ program
try {
const settings = await fs.readJSON(settingsFile);
await update({...settings, force: parent.force, source: parent.source});
await checkDisabled(settings);
await checkDisabled(settings, false);
} catch (error) {
console.error(`Error: ${error.message}`);
process.exit(1);
Expand Down Expand Up @@ -81,16 +81,19 @@ async function update(settings: Required<SchemaGeneratorOptions>): Promise<void>
}

if (newDisabledSchemas.length) {
console.log(`These schemas will be disabled: "${newDisabledSchemas.join(', ')}"`);
console.log('These schemas will be disabled:', newDisabledSchemas);

settings.disabledSchemas = settings.disabledSchemas.concat(newDisabledSchemas).sort();
await fs.writeFile(settingsFile, `${JSON.stringify(settings, null, 2)}\n`);
}
}

async function checkDisabled(settings: FileSettings): Promise<void> {
async function checkDisabled(settings: FileSettings, versionCheck = true): Promise<void> {
const generator = new SchemaGenerator(settings);
await generator.checkVersions();

if (versionCheck) {
await generator.checkVersions();
}

const {enabledSchemas} = await generator.checkDisabled();

Expand Down

0 comments on commit 063a077

Please sign in to comment.