@newlogic-digital/cli 1.2.3 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +79 -24
- package/package.json +14 -13
- package/src/commands/cms/index.mjs +46 -46
- package/src/commands/cms/prepare.mjs +594 -528
- package/src/commands/init/cms.mjs +195 -140
- package/src/commands/init/index.mjs +70 -58
- package/src/commands/init/options.mjs +47 -0
- package/src/commands/init/ui.mjs +161 -58
- package/src/utils.mjs +18 -17
package/src/commands/init/ui.mjs
CHANGED
|
@@ -1,74 +1,177 @@
|
|
|
1
|
+
import { cancel, confirm, isCancel, select, text } from '@clack/prompts'
|
|
1
2
|
import { execSync } from '../../utils.mjs'
|
|
2
3
|
import fse from 'fs-extra'
|
|
3
|
-
import prompts from 'prompts'
|
|
4
4
|
import { join, resolve } from 'path'
|
|
5
|
+
import { isAutoYes, normalizeEnum, normalizeYesNo } from './options.mjs'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
function prepareBlankInstall(projectPath) {
|
|
8
|
+
[
|
|
9
|
+
join(projectPath, 'src', 'template', 'emails'),
|
|
10
|
+
join(projectPath, 'src', 'templates', 'emails'),
|
|
11
|
+
join(projectPath, 'src', 'styles', 'emails'),
|
|
12
|
+
join(projectPath, 'src', 'data', 'nav.json'),
|
|
13
|
+
join(projectPath, 'src', 'data', 'socials.json'),
|
|
14
|
+
join(projectPath, 'src', 'styles', 'tinymce.css'),
|
|
15
|
+
].forEach(path => fse.removeSync(path))
|
|
16
|
+
|
|
17
|
+
const mainDataPath = join(projectPath, 'src', 'data', 'main.json')
|
|
18
|
+
|
|
19
|
+
if (fse.existsSync(mainDataPath)) {
|
|
20
|
+
const mainData = fse.readFileSync(mainDataPath, 'utf8').replace('"cookieConsent": true', '"cookieConsent": false')
|
|
21
|
+
fse.writeFileSync(mainDataPath, mainData)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const iconsPath = join(projectPath, 'src', 'icons')
|
|
25
|
+
fse.ensureDirSync(iconsPath)
|
|
26
|
+
fse.emptyDirSync(iconsPath)
|
|
27
|
+
|
|
28
|
+
const scriptsPath = join(projectPath, 'src', 'scripts')
|
|
29
|
+
fse.emptyDirSync(scriptsPath)
|
|
30
|
+
fse.outputFileSync(join(scriptsPath, 'main.js'), '')
|
|
31
|
+
|
|
32
|
+
const stylesComponentsPath = join(projectPath, 'src', 'styles', 'components')
|
|
33
|
+
fse.emptyDirSync(stylesComponentsPath)
|
|
34
|
+
fse.outputFileSync(join(stylesComponentsPath, '+.css'), '')
|
|
35
|
+
|
|
36
|
+
const templatesComponentsPath = join(projectPath, 'src', 'templates', 'components')
|
|
37
|
+
fse.emptyDirSync(templatesComponentsPath)
|
|
38
|
+
fse.outputFileSync(join(templatesComponentsPath, 'footer', 'Footer.latte'), '')
|
|
39
|
+
fse.outputFileSync(join(templatesComponentsPath, 'header', 'Header.latte'), '')
|
|
40
|
+
|
|
41
|
+
const pagesPath = join(projectPath, 'src', 'pages')
|
|
42
|
+
fse.emptyDirSync(pagesPath)
|
|
43
|
+
fse.outputFileSync(join(pagesPath, 'index.json'), '{\n "title": "Hello world"\n}\n')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default async function ui(name, { branch, ...options } = {}) {
|
|
47
|
+
const autoYes = isAutoYes(options)
|
|
48
|
+
let clone = normalizeEnum(options.clone, ['ssh', 'https'])
|
|
49
|
+
let scope = normalizeEnum(options.scope, ['default', 'blank'])
|
|
50
|
+
|
|
51
|
+
if (!clone) {
|
|
52
|
+
if (autoYes) {
|
|
53
|
+
clone = 'https'
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
clone = await select({
|
|
57
|
+
message: 'Clone with SSH or HTTPS?',
|
|
58
|
+
options: [
|
|
59
|
+
{ label: 'SSH', value: 'ssh' },
|
|
60
|
+
{ label: 'HTTPS', value: 'https' },
|
|
61
|
+
],
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
if (isCancel(clone)) {
|
|
65
|
+
cancel('Operation cancelled.')
|
|
66
|
+
process.exit(1)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!scope) {
|
|
72
|
+
if (autoYes) {
|
|
73
|
+
scope = 'default'
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
scope = await select({
|
|
77
|
+
message: 'Select install scope',
|
|
78
|
+
options: [
|
|
79
|
+
{ label: 'default', value: 'default' },
|
|
80
|
+
{ label: 'blank', value: 'blank' },
|
|
81
|
+
],
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (isCancel(scope)) {
|
|
85
|
+
cancel('Operation cancelled.')
|
|
86
|
+
process.exit(1)
|
|
87
|
+
}
|
|
25
88
|
}
|
|
89
|
+
}
|
|
26
90
|
|
|
27
|
-
|
|
91
|
+
let url = ''
|
|
28
92
|
|
|
29
|
-
|
|
93
|
+
if (clone === 'ssh') {
|
|
94
|
+
url = 'git@git.newlogic.cz:newlogic-digital'
|
|
95
|
+
}
|
|
96
|
+
else if (clone === 'https') {
|
|
97
|
+
url = 'https://git.newlogic.cz/newlogic-digital'
|
|
98
|
+
}
|
|
30
99
|
|
|
31
|
-
|
|
100
|
+
execSync(`git clone -b ${branch} --single-branch --depth 1 ${url}/newlogic-ui.git ${name || '.'}`)
|
|
32
101
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
type: 'select',
|
|
36
|
-
name: 'git',
|
|
37
|
-
message: 'Init as git repository?',
|
|
38
|
-
choices: [
|
|
39
|
-
{ title: 'yes', value: 'yes' },
|
|
40
|
-
{ title: 'no', value: 'no' }
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
])
|
|
102
|
+
const projectPath = name ? resolve(process.cwd(), name) : resolve(process.cwd())
|
|
103
|
+
const gitPath = join(projectPath, '.git')
|
|
44
104
|
|
|
45
|
-
|
|
46
|
-
execSync(`git init ${name || ''}`)
|
|
105
|
+
fse.removeSync(gitPath)
|
|
47
106
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
name: 'remote',
|
|
52
|
-
message: 'Set remote for git repository'
|
|
53
|
-
}
|
|
54
|
-
])
|
|
107
|
+
if (scope === 'blank') {
|
|
108
|
+
prepareBlankInstall(projectPath)
|
|
109
|
+
}
|
|
55
110
|
|
|
56
|
-
|
|
111
|
+
let git = normalizeYesNo(options.git)
|
|
112
|
+
|
|
113
|
+
if (!git) {
|
|
114
|
+
if (autoYes) {
|
|
115
|
+
git = 'no'
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const response = await confirm({
|
|
119
|
+
message: 'Init as git repository?',
|
|
120
|
+
initialValue: true,
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
if (isCancel(response)) {
|
|
124
|
+
cancel('Operation cancelled.')
|
|
125
|
+
process.exit(1)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
git = response ? 'yes' : 'no'
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (git === 'yes') {
|
|
133
|
+
execSync(`git init ${name || ''}`)
|
|
134
|
+
|
|
135
|
+
let remote = (typeof options.remote === 'string' && options.remote.trim()) ? options.remote.trim() : undefined
|
|
136
|
+
|
|
137
|
+
if (!remote && !autoYes) {
|
|
138
|
+
remote = await text({
|
|
139
|
+
message: 'Set remote for git repository',
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
if (isCancel(remote)) {
|
|
143
|
+
cancel('Operation cancelled.')
|
|
144
|
+
process.exit(1)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (remote) {
|
|
149
|
+
execSync(`cd ${name || '.'} && git remote add origin ${remote} ${name ? '&& cd ..' : ''}`)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let install = normalizeYesNo(options.install)
|
|
154
|
+
|
|
155
|
+
if (!install) {
|
|
156
|
+
if (autoYes) {
|
|
157
|
+
install = 'yes'
|
|
57
158
|
}
|
|
159
|
+
else {
|
|
160
|
+
const response = await confirm({
|
|
161
|
+
message: 'Install project?',
|
|
162
|
+
initialValue: true,
|
|
163
|
+
})
|
|
58
164
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{ title: 'yes', value: 'yes' },
|
|
66
|
-
{ title: 'no', value: 'no' }
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
])
|
|
70
|
-
|
|
71
|
-
if (install === 'yes') {
|
|
72
|
-
execSync(`cd ${name || '.'} && npm i`)
|
|
165
|
+
if (isCancel(response)) {
|
|
166
|
+
cancel('Operation cancelled.')
|
|
167
|
+
process.exit(1)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
install = response ? 'yes' : 'no'
|
|
73
171
|
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (install === 'yes') {
|
|
175
|
+
execSync(`cd ${name || '.'} && npm i`)
|
|
176
|
+
}
|
|
74
177
|
}
|
package/src/utils.mjs
CHANGED
|
@@ -6,31 +6,32 @@ import { fileURLToPath } from 'url'
|
|
|
6
6
|
const { version, name } = JSON.parse(fs.readFileSync(resolve(dirname((fileURLToPath(import.meta.url))), '../package.json')).toString())
|
|
7
7
|
|
|
8
8
|
const execSync = (cmd) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
try {
|
|
10
|
+
childProcess.execSync(cmd, { stdio: [0, 1, 2] })
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
const stripIndent = (string) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!match) {
|
|
21
|
-
return 0
|
|
22
|
-
}
|
|
18
|
+
const indent = () => {
|
|
19
|
+
const match = string.match(/^[ \t]*(?=\S)/gm)
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
if (!match) {
|
|
22
|
+
return 0
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
return match.reduce((r, a) => Math.min(r, a.length), Infinity)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (indent() === 0) {
|
|
29
|
+
return string
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
const regex = new RegExp(`^[ \\t]{${indent()}}`, 'gm')
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
return string.replace(regex, '')
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export { execSync, stripIndent, version, name }
|