@newlogic-digital/cli 0.0.12 → 0.0.13

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.12",
3
+ "version": "0.0.13",
4
4
  "main": "index.mjs",
5
5
  "bin": {
6
6
  "newlogic-cli": "index.mjs",
@@ -14,7 +14,8 @@
14
14
  "prompts": "^2.4.2",
15
15
  "fs-extra": "^10.1.0",
16
16
  "picocolors": "^1.0.0",
17
- "fast-glob": "^3.2.11"
17
+ "fast-glob": "^3.2.11",
18
+ "dedent": "^0.7.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "eslint": "^8.23.0",
@@ -2,9 +2,9 @@ import FastGlob from 'fast-glob'
2
2
  import { join, relative, extname } from 'path'
3
3
  import fs from 'fs'
4
4
  import fse from 'fs-extra'
5
- import { stripIndent } from '../../utils.mjs'
6
5
  import pc from 'picocolors'
7
6
  import lodash from 'lodash'
7
+ import dedent from 'dedent'
8
8
 
9
9
  let sectionsCount = 0
10
10
  let sectionsFactoryCount = 0
@@ -107,21 +107,31 @@ export default function prepare(options) {
107
107
 
108
108
  Object.keys(controls).forEach(control => {
109
109
  if (control !== 'src') {
110
- const type = typeof controls[control] === 'number' ? 'int' : typeof controls[control]
110
+ const type = typeof controls[control]
111
111
  const value = typeof controls[control] === 'object' ? JSON.stringify(controls[control]) : controls[control]
112
112
 
113
+ let phpType = type;
114
+
115
+ if (type === 'object' && Array.isArray(controls[control])) {
116
+ phpType = 'array'
117
+ } else if (type === 'boolean') {
118
+ phpType = 'bool'
119
+ } else if (type === 'number') {
120
+ phpType = 'int'
121
+ }
122
+
113
123
  annotations.push(`
114
124
  /**
115
125
  * @field ${getField(control, type)}
116
126
  * @title ${getTitle(control)}
117
127
  * @value ${value}
118
128
  */
119
- public ${type} $${control};
129
+ public ${phpType} $${control}${type === 'string' ? " = '" + value + "'" : ""};
120
130
  `)
121
131
 
122
132
  if (type === 'object') {
123
133
  objects.push(`
124
- $this->${control} = json_decode('${value}', true);
134
+ $this->${control} = json_decode('${value}', false);
125
135
  `)
126
136
  }
127
137
  }
@@ -140,10 +150,10 @@ export default function prepare(options) {
140
150
  }
141
151
 
142
152
  fs.writeFileSync(join(options.path.app.sections, `${name}.php`),
143
- stripIndent(`
153
+ dedent`
144
154
  <?php
145
155
 
146
- namespace App\\Sections;
156
+ namespace App\Sections;
147
157
 
148
158
  class ${name} extends BaseSection
149
159
  {
@@ -154,7 +164,7 @@ export default function prepare(options) {
154
164
  $this->getTemplate()->render(TEMPLATES_DIR . '/${path}');
155
165
  }
156
166
  }
157
- `).replace(/^\s*\n/g, '')
167
+ `
158
168
  )
159
169
 
160
170
  sectionsCount += 1
@@ -165,18 +175,18 @@ export default function prepare(options) {
165
175
  if (!name.match(/(Ui)/)) {
166
176
  if (!fs.existsSync(join(options.path.app.sectionsFactory, `${name}Factory.php`)) || force) {
167
177
  fs.writeFileSync(join(options.path.app.sectionsFactory, `${name}Factory.php`),
168
- stripIndent(`
178
+ dedent`
169
179
  <?php
170
180
 
171
- namespace App\\Sections\\Factory;
181
+ namespace App\Sections\Factory;
172
182
 
173
- use App\\Sections\\${name};
183
+ use App\Sections\${name};
174
184
 
175
185
  interface ${name}Factory
176
186
  {
177
187
  public function create(): ${name};
178
188
  }
179
- `).replace(/^\s*\n/g, '')
189
+ `
180
190
  )
181
191
 
182
192
  sectionsFactoryCount += 1