forked from saas-js/saas-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.hygen.js
75 lines (69 loc) · 2.21 KB
/
.hygen.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const inflection = require('inflection')
const path = require('path')
// Todo read this from the main package.json or git?
const config = {
author: 'Eelco Wiersma <eelco@appulse.nl>',
org: 'saas-ui',
packagesDir: 'packages',
appsDir: 'apps',
}
const packageName = (org, name, separator = '/') => {
if (org === '') org = config.org
return `${inflection.dasherize(org)}${separator}${inflection.dasherize(name)}`
}
const camelizePath = (name, lower = true) =>
inflection.camelize(name, lower).replace(/::/g, '/')
const pluralizeProp = (name) => inflection.pluralize(name)
const camelizeQuery = (name, lower = false) =>
inflection.camelize(name, lower).replace(/::/g, '/')
const pluralizeQuery = (name) => inflection.pluralize(name)
module.exports = {
templates: `${__dirname}/templates`,
helpers: {
config: (key) => config[key],
camelizedPathName: (name, lower = true) => camelizePath(name, lower),
camelizedBaseName: (name, lower = false) =>
path.parse(camelizePath(name, lower)).base,
baseName: (name) => path.parse(name).base,
dirName: (name) => path.parse(name).dir,
pluralizePageProp: (name) => pluralizeProp(name),
camelizedQueryHook: (name, plural) => {
const query = plural ? pluralizeQuery(name) : name
const camelizedQuery = camelizeQuery(query)
return `use${camelizedQuery}Query`
},
/**
* Normalize the filename casing. Defaults to kebabcase.
* @param {string} name
* @returns
*/
filename: (name) => {
return inflection.dasherize(name)
},
/**
* Returns the package directory, eg: packages/saas-ui-component
* @param {string} org
* @param {string} name
* @returns
*/
packageDir: (org, name) => {
return path.join(config.packagesDir, packageName(org, name, '-'))
},
/**
* Returns the package name, eg: @saas-ui/component
* @param {string} org
* @param {string} name
* @returns
*/
packageName: (org, name) => `@${packageName(org, name)}`,
/**
* Returns the relative app directory, eg: apps/website
* @param {string} org
* @param {string} name
* @returns
*/
appDir: (app) => {
return path.join(config.appsDir, app)
},
},
}