forked from Azure/azure-resource-manager-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1070 from Descatles/OnbroadAutorestSchema
Onboard autorest.schema to sdkauto
- Loading branch information
Showing
8 changed files
with
1,441 additions
and
7 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ npm-debug.log | |
node_modules | ||
.DS_Store | ||
test-results.xml | ||
schemas/code-model-v1 |
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,70 @@ | ||
import path from 'path'; | ||
import chalk from 'chalk'; | ||
import { executeSynchronous, lowerCaseEquals, safeUnlink } from '../utils'; | ||
import { findAutogenEntries } from '../autogenlist'; | ||
import { saveAutogeneratedSchemaRefs, SchemaConfiguration, schemaPostProcess } from '../generate'; | ||
import * as constants from '../constants'; | ||
|
||
async function getChangedSchemas(repoPath: string) { | ||
var git = require('nodegit-kit'); | ||
const repo = await git.open(repoPath); | ||
const status = await git.status(repo); | ||
const changedSchemas: { path: string, isNew: boolean }[] = []; | ||
for (const stat of status) { | ||
if (stat.path.toString().split(path.sep).indexOf('schemas') !== -1 | ||
&& path.extname(stat.path) === '.json') { | ||
if (stat.status !== 'modified' && stat.status !== 'new') { | ||
throw new Error(`Undefined file status for '${stat.path}'.`); | ||
} else { | ||
if (stat.status === 'modified') { | ||
changedSchemas.push({ | ||
path: path.join(repoPath, stat.path), | ||
isNew: false | ||
}); | ||
} else { | ||
changedSchemas.push({ | ||
path: path.join(repoPath, stat.path), | ||
isNew: true | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return changedSchemas; | ||
} | ||
|
||
async function postProcessor(basePath: string) { | ||
const autogenEntries = findAutogenEntries(basePath); | ||
let changedSchemas = await getChangedSchemas(constants.generatorRoot); | ||
let schemaConfigs: SchemaConfiguration[] = []; | ||
for (const changedSchema of changedSchemas) { | ||
const changedSchemaPath = changedSchema.path; | ||
console.log('Processing changed schema file: ' + chalk.green(changedSchemaPath)); | ||
const namespace = path.basename(changedSchemaPath.substring(0, changedSchemaPath.lastIndexOf(path.extname(changedSchemaPath)))); | ||
const autogenEntriesSameNamespace = autogenEntries | ||
.filter(autogenEntry => lowerCaseEquals(autogenEntry.namespace, namespace)); | ||
if (autogenEntriesSameNamespace.length === 0) { | ||
const localSchemaConfig = await schemaPostProcess(changedSchemaPath, changedSchema.isNew); | ||
schemaConfigs.push(localSchemaConfig); | ||
} else { | ||
if (autogenEntriesSameNamespace.length > 1) { | ||
throw new Error(`Multiple autogenEntries for '${changedSchemaPath}'`); | ||
} | ||
const autogenlistConfig = autogenEntriesSameNamespace[0]; | ||
const localSchemaConfig = await schemaPostProcess(changedSchemaPath, changedSchema.isNew, autogenlistConfig); | ||
schemaConfigs.push(localSchemaConfig); | ||
} | ||
} | ||
await saveAutogeneratedSchemaRefs(schemaConfigs); | ||
await safeUnlink(path.join(constants.generatorRoot, "schemas", "code-model-v1")); | ||
} | ||
|
||
executeSynchronous(async () => { | ||
const basePath = process.argv[2]; | ||
try { | ||
await postProcessor(basePath); | ||
console.log(`PostProcessor finished successfully.`); | ||
} catch (e) { | ||
console.error(`PostProcessor ${e}`); | ||
} | ||
}); |
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
Oops, something went wrong.