-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#126): add tool to generate stories
- Loading branch information
1 parent
5a28e62
commit 3ba6932
Showing
7 changed files
with
769 additions
and
20 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,12 @@ | ||
import React from 'react'; | ||
import { ComponentMeta } from '@storybook/react'; | ||
|
||
import { {{ properCase ( getName path ) }} } from '@/{{ getFolder path }}'; | ||
|
||
export default { | ||
title: '{{ directoryCase ( getFolder path ) }}', | ||
} as ComponentMeta<typeof {{ properCase ( getName path ) }}>; | ||
|
||
export const Default = () => ( | ||
<{{ properCase ( getName path ) }} /> | ||
) |
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,19 @@ | ||
module.exports = { | ||
description: 'Component Story Generator', | ||
prompts: [ | ||
{ | ||
type: 'fuzzypath', | ||
message: 'Component name for story', | ||
name: 'path', | ||
rootPath: 'src', | ||
itemType: 'file', | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: 'add', | ||
path: 'src/{{getFolder path}}/docs.stories.tsx', | ||
templateFile: 'generators/docs.stories.tsx.hbs', | ||
}, | ||
], | ||
}; |
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,43 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const inquirerFuzzyPath = require('inquirer-fuzzy-path'); | ||
const storyGenerator = require('./generators/story'); | ||
|
||
module.exports = function (plop) { | ||
plop.setGenerator('stories', storyGenerator); | ||
|
||
//#region //*=========== Handlebars Helper =========== | ||
/** | ||
* Generate story component route | ||
* @see https://stackoverflow.com/questions/41490076/capitalize-every-letter-after-and-characters | ||
*/ | ||
plop.setHelper('directoryCase', function (title) { | ||
return title.replace(/(^|\/|-)(\S)/g, (s) => s.toUpperCase()); | ||
}); | ||
|
||
/** | ||
* Remove 'src', and file name from path | ||
*/ | ||
plop.setHelper('getFolder', (path) => { | ||
const split = path.split('/'); | ||
// remove filename | ||
split.pop(); | ||
if (split[0] === 'src') split.splice(0, 1); | ||
return split.join('/'); | ||
}); | ||
|
||
/** | ||
* Remove file name from path and get the parent folder name | ||
*/ | ||
plop.setHelper('getName', (path) => { | ||
const split = path.split('/'); | ||
// remove filename | ||
split.pop(); | ||
// get the parent folder name | ||
return split.pop(); | ||
}); | ||
//#endregion //*======== Handlebars Helper =========== | ||
|
||
//#region //*=========== Inquirer Prompt =========== | ||
plop.setPrompt('fuzzypath', inquirerFuzzyPath); | ||
//#endregion //*======== Inquirer Prompt =========== | ||
}; |
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.