-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDPA-2718] Update docs / new-component / package-dependencies script…
…s. (#412) * [SDPA-2718] Update generate-readme to work with storybook 5. * [SDPA-2718] Update package-dependencies script. * [SDPA-2718] Update new-package script. * [SDPA-2718] Fixes to new-component script.
- Loading branch information
1 parent
bd2d599
commit 882496d
Showing
17 changed files
with
221 additions
and
152 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
File renamed without changes.
File renamed without changes.
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,91 @@ | ||
/** | ||
* Generates a Package and folder for a new component, based off the default | ||
* templates. | ||
*/ | ||
|
||
let Twig = require('twig') | ||
let fs = require('fs') | ||
let path = require('path') | ||
const packageManager = 'yarn' | ||
const componentDirectory = '../packages/components' | ||
|
||
if (process.argv.length < 5) { | ||
console.error(`Missing arguments: ${packageManager} run new-component:storybook "[Component name]" "[Component description]" "[Atoms / Molecules / Organisms]"`) | ||
console.log(`e.g. ${packageManager} run new-component:storybook "My Component" "A component to..." "Organisms"`) | ||
return true | ||
} | ||
|
||
let pkg = fs.readFileSync('./package.json', 'utf-8') | ||
|
||
// Arguments | ||
let componentName = process.argv.length > 2 ? process.argv[2] : 'My Component' | ||
let description = process.argv.length > 3 ? process.argv[3] : 'A component for...' | ||
let atom = process.argv.length > 4 ? process.argv[4] : 'Organisms' | ||
let version = JSON.parse(pkg).version | ||
|
||
// Helper functions | ||
function getSnakeCase (val) { | ||
return val.toLowerCase().replace(/\s/gi, '-') | ||
} | ||
|
||
function getTitleCase (val) { | ||
const arr = val.split(' ') | ||
for (let i = 0; i < arr.length; i++) { | ||
let word = arr[i] | ||
arr[i] = word[0].toUpperCase() + word.substr(1).toLowerCase() | ||
} | ||
return arr.join(' ') | ||
} | ||
|
||
function getTitleCaseNoSpace (val) { | ||
return getTitleCase(val).replace(/\s/gi, '') | ||
} | ||
|
||
function getCamelCase (val) { | ||
const word = getTitleCaseNoSpace(val) | ||
return (word[0].toLowerCase() + word.substr(1)) | ||
} | ||
|
||
// Get Names | ||
let data = { | ||
componentNaturalName: getTitleCase(componentName), | ||
componentSpacelessName: getTitleCaseNoSpace(componentName), | ||
componentFileName: getTitleCaseNoSpace(componentName), | ||
componentDemoDataName: getCamelCase(componentName), | ||
componentRippleName: 'Rpl' + getTitleCaseNoSpace(componentName), | ||
componentClassName: 'rpl-' + getSnakeCase(componentName), | ||
componentPackageName: 'ripple-' + getSnakeCase(componentName), | ||
componentRippleExportName: '{ ' + 'Rpl' + getTitleCaseNoSpace(componentName) + ' }', | ||
componentDescription: description, | ||
componentAtomFolder: getTitleCaseNoSpace(atom), | ||
componentVersion: version | ||
} | ||
const directory = componentDirectory + '/' + data.componentAtomFolder + '/' + data.componentSpacelessName + '/' | ||
const files = [ | ||
{ template: '.npmignore', output: '.npmignore' }, | ||
{ template: 'component_template.vue', output: data.componentSpacelessName + '.vue' }, | ||
{ template: 'index_template.js', output: 'index.js' }, | ||
{ template: 'LICENSE', output: 'LICENSE' }, | ||
{ template: 'package_template.json', output: 'package.json' }, | ||
{ template: 'stories_template.js', output: 'stories.js' } | ||
] | ||
|
||
// Make folder | ||
if (!fs.existsSync(directory)) { | ||
fs.mkdirSync(directory) | ||
} | ||
// Create all files | ||
files.forEach((item) => { | ||
Twig.renderFile(path.join(__dirname, item.template), data, (err, twigOutput) => { | ||
if (err) { | ||
console.log(err) | ||
} else { | ||
fs.writeFileSync(directory + item.output, twigOutput) | ||
} | ||
}) | ||
}) | ||
|
||
console.log(`Created "${getTitleCase(componentName)}"`) | ||
console.log(`\nTo complete setup, run:`) | ||
console.log(`- ${packageManager} run package-dependencies:storybook`) | ||
console.log(`- ${packageManager} run docs:storybook`) |
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,4 @@ | ||
import {{componentRippleName}} from './{{componentFileName}}.vue' | ||
|
||
export {{componentRippleExportName}} | ||
export default {{componentRippleName}} |
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,15 @@ | ||
{ | ||
"name": "@dpc-sdp/{{componentPackageName}}", | ||
"version": "{{componentVersion}}", | ||
"description": "{{componentDescription}}", | ||
"license": "Apache-2.0", | ||
"main": "index.js", | ||
"homepage": "https://ripple.sdp.vic.gov.au", | ||
"repository": "https://github.com/dpc-sdp/ripple/tree/master/packages/components/{{componentAtomFolder}}/{{componentSpacelessName}}", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@dpc-sdp/ripple-global": "{{componentVersion}}" | ||
} | ||
} |
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,15 @@ | ||
import { storiesOf } from '@storybook/vue' | ||
|
||
import { | ||
withKnobs | ||
} from '@storybook/addon-knobs/vue' | ||
|
||
import {{componentRippleName}} from './{{componentFileName}}.vue' | ||
|
||
storiesOf('{{componentAtomFolder}}/{{componentSpacelessName}}', module) | ||
.addDecorator(withKnobs) | ||
.add('{{componentNaturalName}}', () => ({ | ||
components: { {{componentRippleName}} }, | ||
template: `<{{componentClassName}} />`, | ||
props: {} | ||
})) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.