@codigodoleo/wp-kit 2.0.2 → 2.0.4

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.php ADDED
@@ -0,0 +1,17 @@
1
+ <?php
2
+ /**
3
+ * Front to the WordPress application. This file doesn't do anything, but loads
4
+ * wp-blog-header.php which does and tells WordPress to load the theme.
5
+ *
6
+ * @package WordPress
7
+ */
8
+
9
+ /**
10
+ * Tells WordPress to load the WordPress theme and output it.
11
+ *
12
+ * @var bool
13
+ */
14
+ define( 'WP_USE_THEMES', true );
15
+
16
+ /** Loads the WordPress Environment and Template */
17
+ require __DIR__ . '/wp/wp-blog-header.php';
@@ -7,6 +7,7 @@ import mergeWith from 'lodash.mergewith';
7
7
  import yaml from 'js-yaml';
8
8
  import { log, color } from '../utils/logger.js';
9
9
  import { HookManager } from './hook-manager.js';
10
+ import { PACKAGE_ROOT, MODULES_PATH, TEMPLATES_PATH, getModulePath, getModuleTemplatePath, getBaseTemplatePath } from '../utils/paths.js';
10
11
 
11
12
  export class Generator {
12
13
  constructor(baseDir = process.cwd()) {
@@ -16,8 +17,8 @@ export class Generator {
16
17
 
17
18
  async copyFile(sourcePathRelative, moduleName = null, outputName = "") {
18
19
  const baseDir = moduleName
19
- ? path.resolve('modules', moduleName)
20
- : path.resolve();
20
+ ? getModulePath(moduleName)
21
+ : PACKAGE_ROOT;
21
22
 
22
23
  outputName = outputName ? outputName : sourcePathRelative;
23
24
 
@@ -37,8 +38,8 @@ export class Generator {
37
38
  */
38
39
  async copyDirectory(sourcePathRelative, moduleName = null, outputName = "", overwrite = true) {
39
40
  const baseDir = moduleName
40
- ? path.resolve('modules', moduleName)
41
- : path.resolve();
41
+ ? getModulePath(moduleName)
42
+ : PACKAGE_ROOT;
42
43
 
43
44
  outputName = outputName ? outputName : sourcePathRelative;
44
45
 
@@ -102,8 +103,8 @@ export class Generator {
102
103
 
103
104
  async generateFile(templatePathRelative, context, moduleName = null, outputName = "") {
104
105
  const baseDir = moduleName
105
- ? path.resolve('modules', moduleName, 'templates')
106
- : path.resolve('templates');
106
+ ? getModuleTemplatePath(moduleName, '')
107
+ : TEMPLATES_PATH;
107
108
 
108
109
  outputName = outputName ? outputName : templatePathRelative;
109
110
 
@@ -129,7 +130,7 @@ export class Generator {
129
130
  * @param {'concat'|'replace'} [options.mergeStrategy='concat'] - Estratégia de merge de arrays
130
131
  */
131
132
  async generateModularFile({ baseTemplate, outputFile = "", modules = [], context = {}, format = 'yaml', mergeStrategy = 'replace', debug = false }) {
132
- const baseTemplatePath = path.resolve('templates', baseTemplate + '.hbs');
133
+ const baseTemplatePath = getBaseTemplatePath(baseTemplate + '.hbs');
133
134
  const baseRaw = await fs.readFile(baseTemplatePath, 'utf8');
134
135
  const compiledBase = handlebars.compile(baseRaw);
135
136
  outputFile = outputFile ? outputFile : baseTemplate;
@@ -156,7 +157,7 @@ export class Generator {
156
157
  }
157
158
 
158
159
  for (const mod of modules) {
159
- const modPath = path.resolve('modules', mod, 'templates', path.basename(baseTemplate) + '.hbs');
160
+ const modPath = getModuleTemplatePath(mod, path.basename(baseTemplate) + '.hbs');
160
161
 
161
162
  if (await fs.pathExists(modPath)) {
162
163
  const modRaw = await fs.readFile(modPath, 'utf8');
@@ -211,8 +212,8 @@ export class Generator {
211
212
  }
212
213
 
213
214
  const moduleBase = moduleName
214
- ? path.resolve('modules', moduleName, 'templates')
215
- : path.resolve('templates');
215
+ ? getModuleTemplatePath(moduleName, '')
216
+ : TEMPLATES_PATH;
216
217
  const templatePath = path.resolve(moduleBase, moduleTemplatePath + '.hbs');
217
218
 
218
219
  const modRaw = await fs.readFile(templatePath, 'utf8');
@@ -1,7 +1,8 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
+ import { MODULES_PATH } from '../utils/paths.js';
3
4
 
4
- export async function loadModulePrompts(modulesDir = 'modules') {
5
+ export async function loadModulePrompts(modulesDir = MODULES_PATH) {
5
6
  const modules = await fs.readdir(modulesDir);
6
7
  const promptsMap = {};
7
8
 
@@ -0,0 +1,29 @@
1
+ // lib/utils/paths.js
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ // Caminho base do pacote (raiz do projeto)
9
+ export const PACKAGE_ROOT = path.resolve(__dirname, '../..');
10
+
11
+ // Caminhos principais
12
+ export const MODULES_PATH = path.join(PACKAGE_ROOT, 'modules');
13
+ export const TEMPLATES_PATH = path.join(PACKAGE_ROOT, 'templates');
14
+ export const SERVER_PATH = path.join(PACKAGE_ROOT, 'server');
15
+
16
+ // Função auxiliar para resolver caminhos de módulos
17
+ export function getModulePath(moduleName) {
18
+ return path.join(MODULES_PATH, moduleName);
19
+ }
20
+
21
+ // Função auxiliar para resolver templates de módulos
22
+ export function getModuleTemplatePath(moduleName, templateName) {
23
+ return path.join(MODULES_PATH, moduleName, 'templates', templateName);
24
+ }
25
+
26
+ // Função auxiliar para resolver templates base
27
+ export function getBaseTemplatePath(templateName) {
28
+ return path.join(TEMPLATES_PATH, templateName);
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codigodoleo/wp-kit",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Kit opinativo para padronizar projetos WordPress com CI/CD dinâmico.",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -16,6 +16,8 @@
16
16
  "modules/",
17
17
  "templates/",
18
18
  "server/",
19
+ "wp-config.php",
20
+ "index.php",
19
21
  ".cspell.json",
20
22
  ".gitkeep"
21
23
  ],
package/wp-config.php ADDED
@@ -0,0 +1,190 @@
1
+ <?php
2
+
3
+ /**
4
+ * The base configuration for WordPress
5
+ *
6
+ * The wp-config.php creation script uses this file during the installation.
7
+ * You don't have to use the website, you can copy this file to "wp-config.php"
8
+ * and fill in the values.
9
+ *
10
+ * This file contains the following configurations:
11
+ *
12
+ * * Database settings
13
+ * * Secret keys
14
+ * * Database table prefix
15
+ * * ABSPATH
16
+ *
17
+ * This has been slightly modified (to read environment variables) for use in Docker.
18
+ *
19
+ * @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
20
+ *
21
+ * @package WordPress
22
+ */
23
+
24
+ // ** Load Composer autoload ** //
25
+ if (file_exists(__DIR__ . '/vendor/autoload.php')) {
26
+ require_once __DIR__ . '/vendor/autoload.php';
27
+ } else {
28
+ die('Error: Composer autoload not found.');
29
+ }
30
+
31
+
32
+ // ** Carregar o .env para variáveis de ambiente ** //
33
+ $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
34
+ $dotenv->safeLoad();
35
+ $requiredEnvs = ['WORDPRESS_DB_NAME', 'WORDPRESS_DB_USER', 'WORDPRESS_DB_PASSWORD', 'WORDPRESS_DB_HOST', 'WORDPRESS_SITE_URL'];
36
+ $dotenv->required($requiredEnvs);
37
+
38
+ // a helper function to lookup "env_FILE", "env", then fallback
39
+ if (!function_exists('getenv_docker')) {
40
+ // https://github.com/docker-library/wordpress/issues/588 (WP-CLI will load this file 2x)
41
+ function getenv_docker($env, $default)
42
+ {
43
+ if (getenv('LANDO_INFO')) {
44
+ // Lando-specific environment variable
45
+ return $_ENV[$env] ?? $default;
46
+ } else if ($fileEnv = getenv($env . '_FILE')) {
47
+ return rtrim(file_get_contents($fileEnv), "\r\n");
48
+ } else if (($val = getenv($env)) !== false) {
49
+ return $val;
50
+ } else {
51
+ return $default;
52
+ }
53
+ }
54
+ }
55
+
56
+ // ** Database settings - You can get this info from your web host ** //
57
+ /** The name of the database for WordPress */
58
+ define('DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'wordpress'));
59
+
60
+ /** Database username */
61
+ define('DB_USER', getenv_docker('WORDPRESS_DB_USER', 'example username'));
62
+
63
+ /** Database password */
64
+ define('DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'example password'));
65
+
66
+ /**
67
+ * Docker image fallback values above are sourced from the official WordPress installation wizard:
68
+ * https://github.com/WordPress/WordPress/blob/1356f6537220ffdc32b9dad2a6cdbe2d010b7a88/wp-admin/setup-config.php#L224-L238
69
+ * (However, using "example username" and "example password" in your database is strongly discouraged. Please use strong, random credentials!)
70
+ */
71
+
72
+ /** Database hostname */
73
+ define('DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql'));
74
+
75
+ /** Database charset to use in creating database tables. */
76
+ define('DB_CHARSET', getenv_docker('WORDPRESS_DB_CHARSET', 'utf8'));
77
+
78
+ /** The database collate type. Don't change this if in doubt. */
79
+ define('DB_COLLATE', getenv_docker('WORDPRESS_DB_COLLATE', ''));
80
+
81
+ /**#@+
82
+ * Authentication unique keys and salts.
83
+ *
84
+ * Change these to different unique phrases! You can generate these using
85
+ * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
86
+ *
87
+ * You can change these at any point in time to invalidate all existing cookies.
88
+ * This will force all users to have to log in again.
89
+ *
90
+ * @since 2.6.0
91
+ */
92
+ define('AUTH_KEY', getenv_docker('WORDPRESS_AUTH_KEY', 'put your unique phrase here'));
93
+ define('SECURE_AUTH_KEY', getenv_docker('WORDPRESS_SECURE_AUTH_KEY', 'put your unique phrase here'));
94
+ define('LOGGED_IN_KEY', getenv_docker('WORDPRESS_LOGGED_IN_KEY', 'put your unique phrase here'));
95
+ define('NONCE_KEY', getenv_docker('WORDPRESS_NONCE_KEY', 'put your unique phrase here'));
96
+ define('AUTH_SALT', getenv_docker('WORDPRESS_AUTH_SALT', 'put your unique phrase here'));
97
+ define('SECURE_AUTH_SALT', getenv_docker('WORDPRESS_SECURE_AUTH_SALT', 'put your unique phrase here'));
98
+ define('LOGGED_IN_SALT', getenv_docker('WORDPRESS_LOGGED_IN_SALT', 'put your unique phrase here'));
99
+ define('NONCE_SALT', getenv_docker('WORDPRESS_NONCE_SALT', 'put your unique phrase here'));
100
+ // (See also https://wordpress.stackexchange.com/a/152905/199287)
101
+
102
+ /**#@-*/
103
+
104
+ /**
105
+ * WordPress database table prefix.
106
+ *
107
+ * You can have multiple installations in one database if you give each
108
+ * a unique prefix. Only numbers, letters, and underscores please!
109
+ *
110
+ * At the installation time, database tables are created with the specified prefix.
111
+ * Changing this value after WordPress is installed will make your site think
112
+ * it has not been installed.
113
+ *
114
+ * @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
115
+ */
116
+ $table_prefix = getenv_docker('WORDPRESS_TABLE_PREFIX', 'wp_');
117
+
118
+ /**
119
+ * For developers: WordPress debugging mode.
120
+ *
121
+ * Change this to true to enable the display of notices during development.
122
+ * It is strongly recommended that plugin and theme developers use WP_DEBUG
123
+ * in their development environments.
124
+ *
125
+ * For information on other constants that can be used for debugging,
126
+ * visit the documentation.
127
+ *
128
+ * @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
129
+ */
130
+ define('WP_DEBUG', !!getenv_docker('WORDPRESS_DEBUG', ''));
131
+
132
+ /* Add any custom values between this line and the "stop editing" line. */
133
+
134
+ // If we're running in a Docker container, we need to set the HTTP_HOST and SERVER_PORT
135
+ // to empty strings, otherwise WordPress will try to use the container name as the host.
136
+ // This is necessary for WordPress to work correctly in a Docker environment.
137
+ // This is a workaround for the issue where WordPress tries to use the container name as the host,
138
+ // which can cause issues with SSL and other configurations.
139
+ if (defined('WP_CLI') && constant('WP_CLI')) {
140
+ $_SERVER["HTTP_HOST"] = "";
141
+ $_SERVER['SERVER_PORT'] = 80;
142
+ }
143
+
144
+ // If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
145
+ // see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy
146
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
147
+ $_SERVER['HTTPS'] = 'on';
148
+ }
149
+
150
+ /** URL routing (Optional, may not be necessary) */
151
+ $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
152
+ $siteUrl = getenv_docker('WORDPRESS_SITE_URL', 'localhost');
153
+ $siteUrl = (strpos($siteUrl, 'http') === 0) ? $siteUrl : $protocol . $siteUrl;
154
+ define('WP_HOME', $siteUrl);
155
+ define('WP_SITEURL', $siteUrl . '/wp');
156
+
157
+ // Define the content directory and URL
158
+ // This is where your themes, plugins, and uploads will be stored.
159
+ // The default is to use the "content" directory in the same directory as this file.
160
+ // If you want to use a different directory, you can change the path below.
161
+ // Note: This is not the same as the "wp-content" directory, which is the default location for WordPress content.
162
+ define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/content' );
163
+ define( 'WP_CONTENT_URL', 'https://' . $_SERVER['HTTP_HOST'] . '/content' );
164
+
165
+ // Load all WordPress environment variables from the .env file
166
+ $wordpressEnvs = array_filter($_ENV, function ($key) {
167
+ return strpos($key, 'WORDPRESS_') === 0;
168
+ }, ARRAY_FILTER_USE_KEY);
169
+
170
+ // Define all remaining WordPress environment variables
171
+ foreach ($wordpressEnvs as $key => $value) {
172
+ $key = str_replace('WORDPRESS_', '', $key);
173
+ if (!defined($key))
174
+ define($key, $value);
175
+ }
176
+
177
+ // If there's a WORDPRESS_CONFIG_EXTRA environment variable, evaluate it
178
+ if ($configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '')) {
179
+ eval($configExtra);
180
+ }
181
+
182
+ /* That's all, stop editing! Happy publishing. */
183
+
184
+ /** Absolute path to the WordPress directory. */
185
+ if (! defined('ABSPATH')) {
186
+ define('ABSPATH', __DIR__ . '/');
187
+ }
188
+
189
+ /** Sets up WordPress vars and included files. */
190
+ require_once ABSPATH . 'wp-settings.php';