Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Allow scaffolding when page type doesn't already exist'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Pittman committed Feb 21, 2020
1 parent 5b16cc2 commit cf37238
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/gridtastic-scaffold.ts
Expand Up @@ -6,12 +6,10 @@ import pascalcase from 'pascalcase';
import isGridsomeProject from './isGridsomeProject';
import arg from 'arg';

// Scaffold --TYPE --name NAME Scaffold out a new file
// --template, -t /templates
// --page, -p /pages
// --component, -c /components
// --layout, -l /layouts
// --name, -n SomeFilename Filename to be used (will be pascal cased by CLI)
async function touchDir(dirPath: string): Promise<void> {
let fsPromises = fs.promises;
await fsPromises.mkdir(dirPath);
}

export default async (argv: string[]): Promise<void> => {
const args = arg({
Expand Down Expand Up @@ -76,10 +74,11 @@ export default async (argv: string[]): Promise<void> => {
let filename: string = pascalcase(name);
let pascalType: string = pascalcase(type);

if (fs.existsSync(`./src/${type}s/${filename}.vue`)) {
if (fs.existsSync(`${pkgRoot}/${type}s/${filename}.vue`)) {
log(chalk.red(`${filename}.vue already exists!`));
process.exit(126);
} else {
fs.existsSync(`./src/${type}s`) || touchDir(`./src/${type}s`);
fs.copyFileSync(`${pkgRoot}/templates/${pascalType}.vue`, `./src/${type}s/${filename}.vue`);
log(chalk.green(`src/${type}s/${filename}.vue`));
}
Expand Down

0 comments on commit cf37238

Please sign in to comment.