-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src dir and class generation with subdirs
- Loading branch information
Showing
5 changed files
with
36 additions
and
12 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
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 |
---|---|---|
@@ -1,27 +1,33 @@ | ||
const fs = require('fs').promises; | ||
const colors = require('colors'); | ||
const Quote = require('inspirational-quotes'); | ||
const utils = require('../../utils'); | ||
const cli = require('../cli'); | ||
|
||
module.exports = async (stubName, argArray, filePath) => { | ||
const rawStub = await fs.readFile(`${__dirname}/${stubName}.stub`, 'utf-8'); | ||
|
||
const finalPath = `src/${filePath}`; | ||
|
||
let computedStub = rawStub; | ||
argArray.forEach(([key, value]) => { | ||
const regexp = new RegExp(`__${key}__`, 'g'); | ||
computedStub = computedStub.replace(regexp, value); | ||
}); | ||
|
||
computedStub = computedStub.replace('__QUOTE__', Quote.getRandomQuote()); | ||
computedStub = computedStub | ||
.replace('__QUOTE__', Quote.getRandomQuote()) | ||
.replace('__ROOTPATH__', utils.calculateRootPath(finalPath)); | ||
|
||
try { | ||
if(/\//.test(filePath)) { | ||
const splitPath = filePath.split('/'); | ||
// splitPath | ||
const directory = filePath.split('/') | ||
} | ||
await fs.writeFile(`./${filePath}`, computedStub, 'utf-8'); | ||
const splitPath = finalPath.split('/'); | ||
splitPath.pop(); | ||
|
||
const directory = splitPath.join('/'); | ||
await utils.createDirsRecursive(directory); | ||
await fs.writeFile(`${finalPath}`, computedStub, 'utf-8'); | ||
} catch (error) { | ||
console.log(error); | ||
console.log(colors.red(`Did you run ${colors.bold.white('uts init')}?`)); | ||
cli.error(`Did you run ${colors.bold.white('uts init')}?`); | ||
} | ||
}; |
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