Skip to content

Commit

Permalink
feat(cli): add library name option
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Sep 14, 2021
1 parent d3040d0 commit 9bf1da2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tools/cli/src/commands/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Command, flags } from '@oclif/command';

import { prompt } from '../prompt';
import { createRepo } from '../builders/repo-builder';
import { writeFileSync } from 'fs-extra';
import { outputFileSync } from 'fs-extra';
import { dash } from '../utils';
import chalk from 'chalk';
import { cosmiconfigSync } from 'cosmiconfig';
import { DEFAULT_ID_KEY, GlobalConfig } from '../types';

import { resolve } from 'path';
import chalk from 'chalk';
export default class Repo extends Command {
static description = 'Create a repository';

Expand All @@ -24,13 +24,17 @@ export default class Repo extends Command {
const { flags } = this.parse(Repo);

const options = await prompt();
let mergedOptions = options;

const path = `${options.path}/${dash(options.storeName)}.repository.ts`;

const globalConfig: GlobalConfig | undefined =
cosmiconfigSync('elf').search()?.config;

let mergedOptions = options;
const path = resolve(
options.path,
globalConfig?.cli?.repoLibrary ?? '',
`${dash(options.storeName)}.repository.ts`
);

if (globalConfig) {
mergedOptions = {
...options,
Expand All @@ -56,7 +60,7 @@ export default class Repo extends Command {
return;
}

writeFileSync(path, repo);
outputFileSync(path, repo);
console.log('\n', chalk.greenBright(`CREATED`), `${path}\n`);
}
}
1 change: 1 addition & 0 deletions tools/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface GlobalConfig {
cli?: {
repoTemplate?: Options['template'];
idKey?: Options['idKey'];
repoLibrary?: string;
};
}

Expand Down

0 comments on commit 9bf1da2

Please sign in to comment.