@scandipwa/magento-scripts 2.4.12-alpha.0 → 2.4.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/index.js CHANGED
@@ -6,7 +6,6 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger')
6
6
  const semver = require('semver')
7
7
  const isInstalledGlobally = require('is-installed-globally')
8
8
  const isRunningRoot = require('./lib/util/is-running-root')
9
- const ensureAgentsMd = require('./lib/util/ensure-agents-md')
10
9
 
11
10
  if (isRunningRoot()) {
12
11
  logger.error('Root privileges detected!')
@@ -28,8 +27,6 @@ If you are experiencing problems with ${logger.style.misc(
28
27
  process.exit(1)
29
28
  }
30
29
 
31
- ensureAgentsMd()
32
-
33
30
  const commands = [
34
31
  require('./lib/commands/link'),
35
32
  require('./lib/commands/logs'),
@@ -3,7 +3,7 @@ const { Listr } = require('listr2')
3
3
  const getMagentoVersionConfig = require('../config/get-magento-version-config')
4
4
  const { getCachedPorts } = require('../config/get-port-config')
5
5
 
6
- const { prettyStatus } = require('../tasks/status')
6
+ const { prettyStatus, simpleStatus } = require('../tasks/status')
7
7
  const { checkRequirements } = require('../tasks/requirements')
8
8
  const { statusContainers } = require('../tasks/docker/containers')
9
9
  const getProjectConfiguration = require('../config/get-project-configuration')
@@ -20,10 +20,35 @@ module.exports = (yargs) => {
20
20
  yargs.command(
21
21
  'status',
22
22
  'Show application status',
23
- // eslint-disable-next-line @typescript-eslint/no-empty-function
24
- () => {},
23
+ (yargs) => {
24
+ yargs
25
+ .option('non-interactive', {
26
+ alias: 'n',
27
+ type: 'boolean',
28
+ default: false,
29
+ description:
30
+ 'Print a plain-text status summary (for AI terminals and scripts)'
31
+ })
32
+ .option('verbose', {
33
+ alias: 'v',
34
+ type: 'boolean',
35
+ default: false,
36
+ description:
37
+ 'Retrieve Docker image and volume sizes (slower, off by default)'
38
+ })
39
+ },
25
40
  async (args) => {
26
41
  const silent = /** @type {boolean} */ (args.silent)
42
+ // A non-TTY stdout (pipe, CI, AI terminal) is inherently
43
+ // non-interactive; the -n flag forces it even inside a TTY.
44
+ const nonInteractive =
45
+ !!(args.nonInteractive || args.n) || !process.stdout.isTTY
46
+ // Enumerating per-image/-volume sizes shells out to
47
+ // `docker system df --verbose`, which is slow; skip it by default.
48
+ // The non-interactive report already prints the full status; the
49
+ // --verbose flag only adds the Docker image/volume sizes (and is
50
+ // what the pretty renderer needs to render them at all).
51
+ const verbose = !!(args.verbose || args.v)
27
52
  const tasks = new Listr(
28
53
  [
29
54
  checkRequirements(),
@@ -40,6 +65,9 @@ module.exports = (yargs) => {
40
65
  checkSearchEngineVersion(),
41
66
  {
42
67
  title: 'Retrieving Docker System data',
68
+ skip: () =>
69
+ !verbose &&
70
+ 'Docker image and volume sizes omitted (pass --verbose to include them)',
43
71
  task: async (ctx) => {
44
72
  ctx.systemDFData =
45
73
  await systemApi.df({
@@ -59,15 +87,25 @@ module.exports = (yargs) => {
59
87
  {
60
88
  concurrent: false,
61
89
  exitOnError: false,
62
- ctx: { throwMagentoVersionMissing: true, ...args, silent },
63
- renderer:
64
- silent || !process.stdout.isTTY ? 'silent' : 'default',
90
+ ctx: {
91
+ throwMagentoVersionMissing: true,
92
+ ...args,
93
+ silent,
94
+ nonInteractive,
95
+ verbose
96
+ },
97
+ renderer: silent || nonInteractive ? 'silent' : 'default',
65
98
  rendererOptions: { collapse: false, clearOutput: false }
66
99
  }
67
100
  )
68
101
 
69
102
  try {
70
- await prettyStatus(await tasks.run())
103
+ const ctx = await tasks.run()
104
+ if (nonInteractive) {
105
+ simpleStatus(ctx)
106
+ } else {
107
+ await prettyStatus(ctx)
108
+ }
71
109
  } catch (e) {
72
110
  logger.error(e.message || e)
73
111
  process.exit(1)
@@ -8,6 +8,16 @@ const { getArchSync } = require('../../util/arch')
8
8
  const ConsoleBlock = require('../../util/console-block')
9
9
  const { getInstanceMetadata } = require('../../util/instance-metadata')
10
10
 
11
+ // eslint-disable-next-line no-control-regex
12
+ const consoleStyleReplacer = /[]\[\S+?m/g
13
+
14
+ /**
15
+ * chalk already drops styling when stdout is not a TTY, but strip defensively
16
+ * so the plain output stays clean even under FORCE_COLOR.
17
+ * @param {string} str
18
+ */
19
+ const stripStyle = (str) => String(str).replace(consoleStyleReplacer, '')
20
+
11
21
  /**
12
22
  * @param {any} str
13
23
  * @returns {str is string}
@@ -230,9 +240,10 @@ const prettyStatus = async (ctx) => {
230
240
 
231
241
  Object.values(volumes)
232
242
  .map((volume) => {
233
- volume.volumeData = systemDFData.Volumes.find(
234
- (v) => v.Name === volume.name
235
- )
243
+ volume.volumeData =
244
+ systemDFData &&
245
+ systemDFData.Volumes &&
246
+ systemDFData.Volumes.find((v) => v.Name === volume.name)
236
247
 
237
248
  return volume
238
249
  })
@@ -273,4 +284,174 @@ const prettyStatus = async (ctx) => {
273
284
  block.log()
274
285
  }
275
286
 
276
- module.exports = { prettyStatus }
287
+ /**
288
+ * Plain-text status summary for non-interactive environments (AI agents, CI,
289
+ * pipes). No box drawing or ANSI styling — just the facts an agent needs to
290
+ * act, plus the commands to run next.
291
+ * @param {import('../../../typings/context').ListrContext & { containers: ReturnType<Awaited<ReturnType<import('../../config/docker')>>['getContainers']> }} ctx
292
+ */
293
+ const simpleStatus = (ctx) => {
294
+ const {
295
+ config: { baseConfig },
296
+ magentoVersion,
297
+ composerVersion,
298
+ dockerVersion,
299
+ containers,
300
+ systemDFData,
301
+ verbose
302
+ } = ctx
303
+
304
+ const lines = []
305
+
306
+ lines.push(
307
+ `magento-scripts ${packageVersion} — status (non-interactive)`,
308
+ '',
309
+ `Project: ${baseConfig.prefix}`,
310
+ `Location: ${process.cwd()}`,
311
+ `Magento: ${magentoVersion || 'unknown'}`,
312
+ `PHP: ${ctx.phpVersion || 'unknown'}`,
313
+ `Composer: ${composerVersion || 'unknown'}`,
314
+ `Docker: ${dockerVersion || 'unknown'}`,
315
+ `Platform: ${ctx.platform} (${getArchSync()})`
316
+ )
317
+
318
+ lines.push(
319
+ `Platform version: ${ctx.platformVersion || 'unknown'}`,
320
+ `CGroup version: ${ctx.cgroupVersion || 'unknown'}`
321
+ )
322
+
323
+ const projectCreatedAt = getProjectCreatedAt()
324
+ if (projectCreatedAt) {
325
+ lines.push(
326
+ `Project created: ${projectCreatedAt.toDateString()} ${projectCreatedAt.toTimeString()}`
327
+ )
328
+ }
329
+
330
+ lines.push('', 'Containers:')
331
+
332
+ let anyRunning = false
333
+
334
+ Object.values(containers).forEach((container) => {
335
+ const state = container.status && container.status.State
336
+ let status
337
+
338
+ if (state && state.Health && state.Status === 'running') {
339
+ status = `running (${state.Health.Status})`
340
+ anyRunning = true
341
+ } else if (state && state.Status && state.Status !== 'exited') {
342
+ status = state.Status
343
+ if (state.Status === 'running') {
344
+ anyRunning = true
345
+ }
346
+ } else {
347
+ status = 'not running'
348
+ }
349
+
350
+ lines.push(` ${container._ || container.name}: ${status}`)
351
+
352
+ lines.push(` Name: ${container.name}`)
353
+
354
+ const image =
355
+ container.status &&
356
+ container.status.Config &&
357
+ container.status.Config.Image
358
+ ? container.status.Config.Image
359
+ : container.image
360
+ lines.push(` Image: ${image}`, ` Network: ${container.network}`)
361
+
362
+ if (
363
+ status !== 'not running' &&
364
+ container.forwardedPorts &&
365
+ container.forwardedPorts.length > 0
366
+ ) {
367
+ lines.push(' Port forwarding:')
368
+ container.forwardedPorts.forEach((port) => {
369
+ const { host, hostPort, containerPort } = parsePort(port)
370
+ if (container.network !== 'host') {
371
+ lines.push(
372
+ ` ${host}:${hostPort} -> ${containerPort} (host -> container)`
373
+ )
374
+ } else {
375
+ lines.push(
376
+ ` Running on host network - ${host}:${hostPort}`
377
+ )
378
+ }
379
+ })
380
+ }
381
+
382
+ if (container.env && Object.keys(container.env).length > 0) {
383
+ lines.push(' Environment variables:')
384
+ for (const [envName, envValue] of Object.entries(container.env)) {
385
+ lines.push(` ${envName}=${envValue}`)
386
+ }
387
+ }
388
+
389
+ if (container.description) {
390
+ lines.push(' Description:')
391
+ container.description.split('\n').forEach((line) => {
392
+ lines.push(` ${stripStyle(line)}`)
393
+ })
394
+ }
395
+ })
396
+
397
+ lines.push('', 'Volumes:')
398
+
399
+ const { volumes } = ctx.config.docker
400
+
401
+ Object.values(volumes).forEach((volume) => {
402
+ const volumeData =
403
+ systemDFData &&
404
+ systemDFData.Volumes &&
405
+ systemDFData.Volumes.find((v) => v.Name === volume.name)
406
+
407
+ lines.push(` ${volume.name}`)
408
+
409
+ if (volumeData) {
410
+ lines.push(` Size: ${volumeData.Size}`)
411
+ }
412
+
413
+ if (ctx.isDockerDesktop && volume.opt && volume.opt.device) {
414
+ lines.push(
415
+ ` Mountpoint: ${volume.opt.device.replace(
416
+ process.cwd(),
417
+ '<project location>'
418
+ )}`
419
+ )
420
+ }
421
+ })
422
+
423
+ if (!verbose) {
424
+ lines.push(' (volume sizes omitted — pass --verbose to include them)')
425
+ }
426
+
427
+ const instanceMetadata = getInstanceMetadata(ctx)
428
+
429
+ lines.push('', 'Frontend:')
430
+ instanceMetadata.frontend.forEach(({ title, text }) => {
431
+ lines.push(` ${stripStyle(title)}: ${stripStyle(text)}`)
432
+ })
433
+
434
+ lines.push('', 'Admin:')
435
+ instanceMetadata.admin.forEach(({ title, text }) => {
436
+ lines.push(` ${stripStyle(title)}: ${stripStyle(text)}`)
437
+ })
438
+
439
+ lines.push('', 'MailDev:')
440
+ instanceMetadata.maildev.forEach(({ title, text }) => {
441
+ lines.push(` ${stripStyle(title)}: ${stripStyle(text)}`)
442
+ })
443
+
444
+ lines.push('')
445
+ if (!anyRunning) {
446
+ lines.push(
447
+ 'Environment is not running. Start it with: magento-scripts start'
448
+ )
449
+ }
450
+ lines.push(
451
+ 'Run Magento CLI: magento-scripts exec php bin/magento <command>'
452
+ )
453
+
454
+ logger.log(lines.join('\n'))
455
+ }
456
+
457
+ module.exports = { prettyStatus, simpleStatus }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "2.4.12-alpha.0",
6
+ "version": "2.4.12",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -59,5 +59,5 @@
59
59
  "@types/node": "^20.14.11",
60
60
  "@types/yargs": "^17.0.32"
61
61
  },
62
- "gitHead": "0fe2409c4e619ff985cf90a7f3d6cc4d45ca2552"
62
+ "gitHead": "6989fd1f8233b1586050ea39a89c1db29334f6cb"
63
63
  }
@@ -1,79 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
-
4
- const AGENTS_MD_CONTENT = `# CMA (magento-scripts) — AI/CI Reference
5
-
6
- > Auto-generated by magento-scripts. Do not delete.
7
-
8
- ## Critical
9
-
10
- - **Cannot run as root** — exits immediately with code 1, no override.
11
- - **Non-TTY safe** — silent renderer activates automatically in CI/pipes; no \`-q\` needed.
12
- - **Do NOT use \`--\` with exec** — it gets passed as the command and fails. Correct: \`magento-scripts exec php bin/magento cache:flush\`
13
- - **\`cli\` is TTY-only** — use \`exec php bin/magento <cmd>\` in automation instead.
14
- - **\`import-db\` is self-contained** — it stops running containers, assigns ports, starts services, waits for MariaDB, and imports. Do NOT run \`start\` before or between \`import-db\` attempts — that creates port conflicts. Just run \`import-db\` directly.
15
- - **Do NOT run \`start\` then \`import-db\`** — each command manages its own container lifecycle. Running both creates split-brain port assignments. Use one or the other.
16
- - **Long-running commands** — \`start\` and \`import-db\` can take 10+ minutes (container setup, large dumps). Set timeouts to at least 600000ms (10 min) or run without a timeout.
17
- - **Shell escaping** — Avoid \`!\` in SQL strings passed via \`exec\` (e.g., \`!=\`), as the shell may interpret it. Use SQL alternatives like \`<>\` instead of \`!=\`.
18
-
19
- ## Commands
20
-
21
- | Command | What it does | Key flags |
22
- |---------|-------------|-----------|
23
- | \`start\` | Start Docker environment | \`--no-open\`, \`--skip-setup\`, \`--port\` |
24
- | \`stop\` | Stop all containers | — |
25
- | \`status\` | Show container/DB status | — |
26
- | \`exec <container> [cmd...]\` | Run command in container | use \`--\` before flags |
27
- | \`import-db [file]\` | Import SQL dump into MariaDB | \`-y\` (non-interactive), \`--remote-db=ssh://user@host\` |
28
- | \`logs <container>\` | Stream container logs | \`--tail N\`, \`--follow\` |
29
- | \`cleanup\` | Remove cached/generated files | \`--force\` |
30
- | \`cli\` | Interactive shell (TTY only) | — |
31
- | \`link <path>\` | Link ScandiPWA theme | — |
32
-
33
- ## Containers
34
-
35
- \`php\`, \`phpWithXdebug\`, \`nginx\`, \`sslTerminator\`, \`redis\`, \`mariadb\`, \`elasticsearch\`, \`maildev\`, \`varnish\` (if enabled)
36
-
37
- ## Examples
38
-
39
- \`\`\`bash
40
- magento-scripts start --no-open --skip-setup
41
- magento-scripts import-db dump.sql -y
42
- magento-scripts import-db -y --remote-db=ssh://user@host
43
- magento-scripts exec php bin/magento cache:flush
44
- magento-scripts exec php bin/magento indexer:reindex
45
-
46
- # Query MariaDB (use mariadb binary, not mysql)
47
- magento-scripts exec mariadb mariadb -u magento -pmagento magento -e "SELECT COUNT(*) FROM store"
48
- magento-scripts logs magento --tail 100
49
- magento-scripts stop
50
- \`\`\`
51
- `
52
-
53
- /**
54
- * Write AGENTS.md and CLAUDE.md to the current working directory if they do not already exist.
55
- * This gives AI agents and CI pipelines a command reference for the project.
56
- */
57
- function ensureAgentsMd() {
58
- const cwd = process.cwd()
59
-
60
- const agentsDest = path.join(cwd, 'AGENTS.md')
61
- if (!fs.existsSync(agentsDest)) {
62
- try {
63
- fs.writeFileSync(agentsDest, AGENTS_MD_CONTENT, 'utf8')
64
- } catch (e) {
65
- // Non-fatal — silently skip if the directory is not writable
66
- }
67
- }
68
-
69
- const claudeDest = path.join(cwd, 'CLAUDE.md')
70
- if (!fs.existsSync(claudeDest)) {
71
- try {
72
- fs.writeFileSync(claudeDest, '@AGENTS.md\n', 'utf8')
73
- } catch (e) {
74
- // Non-fatal
75
- }
76
- }
77
- }
78
-
79
- module.exports = ensureAgentsMd