-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove and refactor q and q-io as dependencies
- Loading branch information
Showing
8 changed files
with
221 additions
and
201 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 |
---|---|---|
@@ -1,55 +1,49 @@ | ||
import { regexReplaceCustomBoilerplateString, readReplaceAndWriteFilesToNewDirAsync, genericLog } from '../utils/functions'; | ||
import { regexReplaceCustomBoilerplateString, genericLog } from '../utils/functions'; | ||
import { cwd } from '../utils/variables'; | ||
import Q from 'q'; | ||
import qfs from 'q-io/fs'; | ||
import fs from 'fs'; | ||
|
||
export default (finalPath, actionType, fileType, fileName) => { | ||
const fullFilePath = `${finalPath}/${fileType}`; | ||
|
||
return qfs.isDirectory(fullFilePath).then((isDirectory) => { | ||
if(isDirectory) { | ||
return qfs.makeDirectory(`${cwd}/${fileName}`) | ||
.then(() => qfs.listTree(fullFilePath)) | ||
.then((files) => { | ||
const deferred = Q.defer(); | ||
const subDirFiles = files.slice(1, files.length); | ||
const dirs = subDirFiles.filter((file) => fs.statSync(file).isDirectory()); | ||
|
||
Q.all(dirs.map((dir) => { | ||
const relativeContentDir = dir.split(fullFilePath)[1]; | ||
const editedRelativeContentDir = regexReplaceCustomBoilerplateString(relativeContentDir, fileName); | ||
return qfs.makeTree(`${cwd}/${fileName + editedRelativeContentDir}`); | ||
})) | ||
.then(() => deferred.resolve(files)) | ||
.catch((err) => { | ||
genericLog(`Error making Directories: >: \n ${err}`, 'red'); | ||
deferred.reject(files); | ||
}); | ||
|
||
return deferred.promise; | ||
}) | ||
.then((files) => { | ||
const subDirFiles = files.filter((file) => !fs.statSync(file).isDirectory()); | ||
return Q.all(subDirFiles.map((file) => { | ||
const relativeContentDir = file.split(fullFilePath)[1]; | ||
return readReplaceAndWriteFilesToNewDirAsync(fileName, file, `${cwd}/${fileName + relativeContentDir}`); | ||
})); | ||
}).catch((err) => { | ||
genericLog(`err: \n ${err}`, 'red'); | ||
}); | ||
} else { | ||
return qfs.read(fullFilePath) | ||
.then((content) => { | ||
const editedContent = regexReplaceCustomBoilerplateString(content, fileName); | ||
return qfs.write(`${cwd}/${fileName}`, editedContent); | ||
}) | ||
.then(() => { | ||
genericLog(`${fileName} created successfully`); | ||
}) | ||
.catch((err) => { | ||
genericLog(`err: \n ${err}`, 'red'); | ||
}); | ||
import fs from 'fs-extra'; | ||
import regexReplace from 'regex-replace'; | ||
|
||
export default async (finalPath, actionType, fileType, fileName) => { | ||
const fullBinFilePath = `${finalPath}/${fileType}`; | ||
|
||
const filePathStats = await fs.stat(fullBinFilePath); | ||
|
||
//handle Directories | ||
if(filePathStats.isDirectory()) { | ||
try { | ||
await fs.copy(fullBinFilePath, `${cwd}/${fileName}`); | ||
} catch (err) { | ||
console.error(`ERROR > error creating directory (${cwd}/${fileName})`, err); | ||
return 1; | ||
} | ||
|
||
try { | ||
await regexReplace('<:rikofilename:>', fileName, `${cwd}/${fileName}`); | ||
} catch (err) { | ||
console.error(`ERROR > error replacing custom filenames in (${cwd}/${fileName})`, err); | ||
return 1; | ||
} | ||
|
||
genericLog(`${fileName} created successfully`); | ||
|
||
} else { //handle files | ||
let customizedFile; | ||
try { | ||
customizedFile = await fs.readFile(fullBinFilePath, 'utf8'); | ||
} catch (err) { | ||
console.error(`ERROR > error reading file (${cwd}/${fileName})`, err); | ||
return 1; | ||
} | ||
|
||
const editedContent = regexReplaceCustomBoilerplateString(customizedFile, fileName); | ||
|
||
try { | ||
await fs.writeFile(`${cwd}/${fileName}`, editedContent); | ||
} catch (err) { | ||
console.error(`ERROR > error writing to file (${cwd}/${fileName})`, err); | ||
return 1; | ||
} | ||
}); | ||
|
||
genericLog(`${fileName} created successfully`); | ||
} | ||
}; |
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,65 +1,98 @@ | ||
import { genericLog, folderAlreadyPresent, sortObjByOwnKeys } from '../utils/functions'; | ||
import { cwd, baseDir, packageJson } from '../utils/variables'; | ||
import qfs from 'q-io/fs'; | ||
import fs from 'fs-extra'; | ||
import spawn from 'cross-spawn'; | ||
import gulpLoadPlugins from 'gulp-load-plugins'; | ||
|
||
const $ = gulpLoadPlugins(); | ||
const spawnSync = spawn.sync; | ||
|
||
export default (actionType, projectType, projectName) => { | ||
export default async (actionType, projectType, projectName) => { | ||
const logSuccess = () => genericLog(`${$.util.colors.blue(projectName)} was setup ${$.util.colors.green('successfully')}`); | ||
|
||
return qfs.list(cwd) | ||
.then(files => { | ||
if(folderAlreadyPresent(files, projectName)) { | ||
genericLog(`${$.util.colors.blue(projectName)} folder must not exist during setup. ${$.util.colors.red('terminating...')}`); | ||
throw new Error(`${projectName} folder must not exist during setup.`); | ||
} else { | ||
switch (projectType) { | ||
case 'electron': { | ||
qfs.copyTree(`${baseDir}/bin/_${actionType}/react`, `${cwd}/${projectName}`) | ||
.then(() => qfs.copyTree(`${baseDir}/bin/_${actionType}/${projectType}`, `${cwd}/${projectName}/src`)) | ||
.then(() => qfs.read(`${cwd}/${projectName}/package.json`)) | ||
.then((customPackageJson) => { | ||
//adds electron as devDependencies to package.json | ||
const packageJsonObj = JSON.parse(customPackageJson); | ||
packageJsonObj.devDependencies = Object.assign( | ||
{}, | ||
packageJsonObj.devDependencies, | ||
{electron: packageJson.dependencies.electron} | ||
); | ||
packageJsonObj.devDependencies = sortObjByOwnKeys(packageJsonObj.devDependencies); | ||
return packageJsonObj; | ||
}) | ||
.then((packageJsonObj) => qfs.write(`${cwd}/${projectName}/package.json`, JSON.stringify(packageJsonObj, null, "\t"))) | ||
.then(() => logSuccess()) | ||
.catch((err) => genericLog(err, 'red')); | ||
break; | ||
} | ||
case 'node-server': | ||
case 'react': { | ||
qfs.copyTree(`${baseDir}/bin/_${actionType}/${projectType}`, `${cwd}/${projectName}`) | ||
.then(() => logSuccess()) | ||
.catch((err) => genericLog(err, 'red')); | ||
break; | ||
} | ||
case 'react-native': { | ||
//run react native shell script | ||
spawnSync('sh', [`${baseDir}/bin/_${actionType}/${projectType}/react-native-install.sh`, projectName], {stdio: 'inherit'}); | ||
|
||
//copy rikoconfig.js file | ||
qfs.makeTree(`${cwd}/${projectName}/src`) | ||
.then(() => qfs.copy(`${baseDir}/bin/_${actionType}/${projectType}/rikoconfig.js`, `${cwd}/${projectName}/src/rikoconfig.js`)) | ||
.then(() => genericLog(`${$.util.colors.blue(`${projectName}`)} folder created ${$.util.colors.green('successfully')}`)) | ||
.catch((err) => genericLog(err, 'red')); | ||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
let userCWDfiles; | ||
|
||
try { | ||
userCWDfiles = await fs.readdir(cwd); | ||
} catch (err) { | ||
console.error(`ERROR > error reading cwd (${cwd})`, err); | ||
} | ||
|
||
if(folderAlreadyPresent(userCWDfiles, projectName)) { | ||
genericLog(`${$.util.colors.blue(projectName)} folder must not exist during setup. ${$.util.colors.red('terminating...')}`); | ||
throw new Error(`${projectName} folder must not exist during setup.`); | ||
} else { | ||
switch (projectType) { | ||
case 'electron': { | ||
try { | ||
await fs.copy(`${baseDir}/bin/_${actionType}/react`, `${cwd}/${projectName}`); | ||
await fs.copy(`${baseDir}/bin/_${actionType}/${projectType}`, `${cwd}/${projectName}/src`); | ||
} catch (err) { | ||
console.error(`ERROR > error copying files to new project (${projectName})`, err); | ||
} | ||
|
||
let customPackageJson; | ||
try { | ||
customPackageJson = await fs.readJson(`${cwd}/${projectName}/package.json`); | ||
} catch (err) { | ||
console.error('ERROR > error reading package.json', err); | ||
} | ||
|
||
//adds electron as devDependencies to package.json | ||
customPackageJson.devDependencies = Object.assign( | ||
{}, | ||
customPackageJson.devDependencies, | ||
{electron: packageJson.dependencies.electron} | ||
); | ||
|
||
customPackageJson.devDependencies = sortObjByOwnKeys(customPackageJson.devDependencies); | ||
|
||
try { | ||
const jsonFormattingOptions = { spaces: "\t" }; | ||
await fs.writeJson(`${cwd}/${projectName}/package.json`, customPackageJson, jsonFormattingOptions); | ||
} catch (err) { | ||
console.error('ERROR > error writing to package.json', err); | ||
} | ||
|
||
logSuccess(); | ||
|
||
break; | ||
} | ||
case 'node-server': | ||
case 'react': { | ||
try { | ||
await fs.copy(`${baseDir}/bin/_${actionType}/${projectType}`, `${cwd}/${projectName}`); | ||
} catch (err) { | ||
console.error(`ERROR > error copying files to new project (${projectName})`, err); | ||
} | ||
|
||
logSuccess(); | ||
break; | ||
} | ||
case 'react-native': { | ||
//run react native shell script | ||
spawnSync('sh', [`${baseDir}/bin/_${actionType}/${projectType}/react-native-install.sh`, projectName], {stdio: 'inherit'}); | ||
|
||
try { | ||
await fs.ensureDir(`${cwd}/${projectName}/src`); | ||
} catch (err) { | ||
console.error(`ERROR > error creating directory (${cwd}/${projectName}/src)`, err); | ||
} | ||
|
||
//copy bin rikoconfig.js file to user project src directory | ||
try { | ||
await fs.copy(`${baseDir}/bin/_${actionType}/${projectType}/rikoconfig.js`, `${cwd}/${projectName}/src/rikoconfig.js`); | ||
} catch (err) { | ||
console.error(`ERROR > error copying files to new project (${projectName})`, err); | ||
} | ||
|
||
genericLog(`${$.util.colors.blue(`${projectName}`)} folder created ${$.util.colors.green('successfully')}`); | ||
|
||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
}) | ||
.catch((err) => genericLog(err, 'red')); | ||
} | ||
} | ||
}; |
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
Oops, something went wrong.