@codigodoleo/wp-kit 2.0.4 → 3.0.1
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/.cspell.json +5 -25
- package/README.md +127 -2
- package/lib/cli.js +1 -0
- package/lib/commands/init.js +32 -10
- package/lib/config/versions.js +163 -0
- package/lib/core/generator.js +63 -46
- package/lib/core/hook-manager.js +2 -2
- package/lib/core/infer-ci-capabilities.js +13 -24
- package/lib/prompts/index.js +31 -19
- package/lib/prompts/loadModulePrompts.js +4 -2
- package/lib/utils/generate-from-template.js +1 -0
- package/modules/deploy/index.js +34 -7
- package/modules/deploy/prompts.js +5 -5
- package/modules/deploy/templates/.github/workflows/ci.yml.hbs +49 -103
- package/modules/deploy/templates/.gitlab/gitlab-ci.yml.hbs +45 -145
- package/modules/deploy/templates/bitbucket-pipelines.yml.hbs +46 -97
- package/modules/docs/prompts.js +2 -2
- package/modules/docs/templates/README.md.hbs +67 -160
- package/modules/docs/templates/docs/Arquitetura.md +113 -92
- package/modules/docs/templates/docs/Deploy-Pipeline.md +22 -8
- package/modules/docs/templates/docs/Desenvolvimento.md +187 -164
- package/modules/docs/templates/docs/Getting-Started.md +37 -7
- package/modules/docs/templates/docs/Infraestrutura.md +41 -12
- package/modules/docs/templates/docs/Monitoramento.md +83 -45
- package/modules/docs/templates/docs/Sync-the-Production-DB-with-the-Staging-DB.md +6 -7
- package/modules/docs/templates/docs/Troubleshooting.md +1 -1
- package/modules/git/.github/PULL_REQUEST_TEMPLATE.md +1 -0
- package/modules/git/.gitlab/merge_request_templates/default.md +1 -0
- package/modules/git/.vscode/commit-instructions.md +7 -0
- package/modules/git/.vscode/conventional-commits.code-snippets +13 -43
- package/modules/git/docs/CONVENTIONAL-COMMITS.md +14 -14
- package/modules/git/index.js +39 -34
- package/modules/git/prompts.js +4 -4
- package/modules/git/templates/.lando.yml.hbs +5 -13
- package/modules/git/templates/package.json.hbs +4 -15
- package/modules/git/templates/workspace.json.hbs +28 -114
- package/modules/lint/eslint.config.mjs +36 -0
- package/modules/lint/index.js +1 -2
- package/modules/lint/prompts.js +3 -3
- package/modules/lint/templates/.lando.yml.hbs +2 -10
- package/modules/lint/templates/package.json.hbs +4 -16
- package/modules/lint/templates/workspace.json.hbs +15 -56
- package/modules/php/prompts.js +2 -2
- package/modules/php/templates/.lando.yml.hbs +2 -11
- package/modules/php/templates/composer.json.hbs +1 -6
- package/modules/php/templates/workspace.json.hbs +15 -74
- package/modules/redis/prompts.js +2 -2
- package/modules/redis/templates/.lando.yml.hbs +1 -8
- package/modules/sage/index.js +115 -7
- package/modules/sage/prompts.js +3 -3
- package/modules/sage/templates/.lando.yml.hbs +20 -64
- package/modules/sage/templates/theme/composer.json.hbs +3 -18
- package/modules/sage/templates/theme/package.json.hbs +3 -11
- package/modules/sage/templates/theme/style.css.hbs +20 -13
- package/modules/sage/templates/theme/vite.config.js.hbs +13 -53
- package/modules/sage/templates/workspace.json.hbs +12 -67
- package/modules/test-directory/prompts.js +2 -2
- package/package.json +20 -1
- package/templates/.editorconfig.hbs +5 -39
- package/templates/.env.hbs +14 -35
- package/templates/.gitignore.hbs +13 -86
- package/templates/.lando.yml.hbs +11 -44
- package/templates/README.md.hbs +7 -8
- package/templates/composer.json.hbs +12 -60
- package/templates/server/cmd/install-wp.sh.hbs +43 -58
- package/templates/server/www/vhosts.conf.hbs +21 -71
- package/templates/workspace.json.hbs +40 -177
package/lib/core/generator.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
// lib/core/generator.js
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
2
|
import path from 'path';
|
|
4
|
-
import handlebars from 'handlebars';
|
|
5
3
|
import crypto from 'crypto';
|
|
4
|
+
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
import handlebars from 'handlebars';
|
|
6
7
|
import mergeWith from 'lodash.mergewith';
|
|
7
8
|
import yaml from 'js-yaml';
|
|
9
|
+
|
|
8
10
|
import { log, color } from '../utils/logger.js';
|
|
11
|
+
import {
|
|
12
|
+
PACKAGE_ROOT,
|
|
13
|
+
MODULES_PATH,
|
|
14
|
+
TEMPLATES_PATH,
|
|
15
|
+
getModulePath,
|
|
16
|
+
getModuleTemplatePath,
|
|
17
|
+
getBaseTemplatePath,
|
|
18
|
+
} from '../utils/paths.js';
|
|
19
|
+
|
|
9
20
|
import { HookManager } from './hook-manager.js';
|
|
10
|
-
import { PACKAGE_ROOT, MODULES_PATH, TEMPLATES_PATH, getModulePath, getModuleTemplatePath, getBaseTemplatePath } from '../utils/paths.js';
|
|
11
21
|
|
|
12
22
|
export class Generator {
|
|
13
23
|
constructor(baseDir = process.cwd()) {
|
|
@@ -15,10 +25,8 @@ export class Generator {
|
|
|
15
25
|
this.hooks = new HookManager();
|
|
16
26
|
}
|
|
17
27
|
|
|
18
|
-
async copyFile(sourcePathRelative, moduleName = null, outputName =
|
|
19
|
-
const baseDir = moduleName
|
|
20
|
-
? getModulePath(moduleName)
|
|
21
|
-
: PACKAGE_ROOT;
|
|
28
|
+
async copyFile(sourcePathRelative, moduleName = null, outputName = '') {
|
|
29
|
+
const baseDir = moduleName ? getModulePath(moduleName) : PACKAGE_ROOT;
|
|
22
30
|
|
|
23
31
|
outputName = outputName ? outputName : sourcePathRelative;
|
|
24
32
|
|
|
@@ -36,10 +44,8 @@ export class Generator {
|
|
|
36
44
|
* @param {string} outputName - Nome da pasta de destino (opcional)
|
|
37
45
|
* @param {boolean} overwrite - Se deve sobrescrever arquivos existentes (padrão: true)
|
|
38
46
|
*/
|
|
39
|
-
async copyDirectory(sourcePathRelative, moduleName = null, outputName =
|
|
40
|
-
const baseDir = moduleName
|
|
41
|
-
? getModulePath(moduleName)
|
|
42
|
-
: PACKAGE_ROOT;
|
|
47
|
+
async copyDirectory(sourcePathRelative, moduleName = null, outputName = '', overwrite = true) {
|
|
48
|
+
const baseDir = moduleName ? getModulePath(moduleName) : PACKAGE_ROOT;
|
|
43
49
|
|
|
44
50
|
outputName = outputName ? outputName : sourcePathRelative;
|
|
45
51
|
|
|
@@ -47,7 +53,7 @@ export class Generator {
|
|
|
47
53
|
const outputPath = path.join(this.cwd, outputName);
|
|
48
54
|
|
|
49
55
|
// Verifica se a pasta de origem existe
|
|
50
|
-
if (!await fs.pathExists(sourcePath)) {
|
|
56
|
+
if (!(await fs.pathExists(sourcePath))) {
|
|
51
57
|
throw new Error(`Source directory not found: ${sourcePath}`);
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -58,7 +64,7 @@ export class Generator {
|
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
// Se a pasta de destino não existe, copia tudo
|
|
61
|
-
if (!await fs.pathExists(outputPath)) {
|
|
67
|
+
if (!(await fs.pathExists(outputPath))) {
|
|
62
68
|
await fs.copy(sourcePath, outputPath);
|
|
63
69
|
log(color.blue, `📁 Directory copied: ${outputName}`);
|
|
64
70
|
return;
|
|
@@ -90,7 +96,7 @@ export class Generator {
|
|
|
90
96
|
|
|
91
97
|
if (stats.isDirectory()) {
|
|
92
98
|
// Se é uma pasta, cria se não existir e copia recursivamente
|
|
93
|
-
if (!await fs.pathExists(outputItemPath)) {
|
|
99
|
+
if (!(await fs.pathExists(outputItemPath))) {
|
|
94
100
|
await fs.mkdir(outputItemPath, { recursive: true });
|
|
95
101
|
}
|
|
96
102
|
await this._copyDirectoryContents(sourceItemPath, outputItemPath);
|
|
@@ -101,10 +107,8 @@ export class Generator {
|
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
async generateFile(templatePathRelative, context, moduleName = null, outputName =
|
|
105
|
-
const baseDir = moduleName
|
|
106
|
-
? getModuleTemplatePath(moduleName, '')
|
|
107
|
-
: TEMPLATES_PATH;
|
|
110
|
+
async generateFile(templatePathRelative, context, moduleName = null, outputName = '') {
|
|
111
|
+
const baseDir = moduleName ? getModuleTemplatePath(moduleName, '') : TEMPLATES_PATH;
|
|
108
112
|
|
|
109
113
|
outputName = outputName ? outputName : templatePathRelative;
|
|
110
114
|
|
|
@@ -129,16 +133,23 @@ export class Generator {
|
|
|
129
133
|
* @param {'json'|'yaml'} [options.format='yaml'] - Formato do arquivo
|
|
130
134
|
* @param {'concat'|'replace'} [options.mergeStrategy='concat'] - Estratégia de merge de arrays
|
|
131
135
|
*/
|
|
132
|
-
async generateModularFile({
|
|
136
|
+
async generateModularFile({
|
|
137
|
+
baseTemplate,
|
|
138
|
+
outputFile = '',
|
|
139
|
+
modules = [],
|
|
140
|
+
context = {},
|
|
141
|
+
format = 'yaml',
|
|
142
|
+
mergeStrategy = 'replace',
|
|
143
|
+
debug = false,
|
|
144
|
+
}) {
|
|
133
145
|
const baseTemplatePath = getBaseTemplatePath(baseTemplate + '.hbs');
|
|
134
146
|
const baseRaw = await fs.readFile(baseTemplatePath, 'utf8');
|
|
135
147
|
const compiledBase = handlebars.compile(baseRaw);
|
|
136
148
|
outputFile = outputFile ? outputFile : baseTemplate;
|
|
137
149
|
let mergedOutput;
|
|
138
150
|
try {
|
|
139
|
-
mergedOutput =
|
|
140
|
-
? JSON.parse(compiledBase(context))
|
|
141
|
-
: yaml.load(compiledBase(context));
|
|
151
|
+
mergedOutput =
|
|
152
|
+
format === 'json' ? JSON.parse(compiledBase(context)) : yaml.load(compiledBase(context));
|
|
142
153
|
} catch (err) {
|
|
143
154
|
if (debug) {
|
|
144
155
|
log(color.red, '[DEBUG] Erro ao fazer parse do template base:');
|
|
@@ -150,9 +161,7 @@ export class Generator {
|
|
|
150
161
|
|
|
151
162
|
function customizer(objValue, srcValue) {
|
|
152
163
|
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
|
|
153
|
-
return mergeStrategy === 'concat'
|
|
154
|
-
? objValue.concat(srcValue)
|
|
155
|
-
: srcValue;
|
|
164
|
+
return mergeStrategy === 'concat' ? objValue.concat(srcValue) : srcValue;
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
167
|
|
|
@@ -164,9 +173,8 @@ export class Generator {
|
|
|
164
173
|
const compiledMod = handlebars.compile(modRaw);
|
|
165
174
|
let modParsed;
|
|
166
175
|
try {
|
|
167
|
-
modParsed =
|
|
168
|
-
? JSON.parse(compiledMod(context))
|
|
169
|
-
: yaml.load(compiledMod(context));
|
|
176
|
+
modParsed =
|
|
177
|
+
format === 'json' ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
|
|
170
178
|
} catch (err) {
|
|
171
179
|
if (debug) {
|
|
172
180
|
log(color.red, `[DEBUG] Erro ao fazer parse do template do módulo ${mod}:`);
|
|
@@ -179,16 +187,25 @@ export class Generator {
|
|
|
179
187
|
}
|
|
180
188
|
}
|
|
181
189
|
|
|
182
|
-
const finalOutput =
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
const finalOutput =
|
|
191
|
+
format === 'json'
|
|
192
|
+
? JSON.stringify(mergedOutput, null, 2)
|
|
193
|
+
: yaml.dump(mergedOutput, { lineWidth: 120 });
|
|
185
194
|
|
|
186
195
|
const outputPath = path.join(this.cwd, outputFile);
|
|
187
196
|
await fs.outputFile(outputPath, finalOutput);
|
|
188
197
|
log(color.blue, `🧩 Modular file generated: ${outputFile}`);
|
|
189
198
|
}
|
|
190
199
|
|
|
191
|
-
async mergeWithExistingFile({
|
|
200
|
+
async mergeWithExistingFile({
|
|
201
|
+
existingFile,
|
|
202
|
+
moduleTemplatePath,
|
|
203
|
+
context,
|
|
204
|
+
format = 'json',
|
|
205
|
+
moduleName = null,
|
|
206
|
+
mergeStrategy = 'replace',
|
|
207
|
+
debug = false,
|
|
208
|
+
}) {
|
|
192
209
|
const existingPath = path.isAbsolute(existingFile)
|
|
193
210
|
? existingFile
|
|
194
211
|
: path.resolve(this.cwd, existingFile);
|
|
@@ -211,18 +228,15 @@ export class Generator {
|
|
|
211
228
|
throw err;
|
|
212
229
|
}
|
|
213
230
|
|
|
214
|
-
const moduleBase = moduleName
|
|
215
|
-
? getModuleTemplatePath(moduleName, '')
|
|
216
|
-
: TEMPLATES_PATH;
|
|
231
|
+
const moduleBase = moduleName ? getModuleTemplatePath(moduleName, '') : TEMPLATES_PATH;
|
|
217
232
|
const templatePath = path.resolve(moduleBase, moduleTemplatePath + '.hbs');
|
|
218
233
|
|
|
219
234
|
const modRaw = await fs.readFile(templatePath, 'utf8');
|
|
220
235
|
const compiledMod = handlebars.compile(modRaw);
|
|
221
236
|
let modParsed;
|
|
222
237
|
try {
|
|
223
|
-
modParsed =
|
|
224
|
-
? JSON.parse(compiledMod(context))
|
|
225
|
-
: yaml.load(compiledMod(context));
|
|
238
|
+
modParsed =
|
|
239
|
+
format === 'json' ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
|
|
226
240
|
} catch (err) {
|
|
227
241
|
if (debug) {
|
|
228
242
|
log(color.red, '[DEBUG] Erro ao fazer parse do template do módulo:');
|
|
@@ -234,17 +248,14 @@ export class Generator {
|
|
|
234
248
|
|
|
235
249
|
function customizer(objValue, srcValue) {
|
|
236
250
|
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
|
|
237
|
-
return mergeStrategy === 'concat'
|
|
238
|
-
? objValue.concat(srcValue)
|
|
239
|
-
: srcValue;
|
|
251
|
+
return mergeStrategy === 'concat' ? objValue.concat(srcValue) : srcValue;
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
254
|
|
|
243
255
|
const merged = mergeWith({}, existingParsed, modParsed, customizer);
|
|
244
256
|
|
|
245
|
-
const output =
|
|
246
|
-
? JSON.stringify(merged, null, 2)
|
|
247
|
-
: yaml.dump(merged, { lineWidth: 120 });
|
|
257
|
+
const output =
|
|
258
|
+
format === 'json' ? JSON.stringify(merged, null, 2) : yaml.dump(merged, { lineWidth: 120 });
|
|
248
259
|
|
|
249
260
|
await fs.outputFile(existingPath, output);
|
|
250
261
|
log(color.blue, `🔀 Merged into: ${existingPath}`);
|
|
@@ -252,8 +263,14 @@ export class Generator {
|
|
|
252
263
|
|
|
253
264
|
static generateSalts() {
|
|
254
265
|
return [
|
|
255
|
-
'AUTH_KEY',
|
|
256
|
-
'
|
|
266
|
+
'AUTH_KEY',
|
|
267
|
+
'SECURE_AUTH_KEY',
|
|
268
|
+
'LOGGED_IN_KEY',
|
|
269
|
+
'NONCE_KEY',
|
|
270
|
+
'AUTH_SALT',
|
|
271
|
+
'SECURE_AUTH_SALT',
|
|
272
|
+
'LOGGED_IN_SALT',
|
|
273
|
+
'NONCE_SALT',
|
|
257
274
|
].reduce((acc, key) => {
|
|
258
275
|
acc[key] = crypto.randomBytes(64).toString('base64');
|
|
259
276
|
return acc;
|
package/lib/core/hook-manager.js
CHANGED
|
@@ -26,7 +26,7 @@ export class HookManager {
|
|
|
26
26
|
hook.push({
|
|
27
27
|
callback,
|
|
28
28
|
priority,
|
|
29
|
-
acceptedArgs
|
|
29
|
+
acceptedArgs,
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
// Ordena por prioridade (menor número = maior prioridade)
|
|
@@ -117,7 +117,7 @@ export class HookManager {
|
|
|
117
117
|
|
|
118
118
|
const hook = this.hooks.get(hookName);
|
|
119
119
|
const index = hook.findIndex(
|
|
120
|
-
item => item.callback === callback && item.priority === priority
|
|
120
|
+
(item) => item.callback === callback && item.priority === priority
|
|
121
121
|
);
|
|
122
122
|
|
|
123
123
|
if (index !== -1) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
|
|
2
3
|
import fs from 'fs-extra';
|
|
3
4
|
|
|
4
5
|
function fileExists(filePath) {
|
|
@@ -14,7 +15,7 @@ function detectThemePaths(context, hasSage) {
|
|
|
14
15
|
const candidates = [
|
|
15
16
|
path.join(context.cwd, 'content', 'themes', projectName),
|
|
16
17
|
path.join(context.cwd, 'web', 'app', 'themes', projectName),
|
|
17
|
-
path.join(context.cwd, 'wp-content', 'themes', projectName)
|
|
18
|
+
path.join(context.cwd, 'wp-content', 'themes', projectName),
|
|
18
19
|
];
|
|
19
20
|
|
|
20
21
|
for (const abs of candidates) {
|
|
@@ -26,10 +27,7 @@ function detectThemePaths(context, hasSage) {
|
|
|
26
27
|
packageJson: path.join(abs, 'package.json'),
|
|
27
28
|
composerJson: path.join(abs, 'composer.json'),
|
|
28
29
|
// Bud/Sage pode gerar em public/ ou dist/
|
|
29
|
-
distCandidates: [
|
|
30
|
-
path.join(rel, 'public'),
|
|
31
|
-
path.join(rel, 'dist')
|
|
32
|
-
]
|
|
30
|
+
distCandidates: [path.join(rel, 'public'), path.join(rel, 'dist')],
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
33
|
}
|
|
@@ -43,10 +41,7 @@ function detectThemePaths(context, hasSage) {
|
|
|
43
41
|
themeRoot: rel,
|
|
44
42
|
packageJson: path.join(abs, 'package.json'),
|
|
45
43
|
composerJson: path.join(abs, 'composer.json'),
|
|
46
|
-
distCandidates: [
|
|
47
|
-
path.join(rel, 'public'),
|
|
48
|
-
path.join(rel, 'dist')
|
|
49
|
-
]
|
|
44
|
+
distCandidates: [path.join(rel, 'public'), path.join(rel, 'dist')],
|
|
50
45
|
};
|
|
51
46
|
}
|
|
52
47
|
|
|
@@ -55,7 +50,7 @@ function detectThemePaths(context, hasSage) {
|
|
|
55
50
|
themeRoot: null,
|
|
56
51
|
packageJson: null,
|
|
57
52
|
composerJson: null,
|
|
58
|
-
distCandidates: []
|
|
53
|
+
distCandidates: [],
|
|
59
54
|
};
|
|
60
55
|
}
|
|
61
56
|
|
|
@@ -70,13 +65,9 @@ export function inferCiCapabilities(context) {
|
|
|
70
65
|
const existsRootPackage = fileExists(rootPackage);
|
|
71
66
|
const existsThemePackage = Boolean(theme.packageJson && fileExists(theme.packageJson));
|
|
72
67
|
|
|
73
|
-
const hasComposer = Boolean(
|
|
74
|
-
existsRootComposer || existsThemeComposer || hasSage
|
|
75
|
-
);
|
|
68
|
+
const hasComposer = Boolean(existsRootComposer || existsThemeComposer || hasSage);
|
|
76
69
|
|
|
77
|
-
const hasNode = Boolean(
|
|
78
|
-
existsRootPackage || existsThemePackage || hasSage
|
|
79
|
-
);
|
|
70
|
+
const hasNode = Boolean(existsRootPackage || existsThemePackage || hasSage);
|
|
80
71
|
|
|
81
72
|
let nodeVersion = context.nodeVersion;
|
|
82
73
|
if (!nodeVersion) {
|
|
@@ -91,29 +82,27 @@ export function inferCiCapabilities(context) {
|
|
|
91
82
|
build: {
|
|
92
83
|
composer: hasComposer,
|
|
93
84
|
node: hasNode,
|
|
94
|
-
sage: hasSage
|
|
85
|
+
sage: hasSage,
|
|
95
86
|
},
|
|
96
87
|
deploy: {
|
|
97
|
-
docker: context.deploy_strategy === 'docker'
|
|
88
|
+
docker: context.deploy_strategy === 'docker',
|
|
98
89
|
},
|
|
99
90
|
nodeVersion,
|
|
100
91
|
theme: {
|
|
101
|
-
paths: theme
|
|
92
|
+
paths: theme,
|
|
102
93
|
},
|
|
103
94
|
detect: {
|
|
104
95
|
existsRootComposer,
|
|
105
96
|
existsThemeComposer,
|
|
106
97
|
existsRootPackage,
|
|
107
98
|
existsThemePackage,
|
|
108
|
-
themeRootExists: Boolean(theme.themeRootAbs && fileExists(theme.themeRootAbs))
|
|
99
|
+
themeRootExists: Boolean(theme.themeRootAbs && fileExists(theme.themeRootAbs)),
|
|
109
100
|
},
|
|
110
101
|
cache: {
|
|
111
102
|
packageGlobs: ['**/package.json'],
|
|
112
|
-
composerGlobs: ['**/composer.json']
|
|
113
|
-
}
|
|
103
|
+
composerGlobs: ['**/composer.json'],
|
|
104
|
+
},
|
|
114
105
|
};
|
|
115
106
|
|
|
116
107
|
return ci;
|
|
117
108
|
}
|
|
118
|
-
|
|
119
|
-
|
package/lib/prompts/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// lib/prompts/index.js
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
|
+
|
|
3
4
|
import { getGitUserDefaults } from '../utils/git.js';
|
|
4
|
-
import { loadModulePrompts } from './loadModulePrompts.js';
|
|
5
5
|
import { Generator } from '../core/generator.js';
|
|
6
6
|
|
|
7
|
+
import { loadModulePrompts } from './loadModulePrompts.js';
|
|
8
|
+
|
|
7
9
|
export async function runPrompts({ defaults = false } = {}) {
|
|
8
10
|
const defaultsGit = getGitUserDefaults();
|
|
9
11
|
|
|
@@ -12,71 +14,71 @@ export async function runPrompts({ defaults = false } = {}) {
|
|
|
12
14
|
type: 'input',
|
|
13
15
|
name: 'projectName',
|
|
14
16
|
message: 'Project name:',
|
|
15
|
-
default: 'wordpress-dev'
|
|
17
|
+
default: 'wordpress-dev',
|
|
16
18
|
},
|
|
17
19
|
{
|
|
18
20
|
type: 'input',
|
|
19
21
|
name: 'projectDescription',
|
|
20
22
|
message: 'Project description:',
|
|
21
|
-
default: 'Generated with wp-devops'
|
|
23
|
+
default: 'Generated with wp-devops',
|
|
22
24
|
},
|
|
23
25
|
{
|
|
24
26
|
type: 'input',
|
|
25
27
|
name: 'projectVersion',
|
|
26
28
|
message: 'Project version:',
|
|
27
|
-
default: '1.0.0'
|
|
29
|
+
default: '1.0.0',
|
|
28
30
|
},
|
|
29
31
|
{
|
|
30
32
|
type: 'input',
|
|
31
33
|
name: 'author',
|
|
32
34
|
message: 'Author:',
|
|
33
|
-
default: defaultsGit.author
|
|
35
|
+
default: defaultsGit.author,
|
|
34
36
|
},
|
|
35
37
|
{
|
|
36
38
|
type: 'input',
|
|
37
39
|
name: 'authorEmail',
|
|
38
40
|
message: 'Author email:',
|
|
39
|
-
default: defaultsGit.authorEmail
|
|
41
|
+
default: defaultsGit.authorEmail,
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
type: 'input',
|
|
43
45
|
name: 'gitRepository',
|
|
44
46
|
message: 'Repository URL:',
|
|
45
|
-
default: defaultsGit.gitRepository
|
|
47
|
+
default: defaultsGit.gitRepository,
|
|
46
48
|
},
|
|
47
49
|
{
|
|
48
50
|
type: 'list',
|
|
49
51
|
name: 'phpVersion',
|
|
50
52
|
message: 'PHP version:',
|
|
51
|
-
choices: ['8.3', '8.2', '8.1'
|
|
52
|
-
default: '8.3'
|
|
53
|
+
choices: ['8.3', '8.2', '8.1'],
|
|
54
|
+
default: '8.3',
|
|
53
55
|
},
|
|
54
56
|
{
|
|
55
57
|
type: 'list',
|
|
56
58
|
name: 'nodeVersion',
|
|
57
59
|
message: 'Node.js version:',
|
|
58
|
-
choices: ['22', '
|
|
59
|
-
default: '22'
|
|
60
|
+
choices: ['22', '20', '18'],
|
|
61
|
+
default: '22',
|
|
60
62
|
},
|
|
61
63
|
{
|
|
62
64
|
type: 'list',
|
|
63
65
|
name: 'wpCoreVersion',
|
|
64
66
|
message: 'WordPress core version:',
|
|
65
|
-
choices: ['6.
|
|
66
|
-
default: '6.
|
|
67
|
+
choices: ['6.9.4', '6.8.1', '6.7', '6.6'],
|
|
68
|
+
default: '6.9.4',
|
|
67
69
|
},
|
|
68
70
|
{
|
|
69
71
|
type: 'confirm',
|
|
70
72
|
name: 'useRocket',
|
|
71
73
|
message: 'Use WP Rocket?',
|
|
72
|
-
default: true
|
|
74
|
+
default: true,
|
|
73
75
|
},
|
|
74
76
|
{
|
|
75
77
|
type: 'confirm',
|
|
76
78
|
name: 'enableDebug',
|
|
77
79
|
message: 'Enable debug mode?',
|
|
78
|
-
default: false
|
|
79
|
-
}
|
|
80
|
+
default: false,
|
|
81
|
+
},
|
|
80
82
|
];
|
|
81
83
|
|
|
82
84
|
const modulePromptDefs = await loadModulePrompts();
|
|
@@ -84,7 +86,7 @@ export async function runPrompts({ defaults = false } = {}) {
|
|
|
84
86
|
const allPrompts = [...corePrompts, ...modulePrompts];
|
|
85
87
|
|
|
86
88
|
if (defaults) {
|
|
87
|
-
const defaultAnswers = {
|
|
89
|
+
const defaultAnswers = {};
|
|
88
90
|
for (const prompt of allPrompts) {
|
|
89
91
|
if (prompt.when && !prompt.when(defaultAnswers)) continue;
|
|
90
92
|
const def = prompt.default;
|
|
@@ -93,7 +95,12 @@ export async function runPrompts({ defaults = false } = {}) {
|
|
|
93
95
|
const enabledModules = Object.keys(modulePromptDefs).filter(
|
|
94
96
|
(mod) => defaultAnswers[`enable_${mod}`] === true
|
|
95
97
|
);
|
|
96
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
...defaultAnswers,
|
|
100
|
+
enabledModules,
|
|
101
|
+
projectDomain: `${defaultAnswers.projectName}.lndo.site`,
|
|
102
|
+
salts: Generator.generateSalts(),
|
|
103
|
+
};
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
const answers = await inquirer.prompt(allPrompts);
|
|
@@ -101,5 +108,10 @@ export async function runPrompts({ defaults = false } = {}) {
|
|
|
101
108
|
const enabledModules = Object.keys(modulePromptDefs).filter(
|
|
102
109
|
(mod) => answers[`enable_${mod}`] === true
|
|
103
110
|
);
|
|
104
|
-
return {
|
|
111
|
+
return {
|
|
112
|
+
...answers,
|
|
113
|
+
enabledModules,
|
|
114
|
+
projectDomain: `${answers.projectName}.lndo.site`,
|
|
115
|
+
salts: Generator.generateSalts(),
|
|
116
|
+
};
|
|
105
117
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
1
|
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
|
|
3
5
|
import { MODULES_PATH } from '../utils/paths.js';
|
|
4
6
|
|
|
5
7
|
export async function loadModulePrompts(modulesDir = MODULES_PATH) {
|
|
@@ -19,7 +21,7 @@ export async function loadModulePrompts(modulesDir = MODULES_PATH) {
|
|
|
19
21
|
name: `enable_${name}`,
|
|
20
22
|
message: `Enable ${name} module?`,
|
|
21
23
|
default: false,
|
|
22
|
-
}
|
|
24
|
+
},
|
|
23
25
|
];
|
|
24
26
|
}
|
|
25
27
|
}
|
package/modules/deploy/index.js
CHANGED
|
@@ -14,23 +14,50 @@ export async function setupModule(context, generator) {
|
|
|
14
14
|
log(color.green, '[deploy] .gitlab-ci.yml gerado com sucesso.');
|
|
15
15
|
}
|
|
16
16
|
if (context.gitProvider === 'github') {
|
|
17
|
-
await generator.generateFile(
|
|
17
|
+
await generator.generateFile(
|
|
18
|
+
'.github/workflows/ci.yml',
|
|
19
|
+
context,
|
|
20
|
+
'deploy',
|
|
21
|
+
'.github/workflows/ci.yml'
|
|
22
|
+
);
|
|
18
23
|
log(color.green, '[deploy] GitHub Actions workflow gerado com sucesso.');
|
|
19
24
|
}
|
|
20
25
|
if (context.gitProvider === 'bitbucket') {
|
|
21
|
-
await generator.generateFile(
|
|
26
|
+
await generator.generateFile(
|
|
27
|
+
'bitbucket-pipelines.yml',
|
|
28
|
+
context,
|
|
29
|
+
'deploy',
|
|
30
|
+
'bitbucket-pipelines.yml'
|
|
31
|
+
);
|
|
22
32
|
log(color.green, '[deploy] Bitbucket Pipelines gerado com sucesso.');
|
|
23
33
|
}
|
|
24
34
|
// Avisos inteligentes
|
|
25
35
|
if (context.ci) {
|
|
26
|
-
if (
|
|
27
|
-
|
|
36
|
+
if (
|
|
37
|
+
context.ci.build.composer &&
|
|
38
|
+
!context.ci.detect.existsRootComposer &&
|
|
39
|
+
!context.ci.detect.existsThemeComposer
|
|
40
|
+
) {
|
|
41
|
+
log(
|
|
42
|
+
color.orange,
|
|
43
|
+
'[deploy] Aviso: Build de Composer habilitado, mas nenhum composer.json encontrado.'
|
|
44
|
+
);
|
|
28
45
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
46
|
+
if (
|
|
47
|
+
context.ci.build.node &&
|
|
48
|
+
!context.ci.detect.existsRootPackage &&
|
|
49
|
+
!context.ci.detect.existsThemePackage
|
|
50
|
+
) {
|
|
51
|
+
log(
|
|
52
|
+
color.orange,
|
|
53
|
+
'[deploy] Aviso: Build de Node habilitado, mas nenhum package.json encontrado.'
|
|
54
|
+
);
|
|
31
55
|
}
|
|
32
56
|
if (context.ci.build.sage && !context.ci.detect.themeRootExists) {
|
|
33
|
-
log(
|
|
57
|
+
log(
|
|
58
|
+
color.orange,
|
|
59
|
+
'[deploy] Aviso: Sage habilitado, mas diretório do tema não foi encontrado.'
|
|
60
|
+
);
|
|
34
61
|
}
|
|
35
62
|
}
|
|
36
63
|
} catch (err) {
|
|
@@ -3,7 +3,7 @@ export default [
|
|
|
3
3
|
type: 'confirm',
|
|
4
4
|
name: 'enable_deploy',
|
|
5
5
|
message: 'Habilitar Pipelines de CI/CD?',
|
|
6
|
-
default: true
|
|
6
|
+
default: true,
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
9
|
type: 'list',
|
|
@@ -12,16 +12,16 @@ export default [
|
|
|
12
12
|
choices: [
|
|
13
13
|
{
|
|
14
14
|
name: 'Docker',
|
|
15
|
-
value: 'docker'
|
|
15
|
+
value: 'docker',
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
name: 'SSH',
|
|
19
19
|
value: 'ssh',
|
|
20
20
|
disabled: true,
|
|
21
|
-
description: 'Em breve'
|
|
22
|
-
}
|
|
21
|
+
description: 'Em breve',
|
|
22
|
+
},
|
|
23
23
|
],
|
|
24
24
|
default: 'docker',
|
|
25
25
|
when: (answers) => answers.enable_deploy,
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
27
|
];
|