-
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 #20 from victorsoares96/v0.3.1
v0.3.1
- Loading branch information
Showing
24 changed files
with
559 additions
and
461 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
*.test.js | ||
*.test.ts | ||
dist | ||
bin |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../dist/cjs/index.js') | ||
require('../dist/cjs/cli.js') |
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,6 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base" | ||
] | ||
} |
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,37 @@ | ||
import { generateReport } from './generateReport'; | ||
import { generateResult } from './generateResult'; | ||
import { getArguments } from './getArguments'; | ||
import { getSettings } from './getSettings'; | ||
import { saveReport } from './saveReport'; | ||
|
||
(async () => { | ||
try { | ||
const args = getArguments(process.argv.slice(2)); | ||
|
||
const source = args['--source']; | ||
const configFile = args['--config-file']; | ||
|
||
const settings = await getSettings(configFile); | ||
|
||
const results = await generateResult( | ||
source, | ||
settings, | ||
// ! The parameter in this function has been changed to json if the user wants to have the output in xml or js(json) if he uses this function outside the cli | ||
settings.outputFormat === 'html' ? 'json' : 'xml' | ||
); | ||
|
||
let report: string; | ||
|
||
if (settings.outputFormat === 'html') { | ||
report = await generateReport(results, settings); | ||
await saveReport(settings.outputDir, report, settings.outputFormat); | ||
} | ||
|
||
if (settings.outputFormat === 'xml') { | ||
report = String(results); | ||
await saveReport(settings.outputDir, report, settings.outputFormat); | ||
} | ||
} catch (error: any) { | ||
throw new Error(error); | ||
} | ||
})(); |
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 |
---|---|---|
@@ -1,58 +1,42 @@ | ||
import gulp from 'gulp'; | ||
import gulpESLintNew from 'gulp-eslint-new'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import ora from 'ora'; | ||
import generateTemplate from './templates/template-generator'; | ||
import eslintConfig from './eslint_config'; | ||
import { Analyzer, ReporterSettings } from './types'; | ||
import path from 'path'; | ||
import _ from 'lodash'; | ||
|
||
import { renderSummaryTemplate } from './templates/summary.template'; | ||
|
||
import { ReporterSettings, Results } from './types'; | ||
import { renderResultsTemplate } from './templates/results.template'; | ||
|
||
const pageTemplate = _.template( | ||
fs.readFileSync(path.join(__dirname, 'templates', 'main-page.html'), 'utf-8') | ||
); | ||
|
||
const styles = _.template( | ||
fs.readFileSync(path.join(__dirname, 'helpers/styles.html'), 'utf-8') | ||
); | ||
|
||
const scripts = _.template( | ||
fs.readFileSync(path.join(__dirname, 'helpers/scripts.html'), 'utf-8') | ||
); | ||
|
||
export async function generateReport( | ||
files: string[], | ||
output: string, | ||
debug: boolean, | ||
analyzer: Analyzer, | ||
reporterSettings: ReporterSettings | ||
): Promise<NodeJS.ReadWriteStream> { | ||
let filesProcessed = 0; | ||
const totalFiles = files.length; | ||
|
||
const spinner = ora('Generating report').start(); | ||
return gulp | ||
.src(files) | ||
.pipe( | ||
gulpESLintNew({ | ||
useEslintrc: false, | ||
allowInlineConfig: false, | ||
baseConfig: { | ||
...eslintConfig, | ||
rules: { | ||
...eslintConfig.rules, | ||
'react-intl-universal/no-literal-string': ['error', analyzer], | ||
}, | ||
}, | ||
}) | ||
) | ||
.pipe( | ||
gulpESLintNew | ||
.format( | ||
(results) => generateTemplate(results, reporterSettings), | ||
(results) => { | ||
const reportName = `intl-report-${new Date().getTime()}.html`; | ||
if (!fs.existsSync(output)) fs.mkdirSync(output); | ||
fs.writeFileSync(path.join(output, reportName), results); | ||
spinner.succeed( | ||
`Generated report for ${totalFiles} files. See ${output}/${reportName}` | ||
); | ||
} | ||
) | ||
.on('data', (file) => { | ||
filesProcessed += 1; | ||
spinner.text = `Generating report (${filesProcessed}/${totalFiles})`; | ||
|
||
if (debug) { | ||
console.log(`\nFile processed: ${file.path}`); | ||
} | ||
}) | ||
); | ||
result: Results, | ||
config: ReporterSettings | ||
) { | ||
const { template } = config; | ||
|
||
const { internationalizedCount, notInternationalizedCount, results } = result; | ||
|
||
const currentDir = process.cwd() || ''; | ||
|
||
return pageTemplate({ | ||
title: template.title, | ||
reportSummary: renderSummaryTemplate( | ||
notInternationalizedCount, | ||
internationalizedCount | ||
), | ||
results: renderResultsTemplate(results, currentDir), | ||
styles: styles(), | ||
scripts: scripts(), | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,39 +1,5 @@ | ||
import _ from 'lodash'; | ||
import ora from 'ora'; | ||
import { findFiles } from './findFiles'; | ||
import { generateReport } from './generateReport'; | ||
import { getArguments } from './getArguments'; | ||
import { getSettings } from './getSettings'; | ||
import { generateResult } from './generateResult'; | ||
|
||
(async () => { | ||
const spinner = ora('Finding files').start(); | ||
try { | ||
const args = getArguments(process.argv.slice(2)); | ||
export * from './types'; | ||
|
||
const reporterSettings = await getSettings(args['--config-file']); | ||
|
||
const files = await findFiles( | ||
args['--source'], | ||
reporterSettings.ignorePatterns, | ||
reporterSettings.extensions, | ||
reporterSettings.debug | ||
); | ||
spinner.succeed(`Found ${files.length} files`); | ||
|
||
if (_.isEmpty(files)) { | ||
spinner.fail('No files found!'); | ||
process.exit(0); | ||
} | ||
|
||
generateReport( | ||
files, | ||
reporterSettings.outputDir, | ||
reporterSettings.debug, | ||
reporterSettings.analyzer, | ||
reporterSettings | ||
); | ||
} catch (error: any) { | ||
spinner.stop(); | ||
throw new Error(error); | ||
} | ||
})(); | ||
export { generateResult }; |
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.