Add schema (#33095)
This commit is contained in:
parent
373ad382b5
commit
5de604e490
|
@ -73,19 +73,19 @@ export default class Analyzer extends Command {
|
||||||
async run(): Promise< void > {
|
async run(): Promise< void > {
|
||||||
const { args, flags } = await this.parse( Analyzer );
|
const { args, flags } = await this.parse( Analyzer );
|
||||||
|
|
||||||
await this.validateArgs( flags.source );
|
this.validateArgs( flags.source );
|
||||||
|
|
||||||
const patchContent = await generatePatch(
|
const patchContent = generatePatch(
|
||||||
flags.source,
|
flags.source,
|
||||||
args.compare,
|
args.compare,
|
||||||
flags.base,
|
flags.base,
|
||||||
( e: string ): void => this.error( e )
|
( e: string ): void => this.error( e )
|
||||||
);
|
);
|
||||||
|
|
||||||
const pluginData = await this.getPluginData( flags.plugin );
|
const pluginData = this.getPluginData( flags.plugin );
|
||||||
this.log( `${ pluginData[ 1 ] } Version: ${ pluginData[ 0 ] }` );
|
this.log( `${ pluginData[ 1 ] } Version: ${ pluginData[ 0 ] }` );
|
||||||
|
|
||||||
await this.scanChanges( patchContent, pluginData[ 0 ], flags.output );
|
this.scanChanges( patchContent, pluginData[ 0 ], flags.output );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,7 +93,7 @@ export default class Analyzer extends Command {
|
||||||
*
|
*
|
||||||
* @param {string} source The GitHub repository we are merging.
|
* @param {string} source The GitHub repository we are merging.
|
||||||
*/
|
*/
|
||||||
private async validateArgs( source: string ): Promise< void > {
|
private validateArgs( source: string ): void {
|
||||||
// We only support pulling from GitHub so the format needs to match that.
|
// We only support pulling from GitHub so the format needs to match that.
|
||||||
if ( ! source.match( /^[a-z0-9\-]+\/[a-z0-9\-]+$/ ) ) {
|
if ( ! source.match( /^[a-z0-9\-]+\/[a-z0-9\-]+$/ ) ) {
|
||||||
this.error(
|
this.error(
|
||||||
|
@ -106,9 +106,9 @@ export default class Analyzer extends Command {
|
||||||
* Get plugin data
|
* Get plugin data
|
||||||
*
|
*
|
||||||
* @param {string} plugin Plugin slug.
|
* @param {string} plugin Plugin slug.
|
||||||
* @return {Promise<string[]>} Promise.
|
* @return {string[]} Promise.
|
||||||
*/
|
*/
|
||||||
private async getPluginData( plugin: string ): Promise< string[] > {
|
private getPluginData( plugin: string ): string[] {
|
||||||
/**
|
/**
|
||||||
* List of plugins from our monorepo.
|
* List of plugins from our monorepo.
|
||||||
*/
|
*/
|
||||||
|
@ -166,16 +166,16 @@ export default class Analyzer extends Command {
|
||||||
* @param {string} version Current product version.
|
* @param {string} version Current product version.
|
||||||
* @param {string} output Output style.
|
* @param {string} output Output style.
|
||||||
*/
|
*/
|
||||||
private async scanChanges(
|
private scanChanges(
|
||||||
content: string,
|
content: string,
|
||||||
version: string,
|
version: string,
|
||||||
output: string
|
output: string
|
||||||
): Promise< void > {
|
): void {
|
||||||
const templates = await this.scanTemplates( content, version );
|
const templates = this.scanTemplates( content, version );
|
||||||
const hooks = await this.scanHooks( content, version, output );
|
const hooks = this.scanHooks( content, version, output );
|
||||||
|
|
||||||
if ( templates.size ) {
|
if ( templates.size ) {
|
||||||
await printTemplateResults(
|
printTemplateResults(
|
||||||
templates,
|
templates,
|
||||||
output,
|
output,
|
||||||
'TEMPLATE CHANGES',
|
'TEMPLATE CHANGES',
|
||||||
|
@ -186,11 +186,8 @@ export default class Analyzer extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hooks.size ) {
|
if ( hooks.size ) {
|
||||||
await printHookResults(
|
printHookResults( hooks, output, 'HOOKS', ( s: string ): void =>
|
||||||
hooks,
|
this.log( s )
|
||||||
output,
|
|
||||||
'HOOKS',
|
|
||||||
( s: string ): void => this.log( s )
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.log( 'No new hooks found' );
|
this.log( 'No new hooks found' );
|
||||||
|
@ -204,10 +201,10 @@ export default class Analyzer extends Command {
|
||||||
* @param {string} version Current product version.
|
* @param {string} version Current product version.
|
||||||
* @return {Promise<Map<string, string[]>>} Promise.
|
* @return {Promise<Map<string, string[]>>} Promise.
|
||||||
*/
|
*/
|
||||||
private async scanTemplates(
|
private scanTemplates(
|
||||||
content: string,
|
content: string,
|
||||||
version: string
|
version: string
|
||||||
): Promise< Map< string, string[] > > {
|
): Map< string, string[] > {
|
||||||
CliUx.ux.action.start( 'Scanning template changes' );
|
CliUx.ux.action.start( 'Scanning template changes' );
|
||||||
|
|
||||||
const report: Map< string, string[] > = new Map< string, string[] >();
|
const report: Map< string, string[] > = new Map< string, string[] >();
|
||||||
|
@ -261,11 +258,11 @@ export default class Analyzer extends Command {
|
||||||
* @param {string} output Output style.
|
* @param {string} output Output style.
|
||||||
* @return {Promise<Map<string, Map<string, string[]>>>} Promise.
|
* @return {Promise<Map<string, Map<string, string[]>>>} Promise.
|
||||||
*/
|
*/
|
||||||
private async scanHooks(
|
private scanHooks(
|
||||||
content: string,
|
content: string,
|
||||||
version: string,
|
version: string,
|
||||||
output: string
|
output: string
|
||||||
): Promise< Map< string, Map< string, string[] > > > {
|
): Map< string, Map< string, string[] > > {
|
||||||
CliUx.ux.action.start( 'Scanning for new hooks' );
|
CliUx.ux.action.start( 'Scanning for new hooks' );
|
||||||
|
|
||||||
const report: Map< string, Map< string, string[] > > = new Map<
|
const report: Map< string, Map< string, string[] > > = new Map<
|
||||||
|
|
|
@ -12,12 +12,12 @@ import { readFileSync } from 'fs';
|
||||||
*
|
*
|
||||||
* @param {string} branch branch/commit hash.
|
* @param {string} branch branch/commit hash.
|
||||||
* @param {Function} error error print method.
|
* @param {Function} error error print method.
|
||||||
* @return {Promise<boolean>} Promise.
|
* @return {boolean} Promise.
|
||||||
*/
|
*/
|
||||||
export const fetchBranch = async (
|
export const fetchBranch = (
|
||||||
branch: string,
|
branch: string,
|
||||||
error: ( s: string ) => void
|
error: ( s: string ) => void
|
||||||
): Promise< boolean > => {
|
): boolean => {
|
||||||
CliUx.ux.action.start( `Fetching ${ branch }` );
|
CliUx.ux.action.start( `Fetching ${ branch }` );
|
||||||
const branches = execSync( 'git branch', {
|
const branches = execSync( 'git branch', {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
|
@ -37,6 +37,7 @@ export const fetchBranch = async (
|
||||||
execSync( `git branch ${ branch } origin/${ branch }` );
|
execSync( `git branch ${ branch } origin/${ branch }` );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
error( `Unable to fetch ${ branch }` );
|
error( `Unable to fetch ${ branch }` );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CliUx.ux.action.stop();
|
CliUx.ux.action.stop();
|
||||||
|
@ -50,22 +51,22 @@ export const fetchBranch = async (
|
||||||
* @param {string} compare Branch/commit hash to compare against the base.
|
* @param {string} compare Branch/commit hash to compare against the base.
|
||||||
* @param {string} base Base branch/commit hash.
|
* @param {string} base Base branch/commit hash.
|
||||||
* @param {Function} error error print method.
|
* @param {Function} error error print method.
|
||||||
* @return {Promise<string>} Promise.
|
* @return {string} patch string.
|
||||||
*/
|
*/
|
||||||
export const generatePatch = async (
|
export const generatePatch = (
|
||||||
source: string,
|
source: string,
|
||||||
compare: string,
|
compare: string,
|
||||||
base: string,
|
base: string,
|
||||||
error: ( s: string ) => void
|
error: ( s: string ) => void
|
||||||
): Promise< string > => {
|
): string => {
|
||||||
const filename = `${ source }-${ base }-${ compare }.patch`.replace(
|
const filename = `${ source }-${ base }-${ compare }.patch`.replace(
|
||||||
/\//g,
|
/\//g,
|
||||||
'-'
|
'-'
|
||||||
);
|
);
|
||||||
const filepath = join( tmpdir(), filename );
|
const filepath = join( tmpdir(), filename );
|
||||||
|
|
||||||
await fetchBranch( base, error );
|
fetchBranch( base, error );
|
||||||
await fetchBranch( compare, error );
|
fetchBranch( compare, error );
|
||||||
|
|
||||||
CliUx.ux.action.start( 'Generating patch for ' + compare );
|
CliUx.ux.action.start( 'Generating patch for ' + compare );
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
* @param {string} title Section title.
|
* @param {string} title Section title.
|
||||||
* @param {Function} log print method.
|
* @param {Function} log print method.
|
||||||
*/
|
*/
|
||||||
export const printTemplateResults = async (
|
export const printTemplateResults = (
|
||||||
data: Map< string, string[] >,
|
data: Map< string, string[] >,
|
||||||
output: string,
|
output: string,
|
||||||
title: string,
|
title: string,
|
||||||
log: ( s: string ) => void
|
log: ( s: string ) => void
|
||||||
): Promise< void > => {
|
): void => {
|
||||||
if ( output === 'github' ) {
|
if ( output === 'github' ) {
|
||||||
let opt = '\\n\\n### Template changes:';
|
let opt = '\\n\\n### Template changes:';
|
||||||
for ( const [ key, value ] of data ) {
|
for ( const [ key, value ] of data ) {
|
||||||
|
@ -46,12 +46,12 @@ export const printTemplateResults = async (
|
||||||
* @param {string} title Section title.
|
* @param {string} title Section title.
|
||||||
* @param {Function} log print method.
|
* @param {Function} log print method.
|
||||||
*/
|
*/
|
||||||
export const printHookResults = async (
|
export const printHookResults = (
|
||||||
data: Map< string, Map< string, string[] > >,
|
data: Map< string, Map< string, string[] > >,
|
||||||
output: string,
|
output: string,
|
||||||
title: string,
|
title: string,
|
||||||
log: ( s: string ) => void
|
log: ( s: string ) => void
|
||||||
): Promise< void > => {
|
): void => {
|
||||||
if ( output === 'github' ) {
|
if ( output === 'github' ) {
|
||||||
let opt = '\\n\\n### New hooks:';
|
let opt = '\\n\\n### New hooks:';
|
||||||
for ( const [ key, value ] of data ) {
|
for ( const [ key, value ] of data ) {
|
||||||
|
|
Loading…
Reference in New Issue