@newlogic-digital/cli 1.3.0 → 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 +69 -69
- package/package.json +13 -12
- package/src/commands/cms/index.mjs +46 -46
- package/src/commands/cms/prepare.mjs +594 -528
- package/src/commands/init/cms.mjs +178 -179
- package/src/commands/init/index.mjs +63 -78
- package/src/commands/init/options.mjs +27 -27
- package/src/commands/init/ui.mjs +151 -88
- package/src/utils.mjs +18 -17
package/src/commands/init/ui.mjs
CHANGED
|
@@ -1,114 +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
5
|
import { isAutoYes, normalizeEnum, normalizeYesNo } from './options.mjs'
|
|
6
6
|
|
|
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
|
+
|
|
7
46
|
export default async function ui(name, { branch, ...options } = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!clone) {
|
|
12
|
-
if (autoYes) {
|
|
13
|
-
clone = 'https'
|
|
14
|
-
} else {
|
|
15
|
-
const response = await prompts([
|
|
16
|
-
{
|
|
17
|
-
type: 'select',
|
|
18
|
-
name: 'clone',
|
|
19
|
-
message: 'Clone with SSH or HTTPS?',
|
|
20
|
-
choices: [
|
|
21
|
-
{ title: 'SSH', value: 'ssh' },
|
|
22
|
-
{ title: 'HTTPS', value: 'https' }
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
])
|
|
26
|
-
|
|
27
|
-
clone = response.clone
|
|
28
|
-
}
|
|
29
|
-
}
|
|
47
|
+
const autoYes = isAutoYes(options)
|
|
48
|
+
let clone = normalizeEnum(options.clone, ['ssh', 'https'])
|
|
49
|
+
let scope = normalizeEnum(options.scope, ['default', 'blank'])
|
|
30
50
|
|
|
31
|
-
|
|
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
|
+
}
|
|
32
70
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
88
|
}
|
|
89
|
+
}
|
|
38
90
|
|
|
39
|
-
|
|
91
|
+
let url = ''
|
|
40
92
|
|
|
41
|
-
|
|
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
|
+
}
|
|
42
99
|
|
|
43
|
-
|
|
100
|
+
execSync(`git clone -b ${branch} --single-branch --depth 1 ${url}/newlogic-ui.git ${name || '.'}`)
|
|
44
101
|
|
|
45
|
-
|
|
102
|
+
const projectPath = name ? resolve(process.cwd(), name) : resolve(process.cwd())
|
|
103
|
+
const gitPath = join(projectPath, '.git')
|
|
46
104
|
|
|
47
|
-
|
|
48
|
-
if (autoYes) {
|
|
49
|
-
git = 'no'
|
|
50
|
-
} else {
|
|
51
|
-
const response = await prompts([
|
|
52
|
-
{
|
|
53
|
-
type: 'select',
|
|
54
|
-
name: 'git',
|
|
55
|
-
message: 'Init as git repository?',
|
|
56
|
-
choices: [
|
|
57
|
-
{ title: 'yes', value: 'yes' },
|
|
58
|
-
{ title: 'no', value: 'no' }
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
])
|
|
105
|
+
fse.removeSync(gitPath)
|
|
62
106
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
107
|
+
if (scope === 'blank') {
|
|
108
|
+
prepareBlankInstall(projectPath)
|
|
109
|
+
}
|
|
66
110
|
|
|
67
|
-
|
|
68
|
-
execSync(`git init ${name || ''}`)
|
|
111
|
+
let git = normalizeYesNo(options.git)
|
|
69
112
|
|
|
70
|
-
|
|
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 || ''}`)
|
|
71
134
|
|
|
72
|
-
|
|
73
|
-
const response = await prompts([
|
|
74
|
-
{
|
|
75
|
-
type: 'text',
|
|
76
|
-
name: 'remote',
|
|
77
|
-
message: 'Set remote for git repository'
|
|
78
|
-
}
|
|
79
|
-
])
|
|
135
|
+
let remote = (typeof options.remote === 'string' && options.remote.trim()) ? options.remote.trim() : undefined
|
|
80
136
|
|
|
81
|
-
|
|
82
|
-
|
|
137
|
+
if (!remote && !autoYes) {
|
|
138
|
+
remote = await text({
|
|
139
|
+
message: 'Set remote for git repository',
|
|
140
|
+
})
|
|
83
141
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
142
|
+
if (isCancel(remote)) {
|
|
143
|
+
cancel('Operation cancelled.')
|
|
144
|
+
process.exit(1)
|
|
145
|
+
}
|
|
87
146
|
}
|
|
88
147
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (!install) {
|
|
92
|
-
if (autoYes) {
|
|
93
|
-
install = 'yes'
|
|
94
|
-
} else {
|
|
95
|
-
const response = await prompts([
|
|
96
|
-
{
|
|
97
|
-
type: 'select',
|
|
98
|
-
name: 'install',
|
|
99
|
-
message: 'Install project?',
|
|
100
|
-
choices: [
|
|
101
|
-
{ title: 'yes', value: 'yes' },
|
|
102
|
-
{ title: 'no', value: 'no' }
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
])
|
|
106
|
-
|
|
107
|
-
install = response.install
|
|
108
|
-
}
|
|
148
|
+
if (remote) {
|
|
149
|
+
execSync(`cd ${name || '.'} && git remote add origin ${remote} ${name ? '&& cd ..' : ''}`)
|
|
109
150
|
}
|
|
151
|
+
}
|
|
110
152
|
|
|
111
|
-
|
|
112
|
-
|
|
153
|
+
let install = normalizeYesNo(options.install)
|
|
154
|
+
|
|
155
|
+
if (!install) {
|
|
156
|
+
if (autoYes) {
|
|
157
|
+
install = 'yes'
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const response = await confirm({
|
|
161
|
+
message: 'Install project?',
|
|
162
|
+
initialValue: true,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (isCancel(response)) {
|
|
166
|
+
cancel('Operation cancelled.')
|
|
167
|
+
process.exit(1)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
install = response ? 'yes' : 'no'
|
|
113
171
|
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (install === 'yes') {
|
|
175
|
+
execSync(`cd ${name || '.'} && npm i`)
|
|
176
|
+
}
|
|
114
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 }
|