Skip to content

Commit 8b38e46

Browse files
committed
feat: add-category command
1 parent b9add85 commit 8b38e46

22 files changed

Lines changed: 768 additions & 2 deletions

File tree

lib/actions/add-category/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const c = require('ansi-colors')
2+
const Blueprint = require('../blueprint')
3+
const validator = require('../util/validators')
4+
const ask = require('../util/ask')
5+
const _ = require('lodash')
6+
7+
async function addCategory (options) {
8+
const blueprint = Blueprint.load(options)
9+
if (!blueprint) return
10+
11+
const categoryName = await ask({
12+
message: 'Category name',
13+
validate: validator.notEmptyNoSpaces()
14+
})
15+
console.log()
16+
const label = await ask({
17+
message: 'Label',
18+
initial: _.upperFirst(_.lowerCase(categoryName)),
19+
validate: validator.notEmpty()
20+
})
21+
const description = await ask({
22+
message: 'Description',
23+
initial: _.upperFirst(_.lowerCase(categoryName))
24+
})
25+
26+
const scaffold = blueprint.scaffold
27+
scaffold.makeCategory({
28+
name: categoryName,
29+
label: label,
30+
description: description
31+
})
32+
console.log(c.bold(`\nCreating category ${c.cyan(categoryName)}`))
33+
await scaffold.commit()
34+
}
35+
36+
module.exports = addCategory

lib/actions/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ module.exports = {
33
newBlueprintAction: require('./new-blueprint'),
44
addModelAction: require('./add-model'),
55
addEditableAction: require('./add-editable'),
6-
addStateMachine: require('./add-state-machine')
6+
addStateMachine: require('./add-state-machine'),
7+
addCategory: require('./add-category')
78
}

lib/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ function tymlyCli (argv) {
4343
actions.addEditableAction(options)
4444
})
4545

