mirror of
https://github.com/mirego/accent.git
synced 2024-09-11 10:55:28 +03:00
Fix cli --config flag
This commit is contained in:
parent
4dade7089d
commit
38d8f2b32f
@ -3,6 +3,7 @@ import Command from '@oclif/command';
|
||||
import {error} from '@oclif/errors';
|
||||
import * as chalk from 'chalk';
|
||||
import cli from 'cli-ux';
|
||||
import {flags} from '@oclif/command';
|
||||
|
||||
// Services
|
||||
import ConfigFetcher from './services/config';
|
||||
@ -14,18 +15,26 @@ import {Project, ProjectViewer} from './types/project';
|
||||
const sleep = async (ms: number) =>
|
||||
new Promise((resolve: (value: unknown) => void) => setTimeout(resolve, ms));
|
||||
|
||||
export default abstract class extends Command {
|
||||
export default class Base extends Command {
|
||||
static flags = {
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
projectConfig!: ConfigFetcher;
|
||||
project?: Project;
|
||||
viewer?: ProjectViewer;
|
||||
|
||||
async initialize(configFilePath: string) {
|
||||
this.projectConfig = new ConfigFetcher(configFilePath);
|
||||
async init() {
|
||||
const {flags} = this.parse(Base);
|
||||
this.projectConfig = new ConfigFetcher(flags.config);
|
||||
|
||||
const config = this.projectConfig.config;
|
||||
|
||||
// Fetch project from the GraphQL API.
|
||||
cli.action.start(chalk.white('Fetch config'));
|
||||
cli.action.start(chalk.white(`Fetch config in ${flags.config}`));
|
||||
await sleep(1000);
|
||||
|
||||
const fetcher = new ProjectFetcher();
|
||||
|
@ -33,15 +33,10 @@ export default class Export extends Command {
|
||||
default: '',
|
||||
description: 'Fetch a specific version',
|
||||
}),
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
async run() {
|
||||
const {flags} = this.parse(Export);
|
||||
super.initialize(flags.config);
|
||||
const documents = this.projectConfig.files();
|
||||
const formatter = new DocumentExportFormatter();
|
||||
|
||||
@ -62,6 +57,8 @@ export default class Export extends Command {
|
||||
await document.export(localFile, language, documentPath, flags);
|
||||
}
|
||||
|
||||
formatter.done();
|
||||
|
||||
await new HookRunner(document).run(Hooks.afterExport);
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,10 @@ export default class Format extends Command {
|
||||
description: 'Order of the keys',
|
||||
options: ['index', 'key', '-index', '-key'],
|
||||
}),
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
async run() {
|
||||
const {flags} = this.parse(Format);
|
||||
super.initialize(flags.config);
|
||||
const documents = this.projectConfig.files();
|
||||
const t0 = process.hrtime();
|
||||
const formattedPaths: FormattedFile[] = [];
|
||||
|
@ -1,6 +1,5 @@
|
||||
// Command
|
||||
import Command from '../base';
|
||||
import {flags} from '@oclif/command';
|
||||
|
||||
// Formatters
|
||||
import ExportFormatter from '../services/formatters/project-export';
|
||||
@ -26,17 +25,9 @@ export default class Jipt extends Command {
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
static flags = {
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
async run() {
|
||||
const {args} = this.parse(Jipt);
|
||||
const {flags} = this.parse(Jipt);
|
||||
super.initialize(flags.config);
|
||||
const documents = this.projectConfig.files();
|
||||
const formatter = new DocumentExportFormatter();
|
||||
|
||||
|
@ -5,7 +5,6 @@ import Command from '../base';
|
||||
import DocumentPathsFetcher from '../services/document-paths-fetcher';
|
||||
import Formatter from '../services/formatters/project-lint';
|
||||
import {LintTranslation} from '../types/lint-translation';
|
||||
import {flags} from '@oclif/command';
|
||||
|
||||
export default class Lint extends Command {
|
||||
static description =
|
||||
@ -13,16 +12,7 @@ export default class Lint extends Command {
|
||||
|
||||
static examples = [`$ accent lint`];
|
||||
|
||||
static flags = {
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
async run() {
|
||||
const {flags} = this.parse(Lint);
|
||||
super.initialize(flags.config);
|
||||
const documents = this.projectConfig.files();
|
||||
const results: LintTranslation[] = [];
|
||||
const t0 = process.hrtime();
|
||||
|
@ -1,6 +1,5 @@
|
||||
// Command
|
||||
import Command from '../base';
|
||||
import {flags} from '@oclif/command';
|
||||
|
||||
// Services
|
||||
import Formatter from '../services/formatters/project-stats';
|
||||
@ -10,17 +9,8 @@ export default class Stats extends Command {
|
||||
|
||||
static examples = [`$ accent stats`];
|
||||
|
||||
static flags = {
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
async run() {
|
||||
const {flags} = this.parse(Stats);
|
||||
super.initialize(flags.config);
|
||||
const formatter = new Formatter(this.project!, this.projectConfig.config);
|
||||
|
||||
formatter.log();
|
||||
|
@ -66,16 +66,10 @@ export default class Sync extends Command {
|
||||
description:
|
||||
'Sync a specific version, the tag needs to exists in Accent first',
|
||||
}),
|
||||
config: flags.string({
|
||||
default: 'accent.json',
|
||||
description: 'Path to the config file',
|
||||
}),
|
||||
};
|
||||
|
||||
async run() {
|
||||
const t0 = process.hrtime();
|
||||
const {flags} = this.parse(Sync);
|
||||
super.initialize(flags.config);
|
||||
const documents = this.projectConfig.files();
|
||||
|
||||
// From all the documentConfigs, do the sync or peek operations and log the results.
|
||||
|
@ -15,8 +15,7 @@ export default class ConfigFetcher {
|
||||
readonly warnings: string[];
|
||||
|
||||
constructor(configFilePath: string) {
|
||||
console.log(`Loading configuration file: ${configFilePath}`);
|
||||
this.config = fs.readJsonSync(`${configFilePath}`);
|
||||
this.config = fs.readJsonSync(configFilePath);
|
||||
this.config.apiKey = process.env.ACCENT_API_KEY || this.config.apiKey;
|
||||
this.config.apiUrl = process.env.ACCENT_API_URL || this.config.apiUrl;
|
||||
this.config.project = process.env.ACCENT_PROJECT || this.config.project;
|
||||
|
@ -10,4 +10,7 @@ export default class DocumentExportFormatter {
|
||||
chalk.gray.dim.underline(path)
|
||||
);
|
||||
}
|
||||
done() {
|
||||
console.log('');
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,6 @@ import * as chalk from 'chalk';
|
||||
|
||||
export default class ProjectExportFormatter {
|
||||
log() {
|
||||
const title = 'Writing files locally';
|
||||
|
||||
console.log('');
|
||||
console.log(chalk.magenta(title));
|
||||
console.log(chalk.magenta('Writing files locally'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user