Skip to content

Commit ba732d3

Browse files
committed
feat: Hook profile into new-blueprint
1 parent 8bad797 commit ba732d3

14 files changed

Lines changed: 406 additions & 32 deletions

File tree

lib/actions/init/index.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
const c = require('ansi-colors')
2-
const path = require('path')
3-
const homedir = require('os').homedir()
42
const { prompt } = require('enquirer')
53
const loadProfile = require('../profile')
6-
const username = require('username')
74

85
async function initAction (options) {
9-
const workingDirectory = options.profile || path.join(homedir, '.tymly')
10-
11-
const profile = loadProfile(workingDirectory)
12-
console.log(c.bold(`${profile.loaded ? 'Updating' : 'Creating'} Tymly profile in ${workingDirectory}`))
6+
const profile = loadProfile(options.profile)
7+
console.log(c.bold(`${profile.loaded ? 'Updating' : 'Creating'} Tymly profile in ${profile.directory}`))
138

149
const updates = await gatherProfileDetails(profile)
1510

@@ -25,26 +20,26 @@ async function gatherProfileDetails (profile) {
2520
type: 'input',
2621
name: 'author',
2722
message: 'Your name',
28-
initial: profile.author || await username()
23+
initial: () => profile.authorSuggestion()
2924
},
3025
{
3126
type: 'input',
3227
name: 'organisation',
3328
message: 'Your Organisation',
34-
initial: profile.organisation || ''
29+
initial: () => profile.organisationSuggestion()
3530
},
3631
{
3732
type: 'input',
3833
name: 'gitHubOwner',
3934
message: 'GitHub Owner',
40-
initial: () => profile.gitHubOwner || gitHubGuess(profileInfo.organisation),
35+
initial: () => profile.gitHubOwnerSuggestion(profileInfo.organisation),
4136
validate: v => v.match(' ') ? 'No spaces allowed in GitHub Owner name' : true
4237
},
4338
{
4439
type: 'input',
4540
name: 'npmOrg',
4641
message: 'NPM Organisation',
47-
initial: () => profile.npmOrg || profileInfo.gitHubOwner,
42+
initial: () => profile.npmOrgSuggestion(profileInfo.gitHubOwner),
4843
validate: v => v.match(' ') ? 'No spaces allowed in NPM Organisation name' : true
4944
}
5045
]
@@ -56,10 +51,4 @@ async function gatherProfileDetails (profile) {
5651
return profileInfo
5752
} // gatherProfileDetails
5853

59-
function gitHubGuess (org) {
60-
return org.match(' ')
61-
? org.split(' ').map(s => `${s.toLowerCase()[0]}`).join('')
62-
: org.toLowerCase()
63-
}
64-
6554
module.exports = initAction

lib/actions/new-blueprint/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const c = require('ansi-colors')
22
const { prompt } = require('enquirer')
33
const path = require('path')
44
const fs = require('fs')
5+
const loadProfile = require('../profile')
56
const Scaffold = require('@wmfs/tymly-scaffold')
67

78
async function newBlueprint (blueprintName, options) {
@@ -18,7 +19,8 @@ async function newBlueprint (blueprintName, options) {
1819
return
1920
}
2021

21-
const blueprintInfo = await solicitDetails()
22+
const profile = loadProfile(options.profile)
23+
const blueprintInfo = await solicitDetails(profile)
2224

2325
const scaffold = new Scaffold({
2426
basePath: workingDirectory
@@ -46,7 +48,7 @@ function canCreate (blueprintPath) {
4648
}
4749
}
4850

49-
async function solicitDetails () {
51+
async function solicitDetails (profile) {
5052
let blueprintInfo = { }
5153

5254
const questions = [
@@ -59,12 +61,13 @@ async function solicitDetails () {
5961
type: 'input',
6062
name: 'author',
6163
message: 'Author',
62-
initial: process.env.user
64+
initial: () => profile.authorSuggestion()
6365
},
6466
{
6567
type: 'input',
6668
name: 'organisation',
67-
message: 'Organisation'
69+
message: 'Organisation',
70+
initial: () => profile.organisationSuggestion()
6871
},
6972
{
7073
type: 'input',
@@ -76,16 +79,14 @@ async function solicitDetails () {
7679
type: 'input',
7780
name: 'gitHubOwner',
7881
message: 'GitHub Owner',
79-
initial: () => blueprintInfo.organisation.match(' ')
80-
? blueprintInfo.organisation.split(' ').map(s => `${s.toLowerCase()[0]}`).join('')
81-
: blueprintInfo.organisation.toLowerCase(),
82+
initial: () => profile.gitHubOwnerSuggestion(blueprintInfo.organisation),
8283
validate: v => v.match(' ') ? 'No spaces allowed in GitHub Owner name' : true
8384
},
8485
{
8586
type: 'input',
8687
name: 'npmOrg',
8788
message: 'NPM Organisation',
88-
initial: () => blueprintInfo.gitHubOwner,
89+
initial: () => profile.npmOrgSuggestion(blueprintInfo.gitHubOwner),
8990
validate: v => v.match(' ') ? 'No spaces allowed in NPM Organisation name' : true
9091
},
9192
{

lib/actions/profile.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const fs = require('fs-extra')
22
const path = require('path')
3+
const homedir = require('os').homedir()
4+
const username = require('username')
35

46
const Properties = [
57
'author',
@@ -10,11 +12,17 @@ const Properties = [
1012

1113
class Profile {
1214
constructor (profileFileName, initial = null) {
15+
this.directory = path.dirname(profileFileName)
1316
this.profileFileName = profileFileName
1417
this.loaded = !!initial
1518
this.update(initial || { })
1619
}
1720

21+
authorSuggestion () { return this.author || username.sync() }
22+
organisationSuggestion () { return this.organisation || '' }
23+
gitHubOwnerSuggestion (org) { return this.gitHubOwner || gitHubGuess(org) }
24+
npmOrgSuggestion (org) { return this.npmOrg || org }
25+
1826
update (props) {
1927
Properties.forEach(p => { this[p] = props[p] })
2028
}
@@ -40,12 +48,20 @@ function load (profileFileName) {
4048
}
4149

4250
function loadProfile (profileDir) {
43-
const profileFileName = path.join(profileDir, 'tymly-profile.json')
51+
const workingDir = profileDir || path.join(homedir, '.tymly')
52+
53+
const profileFileName = path.join(workingDir, 'tymly-profile.json')
4454

4555
return new Profile(
4656
profileFileName,
4757
load(profileFileName)
4858
)
4959
}
5060

61+
function gitHubGuess (org) {
62+
return org.match(' ')
63+
? org.split(' ').map(s => `${s.toLowerCase()[0]}`).join('')
64+
: org.toLowerCase()
65+
}
66+
5167
module.exports = loadProfile

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function tymlyCli (argv) {
2121
.command('new-blueprint <blueprint-name>')
2222
.description('Create a new Tymly blueprint')
2323
.option('-p, --path <path>', 'working directory - defaults to "."')
24+
.option('--profile <path>', 'alternative profile path - defaults to your home directory')
2425
.action((blueprintName, options) => {
2526
actions.newBlueprintAction(blueprintName, options)
2627
})
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

0 commit comments

Comments
 (0)