46+
program
47+
.command('add-category')
48+
.description('Generate category')
49+
.option('-p, --path <path>', 'blueprint directory - defaults to "."')
50+
.action((options) => {
51+
actions.addCategory(options)
52+
})
53+
4654
program
4755
.command('add-state-machine')
4856
.description('Generate a new state machine')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"tymly": "bin/tymly-cli.js"
2424
},
2525
"dependencies": {
26-
"@wmfs/tymly-scaffold": "1.8.1",
26+
"@wmfs/tymly-scaffold": "1.9.0",
2727
"ansi-colors": "3.2.3",
2828
"commander": "2.19.0",
2929
"enquirer": "2.3.0",

test/add-category-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-env mocha */
2+
3+
const helpers = require('./test-helpers')
4+
5+
const addCategory = require('../lib/actions').addCategory
6+
7+
describe('tymly add-category', () => {
8+
const tests = {
9+
'add-category': [
10+
'pizza',
11+
'',
12+
''
13+
]
14+
}
15+
16+
const suiteName = 'add-category'
17+
18+
before(() => {
19+
helpers.prepareFixture(suiteName)
20+
})
21+
22+
for (const [name, inputs] of Object.entries(tests)) {
23+
helpers.runTest(
24+
suiteName,
25+
name,
26+
inputs,
27+
addCategory,
28+
{ }
29+
)
30+
}
31+
})
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
# it's better to unpack these files and commit the raw source
13+
# git has its own built in compression methods
14+
*.7z
15+
*.dmg
16+
*.gz
17+
*.iso
18+
*.jar
19+
*.rar
20+
*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
27+
*.sqlite
28+
29+
## Node ###
30+
~*
31+
.~*
32+
\#*
33+
34+
# Logs
35+
logs
36+
*.log
37+
npm-debug.log*
38+
39+
# Runtime data
40+
pids
41+
*.pid
42+
*.seed
43+
*.pid.lock
44+
45+
# Directory for instrumented libs generated by jscoverage/JSCover
46+
lib-cov
47+
48+
# Coverage directory used by tools like istanbul
49+
coverage
50+
51+
# nyc test coverage
52+
.nyc_output
53+
54+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
55+
.grunt
56+
57+
# node-waf configuration
58+
.lock-wscript
59+
60+
# Compiled binary addons (http://nodejs.org/api/addons.html)
61+
build/Release
62+
63+
# Dependency directories
64+
node_modules
65+
jspm_packages
66+
67+
# Optional npm cache directory
68+
.npm
69+
70+
# Optional eslint cache
71+
.eslintcache
72+
73+
# Optional REPL history
74+
.node_repl_history
75+
76+
# Output of 'npm pack'
77+
*.tgz
78+
79+
# Yarn Integrity file
80+
.yarn-integrity
81+
82+
83+
## IDE things ##
84+
85+
# Webstorm
86+
.idea
87+
88+
# Eclipse:
89+
90+
.project
91+
.metadata
92+
bin/
93+
tmp/
94+
*.tmp
95+
*.bak
96+
*.swp
97+
*~.nib
98+
local.properties
99+
.settings/
100+
.loadpath
101+
.recommenders
102+
103+
104+
scratch.txt
105+
package-lock.json
106+
107+
output/
108+
109+
# Ignore Rush temporary files
110+
/common/temp/**
111+
112+
package-deps.json
113+
114+
.yo-rc.json
115+
116+
lerna-debug.log
117+
118+
TEST-result.xml
119+
.gradle/
120+
.embedpostgresql/
121+
build/
122+
123+
# Windows thumbnail cache files
124+
Thumbs.db
125+
ehthumbs.db
126+
ehthumbs_vista.db
127+
128+
# Dump file
129+
*.stackdump
130+
131+
# Folder config file
132+
[Dd]esktop.ini
133+
134+
# Recycle Bin used on file shares
135+
$RECYCLE.BIN/
136+
137+
# Windows Installer files
138+
*.cab
139+
*.msi
140+
*.msix
141+
*.msm
142+
*.msp
143+
144+
# Windows shortcuts
145+
*.lnk
146+
147+
# OS generated files #
148+
######################
149+
.DS_Store
150+
.DS_Store?
151+
._*
152+
.Spotlight-V100
153+
.Trashes
154+
ehthumbs.db
155+
Thumbs.db
156+
.LSOverride
157+
158+
# Icon must end with two \r
159+
Icon
160+
161+
162+
# Thumbnails
163+
._*
164+
165+
# Files that might appear in the root of a volume
166+
.DocumentRevisions-V100
167+
.fseventsd
168+
.Spotlight-V100
169+
.TemporaryItems
170+
.Trashes
171+
.VolumeIcon.icns
172+
.com.apple.timemachine.donotpresent
173+
174+
# Directories potentially created on remote AFP share
175+
.AppleDB
176+
.AppleDesktop
177+
Network Trash Folder
178+
Temporary Items
179+
.apdisk
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"branch": "master",
3+
"analyzeCommits": {
4+
"preset": "angular",
5+
"releaseRules": [
6+
{
7+
"type": "build",
8+
"scope": "deps",
9+
"release": "minor"
10+
}
11+
]
12+
},
13+
"verifyConditions": [
14+
"@semantic-release/changelog",
15+
"@semantic-release/npm",
16+
"@semantic-release/git"
17+
],
18+
"generateNotes": {
19+
"preset": "metahub"
20+
},
21+
"prepare": [
22+
{
23+
"path": "@semantic-release/changelog",
24+
"changelogFile": "CHANGELOG.md"
25+
},
26+
{
27+
"path": "@semantic-release/git",
28+
"assets": [
29+
"CHANGELOG.md"
30+
]
31+
},
32+
"@semantic-release/npm"
33+
],
34+
"publish": [
35+
"@semantic-release/npm",
36+
"@semantic-release/github"
37+
],
38+
"success": [
39+
"@semantic-release/github"
40+
],
41+
"fail": [
42+
"@semantic-release/github"
43+
]
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: node_js
2+
notifications:
3+
email: false
4+
node_js:
5+
- lts/*
6+
sudo: false
7+
dist: trusty
8+
branches:
9+
only:
10+
- master
11+
env:
12+
global:
13+
- TIMEOUT=15000
14+
install:
15+
- travis_retry npm install
16+
test:
17+
- npm test
18+
before_deploy:
19+
- npm run coverage
20+
deploy:
21+
- provider: script
22+
skip_cleanup: true
23+
script: npx semantic-release
24+
on:
25+
branch: master
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 West Midlands Fire Service
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# tymly-pizza-blueprint
2+
3+
> For ordering delicious pizza
4+
5+
## Install
6+
7+
``` bash
8+
npm install @wmfs/tymly-pizza-blueprint --save
9+
```
10+
11+
## <a name="license"></a>License
12+
13+
MIT

0 commit comments

Comments
 (0)