Skip to content

Commit 9b8f1fc

Browse files
committed
Minor fixes
1 parent 86607b5 commit 9b8f1fc

6 files changed

Lines changed: 36 additions & 12 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "react-codegen-cli",
33
"version": "0.1.6",
44
"description": "Software Development Kit for React",
5-
"main": "lib/bin.js",
5+
"main": "lib/index.js",
66
"bin": {
7-
"react-codegen": "lib/index.js"
7+
"react-codegen": "lib/bin.js"
88
},
99
"scripts": {
1010
"prepublish": "babel src --out-dir lib --copy-files",

src/constants/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import path from 'path';
22

33
import { getAppRoot, getConfig } from '../utils';
4+
import { getStylesExtension } from '../utils/getStylesExtension';
45

6+
export const STYLE_FORMATS = ['CSS', 'SCSS', 'SASS', 'Less', 'Stylus'];
57
export const APP_ROOT = getAppRoot();
68
export const ROOT = path.dirname(require.main.filename);
79
export const CONFIG = getConfig();
810
export const EXT = {
911
component: CONFIG.typescript ? 'tsx' : `j${CONFIG.jsxExt ? 'sx' : 's'}`,
1012
script: `${CONFIG.typescript ? 't' : 'j'}s`,
11-
style: CONFIG.styles,
13+
style: getStylesExtension(CONFIG.styles),
1214
};

src/init/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@ export async function init() {
2020
const answers = await inquirer.prompt(question);
2121

2222
const config = {
23-
styles: answers.styles,
23+
styles: answers.styles.toLowerCase(),
2424
typescript: answers.typescript,
2525
jsxExt: answers.jsxExt,
2626
fileNameCase: answers.fileNameCase,
2727
path: answers.path,
2828
};
2929

3030
const content = JSON.stringify(config, null, 2);
31-
const filePath = path.resolve(APP_ROOT, 'react-codegen.json');
31+
const filePath = path.resolve(APP_ROOT, '.react-codegenrc.json');
3232

3333
fs.writeFileSync(filePath, content, 'utf-8');
3434

3535
if (answers.script) {
3636
await updatePackage(answers.scriptName);
37-
}
3837

39-
Logger.log(
40-
chalk => `
38+
Logger.log(
39+
chalk => `
4140
Now you can run the following command
42-
To run GraphQL Code Generator.
41+
to run React CodeGen.
4342
4443
${chalk.cyan(`npm run ${answers.scriptName}`)}
4544
`
46-
);
45+
);
46+
}
4747
}

src/init/questions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { STYLE_FORMATS } from '../constants';
12
import { getNameCases } from '../utils';
23

34
const nameCases = getNameCases('my component');
@@ -14,7 +15,7 @@ export const question = [
1415
type: 'list',
1516
name: 'styles',
1617
message: 'Which stylesheet format would you like to use?',
17-
choices: ['CSS', 'SCSS', 'SASS', 'Less', 'Stylus'],
18+
choices: STYLE_FORMATS,
1819
},
1920
{
2021
type: 'confirm',

src/utils/getConfig.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import path from 'path';
22
import { cosmiconfigSync } from 'cosmiconfig';
33

44
import defaultConfig from '../config/default.json';
5-
import { APP_ROOT } from '../constants';
5+
import { APP_ROOT, STYLE_FORMATS } from '../constants';
6+
import { Logger } from '../core/Logger';
67

78
export function getConfig() {
89
let config = defaultConfig;
@@ -11,6 +12,18 @@ export function getConfig() {
1112
const { config: userConfig } = explorer.search(APP_ROOT) || {};
1213

1314
if (userConfig) {
15+
if (userConfig.styles) {
16+
userConfig.styles = userConfig.styles.toLowerCase();
17+
const formats = STYLE_FORMATS.map(v => v.toLowerCase());
18+
const isSupported = formats.includes(userConfig.styles);
19+
20+
if (!isSupported) {
21+
Logger.warn(`Unknown stylesheet format - ${userConfig.styles}`);
22+
Logger.warn(`Using default - css`);
23+
userConfig.styles = 'css';
24+
}
25+
}
26+
1427
config = Object.assign(config, userConfig);
1528
}
1629

src/utils/getStylesExtension.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function getStylesExtension(type) {
2+
switch (type) {
3+
case 'stylus':
4+
return 'styl';
5+
default:
6+
return type.toLowerCase();
7+
}
8+
}

0 commit comments

Comments
 (0)