-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
fs
utility file and more readability touches
- Loading branch information
1 parent
f44a093
commit a7c2fe1
Showing
6 changed files
with
123 additions
and
111 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
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,70 @@ | ||
import fs from 'fs'; | ||
import { CSStemplate, JSXtemplate } from '../react-library/template.js'; | ||
import { extractComponentPaths } from './utils.js'; | ||
|
||
export const createComponentFileType = (name, type, data = '') => { | ||
if (type === 'index') { | ||
return fs.writeFileSync(name, data); | ||
} | ||
|
||
if (type.includes('module')) { | ||
return fs.writeFileSync(`${name}.${type}`, data); | ||
} | ||
|
||
if (type === 'jsx' || type === 'js') { | ||
return fs.writeFileSync(`${name}.${type}`, data); | ||
} | ||
|
||
return fs.writeFileSync(`${name}.${type}.js`, data); | ||
}; | ||
|
||
export function createFiles( | ||
name, | ||
filesToCreate, | ||
componentTemplate, | ||
nameConvention, | ||
filesPath = '', | ||
) { | ||
if (filesPath.includes('--')) { | ||
filesPath = ''; | ||
} | ||
|
||
const cmpPaths = extractComponentPaths(name, filesPath); | ||
|
||
for (let fileType of filesToCreate) { | ||
// TODO: Create generator class | ||
if (fileType === 'folder') { | ||
fs.mkdirSync(cmpPaths.folder); | ||
} | ||
|
||
if (fileType === 'index') { | ||
createComponentFileType(cmpPaths.index, fileType); | ||
} | ||
|
||
if (fileType === 'js' || fileType === 'controller') { | ||
createComponentFileType(cmpPaths.clean, fileType); | ||
} | ||
|
||
if (fileType === 'css' || fileType === 'scss') { | ||
const styleType = `module.${fileType}`; | ||
const template = CSStemplate(cmpPaths.cnWithCssSupport, fileType); | ||
|
||
createComponentFileType(cmpPaths.clean, styleType, template); | ||
} | ||
|
||
if (fileType === 'jsx') { | ||
const styleType = filesToCreate.includes('scss') ? 'scss' : 'css'; | ||
|
||
const template = JSXtemplate( | ||
cmpPaths.cnWithCssSupport, | ||
cmpPaths.cnNormalized, | ||
styleType, | ||
componentTemplate, | ||
); | ||
|
||
createComponentFileType(cmpPaths.clean, fileType, template); | ||
} | ||
} | ||
|
||
console.log(`Component '${cmpPaths.name}' generated at '${cmpPaths.folder}'`); | ||
} |
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
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