@newlogic-digital/cli 0.0.9 → 0.0.12
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newlogic-digital/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"main": "index.mjs",
|
|
5
5
|
"bin": {
|
|
6
6
|
"newlogic-cli": "index.mjs",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"eslint": "eslint '**/*.mjs' --fix"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"lodash": "^4.17.21",
|
|
13
14
|
"prompts": "^2.4.2",
|
|
14
15
|
"fs-extra": "^10.1.0",
|
|
15
16
|
"picocolors": "^1.0.0",
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import prepare from './prepare.mjs'
|
|
2
2
|
import pc from 'picocolors'
|
|
3
3
|
import fs from 'fs'
|
|
4
|
+
import fse from 'fs-extra'
|
|
4
5
|
import { join, resolve } from 'path'
|
|
5
6
|
|
|
6
7
|
export const options = {
|
|
7
8
|
path: {
|
|
8
9
|
src: {
|
|
9
10
|
templates: resolve(process.cwd(), 'src/templates'),
|
|
10
|
-
sections: resolve(process.cwd(), 'src/templates/Sections')
|
|
11
|
+
sections: resolve(process.cwd(), 'src/templates/Sections'),
|
|
12
|
+
views: resolve(process.cwd(), 'src/views')
|
|
11
13
|
},
|
|
12
14
|
app: {
|
|
13
15
|
templates: resolve(process.cwd(), 'app/Templates'),
|
|
14
16
|
sections: resolve(process.cwd(), 'app/Sections'),
|
|
15
|
-
sectionsFactory: resolve(process.cwd(), 'app/Sections/Factory')
|
|
17
|
+
sectionsFactory: resolve(process.cwd(), 'app/Sections/Factory'),
|
|
18
|
+
tempCache: resolve(process.cwd(), 'temp/cache')
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -33,6 +36,10 @@ export default async function cms(action, name) {
|
|
|
33
36
|
prepare(options).writeSection(name)
|
|
34
37
|
prepare(options).writeSectionFactory(nameFormatted)
|
|
35
38
|
|
|
39
|
+
if (fs.existsSync(options.path.app.tempCache)) {
|
|
40
|
+
fse.removeSync(options.path.app.tempCache)
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
console.log(`${pc.green('✔')} section ${nameFormatted} created`)
|
|
37
44
|
}
|
|
38
45
|
}
|
|
@@ -4,6 +4,7 @@ import fs from 'fs'
|
|
|
4
4
|
import fse from 'fs-extra'
|
|
5
5
|
import { stripIndent } from '../../utils.mjs'
|
|
6
6
|
import pc from 'picocolors'
|
|
7
|
+
import lodash from 'lodash'
|
|
7
8
|
|
|
8
9
|
let sectionsCount = 0
|
|
9
10
|
let sectionsFactoryCount = 0
|
|
@@ -51,6 +52,93 @@ export default function prepare(options) {
|
|
|
51
52
|
|
|
52
53
|
if (!name.match(/(Ui)/)) {
|
|
53
54
|
if (!fs.existsSync(join(options.path.app.sections, `${name}.php`)) || force) {
|
|
55
|
+
const schema = this.getSectionsSchema()
|
|
56
|
+
const controls = schema[path] ?? {}
|
|
57
|
+
let annotations = []
|
|
58
|
+
let objects = []
|
|
59
|
+
|
|
60
|
+
const getField = (control, type) => {
|
|
61
|
+
if (type === 'number') {
|
|
62
|
+
return 'int'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (control.startsWith('table')) {
|
|
66
|
+
return 'table'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (control === 'heading' || control === 'title') {
|
|
70
|
+
return 'text'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (control === 'content') {
|
|
74
|
+
return 'wsw'
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (type === 'string') {
|
|
78
|
+
return 'textarea'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (type === 'boolean') {
|
|
82
|
+
return type
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return type
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const getTitle = (control) => {
|
|
89
|
+
if (control === 'heading') {
|
|
90
|
+
return 'Nadpis'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (control === 'title') {
|
|
94
|
+
return 'Titulek'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (control === 'content') {
|
|
98
|
+
return 'Obsah'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (control === 'text') {
|
|
102
|
+
return 'Text'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return control[0].toUpperCase() + control.slice(1)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Object.keys(controls).forEach(control => {
|
|
109
|
+
if (control !== 'src') {
|
|
110
|
+
const type = typeof controls[control] === 'number' ? 'int' : typeof controls[control]
|
|
111
|
+
const value = typeof controls[control] === 'object' ? JSON.stringify(controls[control]) : controls[control]
|
|
112
|
+
|
|
113
|
+
annotations.push(`
|
|
114
|
+
/**
|
|
115
|
+
* @field ${getField(control, type)}
|
|
116
|
+
* @title ${getTitle(control)}
|
|
117
|
+
* @value ${value}
|
|
118
|
+
*/
|
|
119
|
+
public ${type} $${control};
|
|
120
|
+
`)
|
|
121
|
+
|
|
122
|
+
if (type === 'object') {
|
|
123
|
+
objects.push(`
|
|
124
|
+
$this->${control} = json_decode('${value}', true);
|
|
125
|
+
`)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
if (annotations.length > 0) {
|
|
131
|
+
annotations = annotations.map(item => item).join("");
|
|
132
|
+
} else {
|
|
133
|
+
annotations = "";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (objects.length > 0) {
|
|
137
|
+
objects = objects.map(item => item).join("");
|
|
138
|
+
} else {
|
|
139
|
+
objects = "";
|
|
140
|
+
}
|
|
141
|
+
|
|
54
142
|
fs.writeFileSync(join(options.path.app.sections, `${name}.php`),
|
|
55
143
|
stripIndent(`
|
|
56
144
|
<?php
|
|
@@ -59,8 +147,10 @@ export default function prepare(options) {
|
|
|
59
147
|
|
|
60
148
|
class ${name} extends BaseSection
|
|
61
149
|
{
|
|
62
|
-
|
|
150
|
+
${annotations}
|
|
151
|
+
public function render() : void
|
|
63
152
|
{
|
|
153
|
+
${objects}
|
|
64
154
|
$this->getTemplate()->render(TEMPLATES_DIR . '/${path}');
|
|
65
155
|
}
|
|
66
156
|
}
|
|
@@ -116,6 +206,40 @@ export default function prepare(options) {
|
|
|
116
206
|
}
|
|
117
207
|
|
|
118
208
|
console.log(`${pc.green('✔')} ${templatesCount} template files copied to app`)
|
|
209
|
+
},
|
|
210
|
+
getSectionsSchema() {
|
|
211
|
+
const views = FastGlob.sync(join(options.path.src.views, '/**/*.json'))
|
|
212
|
+
const sectionsUnsorted = {}
|
|
213
|
+
const sectionsSchema = {}
|
|
214
|
+
|
|
215
|
+
views.forEach(path => {
|
|
216
|
+
const json = JSON.parse(fs.readFileSync(path).toString())
|
|
217
|
+
const sections = [...(json.page.body ?? []), ...(json.page.head ?? []), ...(json.page.foot ?? [])]
|
|
218
|
+
|
|
219
|
+
sections.forEach((section) => {
|
|
220
|
+
if (section.src) {
|
|
221
|
+
if (typeof sectionsUnsorted[section.src] === "undefined") {
|
|
222
|
+
sectionsUnsorted[section.src] = []
|
|
223
|
+
sectionsUnsorted[section.src].push(section);
|
|
224
|
+
} else {
|
|
225
|
+
sectionsUnsorted[section.src].push(section);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
Object.keys(sectionsUnsorted).forEach(key => {
|
|
233
|
+
const sortedSection = {}
|
|
234
|
+
|
|
235
|
+
sectionsUnsorted[key].forEach(section => {
|
|
236
|
+
lodash.merge(sortedSection, section)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
sectionsSchema[sortedSection.src] = sortedSection
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
return sectionsSchema
|
|
119
243
|
}
|
|
120
244
|
}
|
|
121
245
|
}
|
|
@@ -4,11 +4,12 @@ import fs from 'fs'
|
|
|
4
4
|
import os from 'os'
|
|
5
5
|
import pc from 'picocolors'
|
|
6
6
|
import fse from 'fs-extra'
|
|
7
|
+
import prompts from 'prompts'
|
|
7
8
|
|
|
8
9
|
const tempDir = join(os.tmpdir(), 'newlogic-cms-web')
|
|
9
10
|
|
|
10
|
-
async function move(path) {
|
|
11
|
-
await fse.move(join(tempDir, path), resolve(process.cwd(), path)).catch(err => console.log(pc.red(err)))
|
|
11
|
+
async function move(path, options = {}) {
|
|
12
|
+
await fse.move(join(tempDir, path), resolve(process.cwd(), path), options).catch(err => console.log(`${pc.red(err)} - ${path}` ))
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
function clone(path, { variant, branch }) {
|
|
@@ -21,9 +22,47 @@ function clone(path, { variant, branch }) {
|
|
|
21
22
|
execSync(`git clone -b ${branch} --single-branch --depth 1 git@git.newlogic.cz:newlogic-dev/${variant}.git ${path}`)
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
async function install(name) {
|
|
26
|
+
const { install } = await prompts([
|
|
27
|
+
{
|
|
28
|
+
type: 'select',
|
|
29
|
+
name: 'install',
|
|
30
|
+
message: 'Install project?',
|
|
31
|
+
choices: [
|
|
32
|
+
{ title: 'yes', value: 'yes' },
|
|
33
|
+
{ title: 'no', value: 'no' }
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
])
|
|
37
|
+
|
|
38
|
+
if (install === 'yes') {
|
|
39
|
+
execSync(`cd ${name || '.'} && make install`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function prepare() {
|
|
44
|
+
const { install } = await prompts([
|
|
45
|
+
{
|
|
46
|
+
type: 'select',
|
|
47
|
+
name: 'install',
|
|
48
|
+
message: 'Prepare project with templates from frontend?',
|
|
49
|
+
choices: [
|
|
50
|
+
{ title: 'yes', value: 'yes' },
|
|
51
|
+
{ title: 'no', value: 'no' }
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
if (install === 'yes') {
|
|
57
|
+
execSync(`newlogic cms prepare`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
24
61
|
export default async function cms(name, { variant, branch }) {
|
|
25
62
|
if (name) {
|
|
26
63
|
clone(name, { variant, branch })
|
|
64
|
+
await install(name)
|
|
65
|
+
await prepare()
|
|
27
66
|
return
|
|
28
67
|
}
|
|
29
68
|
|
|
@@ -40,7 +79,7 @@ export default async function cms(name, { variant, branch }) {
|
|
|
40
79
|
await move('public/.htaccess')
|
|
41
80
|
await move('public/index.php')
|
|
42
81
|
await move('temp')
|
|
43
|
-
await move('.gitignore')
|
|
82
|
+
await move('.gitignore', { overwrite: true })
|
|
44
83
|
await move('.htaccess')
|
|
45
84
|
await move('Makefile')
|
|
46
85
|
await move('composer.json')
|
|
@@ -50,4 +89,7 @@ export default async function cms(name, { variant, branch }) {
|
|
|
50
89
|
await move('pint.json')
|
|
51
90
|
|
|
52
91
|
fse.removeSync(tempDir)
|
|
92
|
+
|
|
93
|
+
await install()
|
|
94
|
+
await prepare()
|
|
53
95
|
}
|
|
@@ -14,7 +14,12 @@ async function init(project, name) {
|
|
|
14
14
|
choices: [
|
|
15
15
|
{ title: 'ui', value: 'ui' },
|
|
16
16
|
{ title: 'cms', value: 'cms' }
|
|
17
|
-
]
|
|
17
|
+
],
|
|
18
|
+
onState: (state) => {
|
|
19
|
+
if (state.aborted) {
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
])
|
|
20
25
|
|
|
@@ -30,12 +35,17 @@ async function init(project, name) {
|
|
|
30
35
|
choices: [
|
|
31
36
|
{ title: 'main', value: 'main' },
|
|
32
37
|
{ title: 'dev', value: 'dev' }
|
|
33
|
-
]
|
|
38
|
+
],
|
|
39
|
+
onState: (state) => {
|
|
40
|
+
if (state.aborted) {
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
34
44
|
}
|
|
35
45
|
])
|
|
36
46
|
|
|
37
47
|
if (project === 'ui') {
|
|
38
|
-
ui(name, { branch })
|
|
48
|
+
await ui(name, { branch })
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
if (project === 'cms') {
|
|
@@ -47,7 +57,12 @@ async function init(project, name) {
|
|
|
47
57
|
choices: [
|
|
48
58
|
{ title: 'cms-web', value: 'cms-web' },
|
|
49
59
|
{ title: 'cms-eshop', value: 'cms-eshop' }
|
|
50
|
-
]
|
|
60
|
+
],
|
|
61
|
+
onState: (state) => {
|
|
62
|
+
if (state.aborted) {
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
51
66
|
}
|
|
52
67
|
])
|
|
53
68
|
|
package/src/commands/init/ui.mjs
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { execSync } from '../../utils.mjs'
|
|
2
|
+
import prompts from 'prompts'
|
|
2
3
|
|
|
3
|
-
export default function ui(name, { branch }) {
|
|
4
|
+
export default async function ui(name, { branch }) {
|
|
4
5
|
execSync(`git clone -b ${branch} --single-branch --depth 1 git@git.newlogic.cz:newlogic-dev/newlogic-ui.git ${name || '.'}`)
|
|
6
|
+
|
|
7
|
+
const { install } = await prompts([
|
|
8
|
+
{
|
|
9
|
+
type: 'select',
|
|
10
|
+
name: 'install',
|
|
11
|
+
message: 'Install project?',
|
|
12
|
+
choices: [
|
|
13
|
+
{ title: 'yes', value: 'yes' },
|
|
14
|
+
{ title: 'no', value: 'no' }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
if (install === 'yes') {
|
|
20
|
+
execSync(`cd ${name || '.'} && npm i`)
|
|
21
|
+
}
|
|
5
22
|
}
|