forked from layerframe/scaffolding-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scaffold-page-component.js
executable file
·38 lines (33 loc) · 1.09 KB
/
scaffold-page-component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @file bin/scaffold-page-component.js
* Handles scaffolding a page component.
*/
const path = require('path')
const minimist = require('minimist')
const scaffoldComponent = require('./scaffolding/scaffold-component')
const constants = require('./constants')
const PACKAGE_PATH = constants.getPackagePath()
const SOURCE_DIR = constants.dirs().src
const createClassName = (name) => {
// Force uppercase to build the className
const cleanName = `${name[0].toUpperCase()}${name.slice(1, name.length)}`
// transforms PascalCase into slug-case for the CSS class name
return cleanName
.replace(/[A-Z]/g, (word) => '-' + word.toLowerCase())
.substring(1) // trim off leading - from the first capital
}
module.exports = (function () {
const argv = minimist(process.argv.slice(2))
const destPath = argv.path || argv.name
return scaffoldComponent({
name: argv.name,
src: path.resolve(__dirname, 'scaffolding/page-component'),
path: destPath,
dest: path.resolve(
PACKAGE_PATH,
SOURCE_DIR,
'pages',
createClassName(argv.name).toLowerCase()
),
})
})()