Skip to content

Commit

Permalink
feat: add report log file
Browse files Browse the repository at this point in the history
  • Loading branch information
yosion-p committed Jul 14, 2021
1 parent 78e3226 commit 4a576bd
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 110 deletions.
106 changes: 46 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"yorkie": "^2.0.0"
},
"dependencies": {
"table": "^6.7.1",
"chalk": "^4.1.1",
"@originjs/vue-sfc-ast-parser": "^1.0.1",
"commander": "^7.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TransformationType } from './index'
import { stringifyDescriptor } from '@originjs/vue-sfc-ast-parser'
import { FileInfo, TransformationResult, VueSFCContext } from '../astParse';
import { parseVueSfc } from '../../utils/astUtils'
import { recordConver } from '../../utils/report'

export const astTransform:ASTTransformation = async (fileInfo: FileInfo) => {
const context: VueSFCContext = parseVueSfc(fileInfo)
Expand All @@ -19,6 +20,7 @@ export const astTransform:ASTTransformation = async (fileInfo: FileInfo) => {
content: stringifyDescriptor(context.descriptor),
type: TransformationType.removeHtmlLangInTemplateTransformation
}
recordConver({ num: 'O07', feat: 'remove lang="html"' })
return result
}

Expand Down
14 changes: 5 additions & 9 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { genePatches } from '../generate/genePatches'
import { Command } from 'commander'
import { Config } from '../config/config'
import { astParseRoot, AstParsingResult } from '../ast-parse/astParse'
import { reportOpt, printReport } from '../utils/report'
import { printReport, recordConver } from '../utils/report'

export function run (): void {
const program = new Command()
Expand All @@ -20,10 +20,10 @@ export function run (): void {
.option('-e --entry <type>', 'entrance of the entire build process, webpack or vite will start from ' +
'those entry files to build, if no entry file is specified, src/main.ts or src/main.js will be' +
'used as default')
.option('-r --report <boolean>', 'when n, the output conversion report is not output')
.option('-r --reportType <type>', "'log' will output a file of log")
.parse(process.argv)

const keys = ['rootDir', 'projectType', 'entry', 'report']
const keys = ['rootDir', 'projectType', 'entry', 'reportType']
const config: Config = {}
keys.forEach(function (k) {
if (Object.prototype.hasOwnProperty.call(program.opts(), k)) {
Expand All @@ -41,10 +41,6 @@ export async function start (config : Config): Promise<void> {
console.log(chalk.red(`Project path is not correct : ${config.rootDir}`))
return
}
if (config?.report === 'n') {
console.log(chalk.yellow('no report'));
reportOpt.noRepot = true
}
const cwd = process.cwd()
const rootDir = path.resolve(config.rootDir)

Expand All @@ -55,12 +51,12 @@ export async function start (config : Config): Promise<void> {

// generate index.html must be after generate vite.config.js
geneIndexHtml(rootDir, config, astParsingResult)
printReport() // output conversion
printReport(config.reportType, config.rootDir) // output conversion

// generate patches
const patchesDir = path.resolve(rootDir, 'patches')
genePatches(patchesDir)

recordConver({ num: 'B05', feat: 'required plugins' })
console.log(chalk.green('************************ Done ! ************************'))
const pkgManager = fs.existsSync(path.resolve(rootDir, 'yarn.lock'))
? 'yarn'
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface Config {
rootDir?: string;
projectType?: string;
entry?: any;
report?: string;
reportType?: string;
}

export interface DevServer {
Expand Down
2 changes: 2 additions & 0 deletions src/generate/geneIndexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isObject, stringFormat } from '../utils/common'
import { Config } from '../config/config'
import { AstParsingResult } from '../ast-parse/astParse'
import { TransformationType } from '../ast-parse/transformations'
import { recordConver } from '../utils/report'

export function geneIndexHtml (rootDir: string, config: Config, astParsingResult?: AstParsingResult): void {
const outputIndexPath: string = path.resolve(rootDir, 'index.html')
Expand All @@ -19,6 +20,7 @@ export function geneIndexHtml (rootDir: string, config: Config, astParsingResult

const injectedContent = generateWithVueCliPublicIndex(astParsingResult, entries, projectType)
writeSync(outputIndexPath, injectedContent)
recordConver({ num: 'B02', feat: 'add index.html' })
}

function generateEntriesHtml (entries: string[]): string {
Expand Down
2 changes: 2 additions & 0 deletions src/generate/genePackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import * as constants from '../constants/constants'
import { recordConver } from '../utils/report'

// TODO: compatible with vue2 and vue3
export function genePackageJson (packageJsonPath: string): void {
Expand Down Expand Up @@ -54,4 +55,5 @@ export function genePackageJson (packageJsonPath: string): void {
packageJson.scripts.postinstall = 'patch-package'

writeSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
recordConver({ num: 'B01', feat: 'add package.json' })
}
Loading

0 comments on commit 4a576bd

Please sign in to comment.