forked from npm/cli
-
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 npm#16 from herodevs/tracker
Implement HeroDevs tracker logic in this CLI
- Loading branch information
Showing
25 changed files
with
2,571 additions
and
641 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Args, Command, Flags } from '@oclif/core'; | ||
import { TrackerInit } from './init'; | ||
import { BaseCommand } from '../../shared'; | ||
import { TrackerRun } from './run'; | ||
|
||
export default class Tracker extends Command { | ||
static description = 'Tracker info'; | ||
|
||
static examples = [`$ @herodevs/cli tracker`]; | ||
|
||
static flags = {}; | ||
|
||
static args = { | ||
init: TrackerInit.args, | ||
run: TrackerRun.args, | ||
} as any; | ||
|
||
async run(): Promise<void> {} | ||
} |
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,17 @@ | ||
import { Args, Command, Flags } from '@oclif/core'; | ||
import { initialize } from '../../shared/tracker/initialize'; | ||
import { getTheRootDirectory } from '../../shared/tracker/util'; | ||
|
||
export class TrackerInit extends Command { | ||
static description = 'Initialize the tracker configuration'; | ||
|
||
static examples = ['<%= config.bin %> <%= command.id %>']; | ||
|
||
static flags = {}; | ||
|
||
static args = {}; | ||
|
||
public async run(): Promise<void> { | ||
initialize(getTheRootDirectory(global.process.cwd())); | ||
} | ||
} |
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,48 @@ | ||
import { Args, Command, Flags } from '@oclif/core'; | ||
import { resolve } from 'path'; | ||
import { | ||
createDataVizIn, | ||
getData, | ||
getTheRootDirectory, | ||
readConfig, | ||
saveResults, | ||
} from '../../shared/tracker/util'; | ||
import { processConfig } from '../../shared/tracker/process-config'; | ||
import { ChartConfig } from '../../shared/tracker/models/chart-config'; | ||
|
||
export class TrackerRun extends Command { | ||
static description = 'Run the tracker'; | ||
|
||
static examples = ['<%= config.bin %> <%= command.id %>']; | ||
|
||
static flags = { | ||
root: Flags.string({ char: 'r', description: 'root dir of the project' }), | ||
config: Flags.string({ char: 'c', description: 'path to config file' }), | ||
chart: Flags.custom<ChartConfig>({ | ||
description: 'chart configuration', | ||
})(), | ||
}; | ||
|
||
static args = {}; | ||
|
||
public async run(): Promise<void> { | ||
const { flags } = await this.parse(TrackerRun); | ||
|
||
const localRootDir = getTheRootDirectory(global.process.cwd()); | ||
|
||
const rootDirectory = flags.root ? resolve(flags.root) : localRootDir; | ||
const config = readConfig(localRootDir, flags.config); | ||
|
||
const results = await processConfig(config, rootDirectory); | ||
|
||
saveResults(localRootDir, config.outputDir, results); | ||
|
||
const allData = getData(localRootDir, config.outputDir); | ||
|
||
const parentDir = resolve(localRootDir, config.outputDir); | ||
|
||
const chartConfig = new ChartConfig(flags.chart); | ||
|
||
await createDataVizIn(chartConfig, parentDir, allData); | ||
} | ||
} |
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,20 @@ | ||
import { Config } from './models/config'; | ||
|
||
const defaultConfig: Config = { | ||
categories: { | ||
legacy: { | ||
fileTypes: ['js', 'ts', 'html', 'css', 'scss', 'less'], | ||
includes: ['./legacy'], | ||
jsTsPairs: 'js', | ||
}, | ||
modern: { | ||
fileTypes: ['ts', 'html', 'css', 'scss', 'less'], | ||
includes: ['./modern'], | ||
jsTsPairs: 'ts', | ||
}, | ||
}, | ||
ignorePatterns: ['node_modules'], | ||
outputDir: 'hd-tracker', | ||
}; | ||
|
||
export default defaultConfig; |
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,13 @@ | ||
import { join } from "path"; | ||
import { existsSync, writeFileSync, mkdirSync } from "fs"; | ||
|
||
import defaultConfig from "./default-config"; | ||
|
||
export function initialize(rootDir: string): void { | ||
const output = JSON.stringify(defaultConfig, null, 2); | ||
const dir = join(rootDir, "hd-tracker"); | ||
if (!existsSync(dir)) { | ||
mkdirSync(dir); | ||
} | ||
writeFileSync(join(dir, "config.json"), output); | ||
} |
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,5 @@ | ||
import { TotalResult } from './total-result'; | ||
|
||
export interface AggregateResult extends TotalResult { | ||
fileType: string; | ||
} |
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,8 @@ | ||
import { AggregateResult } from './aggregate-result'; | ||
import { TotalResult } from './total-result'; | ||
|
||
export interface CategoryResult { | ||
name: string; | ||
totals: TotalResult; | ||
fileTypes: AggregateResult[]; | ||
} |
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,10 @@ | ||
export interface Category extends CategoryDefinition { | ||
name: string; | ||
} | ||
|
||
export interface CategoryDefinition { | ||
fileTypes: string[]; | ||
includes: string[]; | ||
excludes?: string[]; | ||
jsTsPairs?: 'js' | 'ts' | 'ignore'; | ||
} |
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,86 @@ | ||
export class ChartConfig { | ||
private _perCategoryAndFileType = false; | ||
private _perCategoryTotals = true; | ||
private _width = 1200; | ||
private _height = 800; | ||
private _bg = 'white'; | ||
private _title = 'Migration Progress LOC'; | ||
private _xAxisLabel = 'Date'; | ||
private _yAxisLabel = 'Totals'; | ||
private _overwrite = true; | ||
private _outFile = 'viz.png'; | ||
|
||
get perCategoryAndFileType(): boolean { | ||
// if false, use false; false !== undefined | ||
return this._cliOptions.perCategoryAndFileType !== undefined ? | ||
this._cliOptions.perCategoryAndFileType : | ||
this._perCategoryAndFileType; | ||
} | ||
|
||
get perCategoryTotals(): boolean { | ||
// if false, use false; false !== undefined | ||
return this._cliOptions.perCategoryTotals !== undefined ? | ||
this._cliOptions.perCategoryTotals: | ||
this._perCategoryTotals; | ||
} | ||
|
||
get width(): number { | ||
// if set and non-numeric | ||
if (this._cliOptions.width !== undefined && isNaN(Number(this._cliOptions.width))) { | ||
throw Error('--chart.width must be a number'); | ||
} | ||
// if unset or numeric | ||
return this._cliOptions.width !== undefined ? | ||
this._cliOptions.width: | ||
this._width; | ||
} | ||
|
||
get height(): number { | ||
// if set and non-numeric | ||
if (this._cliOptions.height !== undefined && isNaN(Number(this._cliOptions.height))) { | ||
throw Error('--chart.height must be a number'); | ||
} | ||
// if unset or numeric | ||
return this._cliOptions.height !== undefined ? | ||
this._cliOptions.height: | ||
this._height; | ||
} | ||
|
||
get bg(): string { | ||
return this._cliOptions.bg ? | ||
this._cliOptions.bg: | ||
this._bg; | ||
} | ||
|
||
get title(): string { | ||
return this._cliOptions.title ? | ||
this._cliOptions.title: | ||
this._title; | ||
} | ||
|
||
get xAxisLabel(): string { | ||
return this._cliOptions.xAxisLabel ? | ||
this._cliOptions.xAxisLabel: | ||
this._xAxisLabel; | ||
} | ||
|
||
get yAxisLabel(): string { | ||
return this._cliOptions.yAxisLabel ? | ||
this._cliOptions.yAxisLabel: | ||
this._yAxisLabel; | ||
} | ||
|
||
get overwrite(): boolean { | ||
return this._cliOptions.overwrite !== undefined ? | ||
this._cliOptions.overwrite: | ||
this._overwrite; | ||
} | ||
|
||
get outFile(): string { | ||
return this._cliOptions.outFile ? | ||
this._cliOptions.outFile: | ||
this._outFile; | ||
} | ||
|
||
constructor(private _cliOptions: ChartConfig = {} as ChartConfig) { } | ||
} |
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,7 @@ | ||
import { CategoryDefinition } from './category'; | ||
|
||
export interface Config { | ||
categories: { [key: string]: CategoryDefinition }; | ||
ignorePatterns?: string[]; | ||
outputDir: string; | ||
} |
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,6 @@ | ||
import { Result } from './result'; | ||
|
||
export interface FileResult extends Result { | ||
fileType: string; | ||
path: string; | ||
} |
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,7 @@ | ||
import { CategoryResult } from './category-result'; | ||
|
||
export interface ProcessResult { | ||
timestamp: string; | ||
hash: string; | ||
categories: CategoryResult[]; | ||
} |
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,11 @@ | ||
export interface Result { | ||
total: number; | ||
source: number; | ||
comment: number; | ||
single: number; | ||
block: number; | ||
mixed: number; | ||
empty: number; | ||
todo: number; | ||
blockEmpty: number; | ||
} |
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,5 @@ | ||
import { Result } from './result'; | ||
|
||
export interface TotalResult extends Result { | ||
fileCount: number; | ||
} |
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,4 @@ | ||
export type VizDataset = { | ||
label: string; | ||
data: number[]; | ||
}; |
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,6 @@ | ||
import { VizDataset } from './viz-dataset' | ||
|
||
export type VizLabelsDatasets = { | ||
labels: string[], | ||
datasets: VizDataset[], | ||
} |
Oops, something went wrong.