🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

generate-react-cli

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-react-cli - npm Package Compare versions

Comparing version

to
1.7.1

4

package.json
{
"name": "generate-react-cli",
"version": "1.7.0",
"version": "1.7.1",
"description": "A simple React CLI to generate components instantly and more.",

@@ -26,3 +26,3 @@ "main": "src/index.js",

"chalk": "^2.4.2",
"commander": "^3.0.2",
"commander": "^4.0.0",
"deep-keys": "^0.5.0",

@@ -29,0 +29,0 @@ "esm": "^3.2.25",

import chalk from 'chalk';
import { camelCase } from 'lodash-es';
import { generateComponentTemplates } from '../services/templateService';

@@ -14,8 +15,26 @@ import componentJsTemplate from '../templates/components/componentJsTemplate';

const module = componentConfig.css.module ? '.module' : '';
let jsTemplate = componentJsTemplate;
// if test library is not Testing Library. Remove data-testid from jsTemplate
if (componentConfig.test.library !== 'Testing Library') {
jsTemplate = jsTemplate.replace(` data-testid="TemplateName"`, '');
}
// if the css module is true make sure to update the componentJsTemplate accordingly
if (module.length) {
jsTemplate = jsTemplate.replace(
`'./TemplateName.module.css'`,
`'./${componentName}${module}.${componentConfig.css.preprocessor}'`
);
} else {
jsTemplate = jsTemplate.replace(`{styles.TemplateName}`, `"${componentName}"`);
jsTemplate = jsTemplate.replace(
`styles from './TemplateName.module.css'`,
`'./${componentName}${module}.${componentConfig.css.preprocessor}'`
);
}
const componentTemplates = [
{
template: componentJsTemplate.replace(
'TemplateName.module.css',
`${componentName}${module}.${componentConfig.css.preprocessor}`
),
template: jsTemplate,
templateType: `Component "${componentName}.js"`,

@@ -47,3 +66,3 @@ componentPath: `${componentPathDir}/${componentName}.js`,

componentTemplates.push({
template: getTestingLibraryTemplate(componentConfig),
template: getTestingLibraryTemplate(componentName, componentConfig),
templateType: `Test "${componentName}.test.js"`,

@@ -78,3 +97,3 @@ componentPath: `${componentPathDir}/${componentName}.test.js`,

function getTestingLibraryTemplate(componentConfig) {
function getTestingLibraryTemplate(componentName, componentConfig) {
switch (componentConfig.test.library) {

@@ -84,3 +103,3 @@ case 'Enzyme':

case 'Testing Library':
return componentTestTestingLibraryTemplate;
return componentTestTestingLibraryTemplate.replace(/#|templateName/g, camelCase(componentName))
default:

@@ -87,0 +106,0 @@ return componentTestDefaultTemplate;

import { existsSync, outputFileSync } from 'fs-extra';
import chalk from 'chalk';
import { camelCase } from 'lodash-es';
import replace from 'replace';

@@ -27,8 +26,2 @@

replace({
...replaceDefaultOptions,
regex: 'templateName',
replacement: camelCase(componentName),
});
console.log(chalk.green(`${templateType} was created successfully at ${componentPath}`));

@@ -35,0 +28,0 @@ } catch (error) {