create-cwa 2.0.0-alpha.54 → 2.0.0-alpha.56

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/README.md CHANGED
@@ -17,12 +17,13 @@ Requires Node.js 22.13 or later, and Docker to run the project.
17
17
  The CLI asks for:
18
18
 
19
19
  - **Project name**: lower-case letters, digits and dashes. It becomes the directory (which must not exist yet, or be empty) and the Docker Compose project name.
20
- - **CI/CD pipeline**: GitHub Actions, GitLab CI (both deploy to Kubernetes) or None to decide later.
21
- - **Features**: navigation links, an HTML content editor, image uploads, a blog, nested pages and an example form. Features another one needs are added for you.
22
- - **Fixtures**: sample pages for the chosen features.
20
+ - **Pipeline**: GitHub Actions, GitLab CI or None to set one up later.
21
+ - **Deploy to** (with a pipeline): a Kubernetes cluster, or one server with Docker, which the pipeline deploys over SSH (a preview). The project's README lists the variables to set.
22
+ - **Components**: a navigation menu, rich text (TipTap), images, a blog, nested pages and an example form. The first three are pre-selected. Components another one needs are added for you.
23
+ - **Starting pages**: a home page plus an example of each component you chose, just a home page, or an empty site (only the admin login).
23
24
  - **Start the Docker stack?** Before anything is downloaded, it checks that Docker is running and that ports 80, 443, 3001, 5432 and 8025 are free, and names whatever holds a port. If you don't start the stack now, it offers to install `app/` dependencies on your machine for editor types (default No): the app container installs its own either way.
24
25
 
25
- If you start the stack, the CLI runs the project's `bin/up`: it waits until the stack is healthy, loads the fixtures (which create the admin, and the sample pages if you chose them), pre-compiles the first pages and prints the login. Run `bin/up` again any time; it's safe to repeat. The site is at `https://localhost`, the admin signs in at `https://localhost/login` (`admin` / `admin` in dev), and Mailpit shows the emails the API sends at `http://localhost:8025`. Without a POSIX shell (Windows without WSL), the CLI prints the steps instead.
26
+ If you start the stack, the CLI runs the project's `bin/up`: it waits until the stack is healthy, loads the fixtures (which create the admin, and the starting pages you chose), pre-compiles the first pages and prints the login. Run `bin/up` again any time; it's safe to repeat. The site is at `https://localhost`, the admin signs in at `https://localhost/login` (`admin` / `admin` in dev), and Mailpit shows the emails the API sends at `http://localhost:8025`. Without a POSIX shell (Windows without WSL), the CLI prints the steps instead.
26
27
 
27
28
  ## Options
28
29
 
@@ -32,14 +33,15 @@ If you start the stack, the CLI runs the project's `bin/up`: it waits until the
32
33
  Each of these answers its question, so it isn't asked:
33
34
 
34
35
  - `--pipeline <github|gitlab|none>`: the CI/CD pipeline.
35
- - `--features <list>`: comma-separated feature ids (`navigation`, `html-content`, `image`, `blog`, `nested-pages`, `forms`), `all` or `none`. Features another one needs are still added.
36
- - `--fixtures` / `--no-fixtures`: include the sample pages, or not.
36
+ - `--deploy <kubernetes|server>`: where the pipeline deploys; needs a pipeline.
37
+ - `--features <list>`: comma-separated component ids (`navigation`, `html-content`, `image`, `blog`, `nested-pages`, `forms`), `default` (the pre-selected three), `all` or `none`. Components another one needs are still added.
38
+ - `--content <demo|home|empty>`: the starting pages. `--fixtures` and `--no-fixtures` still work, as `--content demo` and `--content empty`.
37
39
  - `--start` / `--no-start`: run `bin/up` once the project is created, or not. With `--start`, a check that fails (Docker not running, a port taken) stops the CLI before anything is created.
38
40
  - `--install-deps` / `--no-install-deps`: `pnpm install` in `app/` on this machine; only when the stack isn't started.
39
41
 
40
42
  For unattended runs:
41
43
 
42
- - `-y`, `--yes`: take the default for every question no flag answers: GitHub Actions, no features, fixtures, start the stack (when Docker is there and the checks pass), no host install. The project name has no default, so it's still asked for when not given.
44
+ - `-y`, `--yes`: take the default for every question no flag answers: GitHub Actions, Kubernetes, the pre-selected components, a home page with examples, start the stack (when Docker is there and the checks pass), no host install. The project name has no default, so it's still asked for when not given.
43
45
  - `--ci`: never prompt (implies `--yes`). A missing or invalid project name is an error, and a failed `bin/up` makes the CLI exit 1. For example:
44
46
 
45
47
  ```sh
package/dist/index.js CHANGED
@@ -23,8 +23,11 @@ Options:
23
23
  --ref <tag|branch> template version to download (default v${CLI_VERSION})
24
24
  --template-dir <path> copy the template from a local checkout instead of downloading it
25
25
  --pipeline <id> CI/CD pipeline: github, gitlab or none
26
- --features <list> comma-separated features, "all" or "none"
27
- --fixtures, --no-fixtures include the sample pages, or not
26
+ --deploy <target> with a pipeline: kubernetes, or server (one server with Docker, over SSH)
27
+ --features <list> comma-separated components, "default", "all" or "none"
28
+ --content <level> starting pages: demo (an example of each component), home (just a home page)
29
+ or empty (only the admin login)
30
+ --fixtures, --no-fixtures the same as --content demo, or --content empty
28
31
  --start, --no-start run bin/up once the project is created, or not
29
32
  --install-deps, --no-install-deps
30
33
  pnpm install in app/ on this machine (only when the stack isn't started)
@@ -33,7 +36,7 @@ Options:
33
36
  -h, --help show this help`;
34
37
  class UsageError extends Error {
35
38
  }
36
- const VALUE_FLAGS = ['--ref', '--template-dir', '--pipeline', '--features'];
39
+ const VALUE_FLAGS = ['--ref', '--template-dir', '--pipeline', '--deploy', '--features', '--content'];
37
40
  // Flags for unattended runs (#215); with none given, every question is asked as before.
38
41
  function parseArgs(argv) {
39
42
  const args = argv.slice(2);
@@ -68,12 +71,18 @@ function parseArgs(argv) {
68
71
  case '--pipeline':
69
72
  opts.pipeline = value;
70
73
  break;
74
+ case '--deploy':
75
+ opts.deploy = value;
76
+ break;
71
77
  case '--features':
72
78
  opts.features = value.split(',').map((f) => f.trim()).filter(Boolean);
73
79
  break;
80
+ case '--content':
81
+ opts.content = value;
82
+ break;
74
83
  case '--fixtures':
75
84
  case '--no-fixtures':
76
- opts.fixtures = arg === '--fixtures';
85
+ opts.content = arg === '--fixtures' ? 'demo' : 'empty';
77
86
  break;
78
87
  case '--start':
79
88
  case '--no-start':
@@ -230,49 +239,92 @@ async function askQuestions(manifest, opts) {
230
239
  options: ciOptions,
231
240
  }));
232
241
  }
242
+ // Kubernetes or one server (#212), only with a pipeline: bin/server/ deploys by hand without one.
243
+ let deploy = 'none';
244
+ if (ci !== 'none') {
245
+ const deployQuestion = question('deploy');
246
+ const deployOptions = deployQuestion?.choices?.map((c) => ({ value: c.value, label: c.label, hint: c.hint })) ?? [
247
+ { value: 'kubernetes', label: 'A Kubernetes cluster' },
248
+ ];
249
+ if (opts.deploy !== undefined) {
250
+ if (!deployOptions.some((c) => c.value === opts.deploy)) {
251
+ fail(`--deploy ${opts.deploy}: choose one of ${deployOptions.map((c) => c.value).join(', ')}`);
252
+ }
253
+ deploy = opts.deploy;
254
+ }
255
+ else if (opts.yes || deployOptions.length === 1) {
256
+ deploy = deployOptions[0].value;
257
+ }
258
+ else {
259
+ deploy = checkCancel(await select({
260
+ message: withHint(deployQuestion?.message ?? 'Deploy to?', deployQuestion?.hint),
261
+ options: deployOptions,
262
+ }));
263
+ }
264
+ }
265
+ else if (opts.deploy !== undefined) {
266
+ fail('--deploy needs a pipeline (--pipeline github or gitlab); without one, bin/server/ deploys by hand');
267
+ }
233
268
  const featuresQuestion = question('features');
234
269
  const featureChoices = featuresQuestion?.choices?.map((c) => ({ value: c.value, label: c.label, hint: c.hint })) ?? [];
270
+ const preselected = featuresQuestion?.choices?.filter((c) => c.selected).map((c) => c.value) ?? [];
235
271
  let features;
236
272
  if (opts.features !== undefined) {
237
273
  const all = featureChoices.map((c) => c.value);
238
274
  const flag = opts.features;
239
- features = flag.length === 1 && flag[0] === 'all' ? all : flag.length === 1 && flag[0] === 'none' ? [] : flag;
275
+ const one = flag.length === 1 ? flag[0] : undefined;
276
+ features = one === 'all' ? all : one === 'none' ? [] : one === 'default' ? preselected : flag;
240
277
  const unknown = features.filter((f) => !all.includes(f));
241
278
  if (unknown.length) {
242
- fail(`--features: unknown ${unknown.join(', ')}. Choose from ${all.join(', ')}, or "all" or "none"`);
279
+ fail(`--features: unknown ${unknown.join(', ')}. Choose from ${all.join(', ')}, or "default", "all" or "none"`);
243
280
  }
244
281
  }
245
282
  else if (opts.yes) {
246
- features = [];
283
+ features = preselected;
247
284
  }
248
285
  else {
249
286
  features = checkCancel(await multiselect({
250
287
  message: withHint(`${featuresQuestion?.message ?? 'Which features to include?'} (space to toggle, enter to confirm)`, featuresQuestion?.hint),
251
288
  options: featureChoices,
289
+ initialValues: preselected,
252
290
  required: false,
253
291
  }));
254
292
  }
255
293
  // Auto-include required features
256
294
  const resolved = new Set(features);
257
295
  for (const feat of features) {
258
- const requires = manifest.questions
259
- .find((q) => q.id === 'features')
260
- ?.choices?.find((c) => c.value === feat)?.requires ?? [];
296
+ const requires = featuresQuestion?.choices?.find((c) => c.value === feat)?.requires ?? [];
261
297
  requires.forEach((r) => resolved.add(r));
262
298
  }
263
299
  if (resolved.size > features.length) {
264
300
  const added = [...resolved].filter((f) => !features.includes(f));
265
301
  note(`Also enabling: ${added.join(', ')} (required by selected features)`, 'Dependencies');
266
302
  }
267
- const fixturesQuestion = question('fixtures');
268
- const fixtures = opts.fixtures ??
269
- (opts.yes
270
- ? (fixturesQuestion?.default ?? true)
271
- : checkCancel(await confirm({
272
- message: withHint(fixturesQuestion?.message ?? 'Include database fixtures for selected features?', fixturesQuestion?.hint),
273
- initialValue: fixturesQuestion?.default ?? true,
274
- })));
275
- return { projectName: projectName.trim(), ci, features: [...resolved], fixtures };
303
+ // Starting pages: demo, home or empty. An older template (no content question) has only demo or empty.
304
+ const contentQuestion = question('content');
305
+ const contentOptions = contentQuestion?.choices?.map((c) => ({ value: c.value, label: c.label, hint: c.hint })) ?? [
306
+ { value: 'demo', label: 'Example pages' },
307
+ { value: 'empty', label: 'An empty site', hint: 'only the admin login' },
308
+ ];
309
+ const contentDefault = typeof contentQuestion?.default === 'string' ? contentQuestion.default : contentOptions[0].value;
310
+ let content;
311
+ if (opts.content !== undefined) {
312
+ if (!contentOptions.some((c) => c.value === opts.content)) {
313
+ fail(`--content ${opts.content}: choose one of ${contentOptions.map((c) => c.value).join(', ')}`);
314
+ }
315
+ content = opts.content;
316
+ }
317
+ else if (opts.yes) {
318
+ content = contentDefault;
319
+ }
320
+ else {
321
+ content = checkCancel(await select({
322
+ message: withHint(contentQuestion?.message ?? 'Start with example pages?', contentQuestion?.hint),
323
+ options: contentOptions,
324
+ initialValue: contentDefault,
325
+ }));
326
+ }
327
+ return { projectName: projectName.trim(), ci, deploy, features: [...resolved], content };
276
328
  }
277
329
  // Files a download would contain: what git tracks or would track, minus export-ignore paths (GitHub's tarball honours them).
278
330
  function templateFiles(src) {
@@ -388,19 +440,46 @@ async function replaceProjectName(tempDir, projectName) {
388
440
  }
389
441
  }
390
442
  async function generateReadme(tempDir, answers) {
391
- const featureList = answers.features.length
392
- ? answers.features.map((f) => `- ${f}`).join('\n')
393
- : '- Core (Title component)';
394
- const ciSection = answers.ci === 'github'
395
- ? '## CI/CD\n\nGitHub Actions workflows are in `.github/workflows/`. See the workflow files for required secrets and variables.\n'
396
- : answers.ci === 'gitlab'
397
- ? '## CI/CD\n\nGitLab CI is configured in `.gitlab-ci.yml`. See `bin/devops/` for the reusable pipeline scripts.\n'
398
- : '';
443
+ const featureList = ['- title (always)', ...answers.features.map((f) => `- ${f}`)].join('\n') +
444
+ '\n\nA component you left out can be added later: `cwa-manifest.json` in the' +
445
+ ' [template](https://github.com/components-web-app/components-web-app) lists the files each one needs.';
446
+ const pipelineFiles = answers.ci === 'github'
447
+ ? 'GitHub Actions workflows are in `.github/workflows/`'
448
+ : 'GitLab CI is configured in `.gitlab-ci.yml`';
449
+ const serverVariables = answers.ci === 'github'
450
+ ? 'repository variables, and `CWA_CI_SERVER_SSH_KEY` as a secret'
451
+ : 'CI/CD variables (not Protected), with `CWA_CI_SERVER_SSH_KEY` Masked';
452
+ const ciSection = answers.ci === 'none'
453
+ ? `## Deploying
454
+
455
+ There's no pipeline yet. \`bin/server/\` runs the site on one server with Docker: on the server, \`sh bin/server/init\`
456
+ writes its settings, then \`sh bin/server/deploy.sh --fixtures\` deploys it (see the comments at the top of each script).
457
+ `
458
+ : answers.deploy === 'server'
459
+ ? `## Deploying to one server
460
+
461
+ ${pipelineFiles}. The pipeline builds and tests every push; the manual production server deploy copies the
462
+ commit to your server over SSH and runs \`bin/server/deploy.sh\` there. Single-server deploys are a preview.
463
+
464
+ 1. On the server: install Docker with the compose plugin, rsync and curl, and add a \`deploy\` user to the
465
+ \`docker\` group with your pipeline's public SSH key in \`~/.ssh/authorized_keys\`.
466
+ 2. Set these ${serverVariables}: \`CWA_CI_SERVER_HOST\` (the server's address; setting it turns the Kubernetes
467
+ jobs off), \`CWA_CI_SERVER_SSH_KEY\` (the private key) and \`CWA_CI_SERVER_KNOWN_HOSTS\` (the output of
468
+ \`ssh-keyscan <host>\`). \`bin/devops/server-deploy.sh\` lists the optional ones.
469
+ 3. Run the production server deploy once: it copies the files, then stops and asks you to run
470
+ \`cd cwa && sh bin/server/init && sh bin/server/deploy.sh --fixtures\` on the server.
471
+ 4. After that, every production server deploy updates the site.
472
+ `
473
+ : `## Deploying to Kubernetes
474
+
475
+ ${pipelineFiles}, with the deploy scripts in \`bin/devops/\` and the Helm chart in \`helm/cwa/\`. See the
476
+ pipeline files for the secrets and variables they need.
477
+ `;
399
478
  const fixturesSection = `## Fixtures and the admin account
400
479
 
401
480
  \`bin/up\` loads the fixtures with \`--append\`, which only creates what's missing: the admin
402
481
  (\`ADMIN_USERNAME\` / \`ADMIN_PASSWORD\` / \`ADMIN_EMAIL\` in \`api/.env.local\`, default
403
- \`admin\` / \`admin\` / \`admin@example.com\`)${answers.fixtures ? ' and the sample pages' : ''}. Each load resets the
482
+ \`admin\` / \`admin\` / \`admin@example.com\`)${answers.content === 'demo' ? ' and the example pages' : answers.content === 'home' ? ' and the home page' : ''}. Each load resets the
404
483
  admin's password to \`ADMIN_PASSWORD\`; \`bin/up --skip-fixtures\` keeps one changed in the admin.
405
484
  To load them by hand:
406
485
 
@@ -412,7 +491,7 @@ docker compose exec php bin/console doctrine:fixtures:load --append
412
491
 
413
492
  A [CWA](https://github.com/components-web-app/components-web-app) project.
414
493
 
415
- ## Features
494
+ ## Components
416
495
 
417
496
  ${featureList}
418
497
 
@@ -568,10 +647,10 @@ async function main() {
568
647
  await removeExcluded(tempDir, config.exclude);
569
648
  }
570
649
  }
571
- if (!answers.fixtures) {
572
- // Sample content only: UsersFixture stays, so the admin is still created from ADMIN_* (#142).
573
- await removeExcluded(tempDir, ['api/src/DataFixtures/AppScaffold.php', 'api/src/DataFixtures/Parts/']);
574
- }
650
+ // Starting content: UsersFixture always stays, so the admin is created from ADMIN_* (#142).
651
+ const contentExclude = manifest.content?.[answers.content]?.exclude ??
652
+ (answers.content === 'empty' ? ['api/src/DataFixtures/AppScaffold.php', 'api/src/DataFixtures/Parts/'] : []);
653
+ await removeExcluded(tempDir, contentExclude);
575
654
  await processNuxtConfig(tempDir, answers.features);
576
655
  await replaceProjectName(tempDir, answers.projectName);
577
656
  await generateReadme(tempDir, answers);
@@ -593,7 +672,7 @@ async function main() {
593
672
  '(which your editor reads too) and runs the dev server.',
594
673
  '',
595
674
  'bin/up waits for all that, loads the fixtures (the admin' +
596
- (answers.fixtures ? ' and sample pages' : '') +
675
+ (answers.content === 'demo' ? ' and the example pages' : answers.content === 'home' ? ' and the home page' : '') +
597
676
  '),',
598
677
  'pre-compiles the first pages and prints where to sign in. Run it again any time.',
599
678
  ]
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ export interface ManifestChoice {
3
3
  label: string;
4
4
  hint?: string;
5
5
  requires?: string[];
6
+ selected?: boolean;
6
7
  }
7
8
  export interface ManifestQuestion {
8
9
  id: string;
@@ -10,7 +11,7 @@ export interface ManifestQuestion {
10
11
  message: string;
11
12
  placeholder?: string;
12
13
  hint?: string;
13
- default?: boolean;
14
+ default?: boolean | string;
14
15
  choices?: ManifestChoice[];
15
16
  }
16
17
  export interface ManifestFeature {
@@ -28,10 +29,12 @@ export interface Manifest {
28
29
  questions: ManifestQuestion[];
29
30
  features: Record<string, ManifestFeature>;
30
31
  ci: Record<string, ManifestCi>;
32
+ content?: Record<string, ManifestCi>;
31
33
  }
32
34
  export interface Answers {
33
35
  projectName: string;
34
36
  ci: string;
37
+ deploy: string;
35
38
  features: string[];
36
- fixtures: boolean;
39
+ content: string;
37
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cwa",
3
- "version": "2.0.0-alpha.54",
3
+ "version": "2.0.0-alpha.56",
4
4
  "description": "Create a new CWA (Components Web App) project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,8 +24,8 @@
24
24
  "node": ">=22.13.0"
25
25
  },
26
26
  "dependencies": {
27
- "@clack/prompts": "^1.8.1",
28
- "fast-glob": "^3.3.0",
27
+ "@clack/prompts": "^1.9.0",
28
+ "fast-glob": "^3.3.3",
29
29
  "fs-extra": "^11.4.1",
30
30
  "giget": "^3.3.1"
31
31
  },
package/smoke.sh CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/bin/sh
2
2
  # Template CI only (#215): creates a project from this checkout with the built CLI, starts it through bin/up and checks the login.
3
- # Usage: packages/create-cwa/smoke.sh <work dir> (SMOKE_FEATURES: all|none|a,b; SMOKE_FIXTURES: true|false; SMOKE_REQUIRE_BASE=true fails instead of skipping)
3
+ # Usage: packages/create-cwa/smoke.sh <work dir> (SMOKE_FEATURES: all|none|a,b; SMOKE_CONTENT: demo|home|empty; SMOKE_REQUIRE_BASE=true fails instead of skipping)
4
4
  # Needs node and pnpm (or a built dist/), git, docker with compose, and free ports 80, 443, 3001, 5432 and 8025.
5
5
  set -u
6
6
 
7
7
  ROOT=$(cd "$(dirname "$0")/../.." && pwd)
8
8
  WORK=${1:?usage: smoke.sh <work dir>}
9
9
  FEATURES=${SMOKE_FEATURES:-all}
10
- FIXTURES=${SMOKE_FIXTURES:-true}
10
+ CONTENT=${SMOKE_CONTENT:-demo}
11
11
  NAME=cwa-smoke
12
12
  PROJECT="$WORK/$NAME"
13
13
  # The images' first build, composer and pnpm installs on a CI runner take longer than a laptop's default 900 s.
@@ -47,12 +47,11 @@ mkdir -p "$WORK" || exit 1
47
47
  # CI checkouts can belong to another user than the one running git here (GitLab's dind job, GitHub containers).
48
48
  if [ -n "${CI:-}" ]; then git config --global --add safe.directory "$ROOT"; fi
49
49
 
50
- [ "$FIXTURES" = true ] && fixtures=--fixtures || fixtures=--no-fixtures
51
50
  cd "$WORK" || exit 1
52
- echo "==> create-cwa $NAME --ci --template-dir $ROOT --pipeline none --features $FEATURES $fixtures --start"
51
+ echo "==> create-cwa $NAME --ci --template-dir $ROOT --pipeline none --features $FEATURES --content $CONTENT --start"
53
52
  # The exit status goes through a file: POSIX sh has no pipefail.
54
53
  { node "$ROOT/packages/create-cwa/bin/create-cwa.js" "$NAME" --ci --template-dir "$ROOT" \
55
- --pipeline none --features "$FEATURES" "$fixtures" --start 2>&1; echo $? > "$WORK/status"; } | tee "$WORK/create-cwa.log"
54
+ --pipeline none --features "$FEATURES" --content "$CONTENT" --start 2>&1; echo $? > "$WORK/status"; } | tee "$WORK/create-cwa.log"
56
55
  status=$(cat "$WORK/status")
57
56
  [ "$status" = 0 ] || fail "create-cwa exited $status (bin/up's output is above)"
58
57
 
@@ -69,4 +68,11 @@ code=$(docker compose exec -T php curl -sk --max-time 30 --resolve localhost:443
69
68
  -H 'Content-Type: application/json' -d '{"username":"admin","password":"admin"}' https://localhost/_api/login | tr -d '\r')
70
69
  [ "$code" = 204 ] || fail "signing in as admin / admin answered $code, not 204"
71
70
 
72
- echo "create-cwa smoke passed: features $FEATURES, fixtures $FIXTURES"
71
+ # demo and home both create the home page (CoreScaffoldPart); empty has none.
72
+ if [ "$CONTENT" != empty ]; then
73
+ home=$(docker compose exec -T php curl -fsSk --max-time 60 --resolve localhost:443:127.0.0.1 https://localhost/) \
74
+ || fail "https://localhost/ didn't answer 200 with --content $CONTENT"
75
+ echo "$home" | grep -q 'Welcome to CWA' || fail "the home page has no 'Welcome to CWA' title"
76
+ fi
77
+
78
+ echo "create-cwa smoke passed: features $FEATURES, content $CONTENT"
package/src/index.ts CHANGED
@@ -41,8 +41,9 @@ interface CliOptions {
41
41
  ci: boolean
42
42
  templateDir?: string
43
43
  pipeline?: string
44
+ deploy?: string
44
45
  features?: string[]
45
- fixtures?: boolean
46
+ content?: string
46
47
  start?: boolean
47
48
  installDeps?: boolean
48
49
  help: boolean
@@ -56,8 +57,11 @@ Options:
56
57
  --ref <tag|branch> template version to download (default v${CLI_VERSION})
57
58
  --template-dir <path> copy the template from a local checkout instead of downloading it
58
59
  --pipeline <id> CI/CD pipeline: github, gitlab or none
59
- --features <list> comma-separated features, "all" or "none"
60
- --fixtures, --no-fixtures include the sample pages, or not
60
+ --deploy <target> with a pipeline: kubernetes, or server (one server with Docker, over SSH)
61
+ --features <list> comma-separated components, "default", "all" or "none"
62
+ --content <level> starting pages: demo (an example of each component), home (just a home page)
63
+ or empty (only the admin login)
64
+ --fixtures, --no-fixtures the same as --content demo, or --content empty
61
65
  --start, --no-start run bin/up once the project is created, or not
62
66
  --install-deps, --no-install-deps
63
67
  pnpm install in app/ on this machine (only when the stack isn't started)
@@ -67,7 +71,7 @@ Options:
67
71
 
68
72
  class UsageError extends Error {}
69
73
 
70
- const VALUE_FLAGS = ['--ref', '--template-dir', '--pipeline', '--features']
74
+ const VALUE_FLAGS = ['--ref', '--template-dir', '--pipeline', '--deploy', '--features', '--content']
71
75
 
72
76
  // Flags for unattended runs (#215); with none given, every question is asked as before.
73
77
  function parseArgs(argv: string[]): CliOptions {
@@ -100,12 +104,18 @@ function parseArgs(argv: string[]): CliOptions {
100
104
  case '--pipeline':
101
105
  opts.pipeline = value
102
106
  break
107
+ case '--deploy':
108
+ opts.deploy = value
109
+ break
103
110
  case '--features':
104
111
  opts.features = (value as string).split(',').map((f) => f.trim()).filter(Boolean)
105
112
  break
113
+ case '--content':
114
+ opts.content = value
115
+ break
106
116
  case '--fixtures':
107
117
  case '--no-fixtures':
108
- opts.fixtures = arg === '--fixtures'
118
+ opts.content = arg === '--fixtures' ? 'demo' : 'empty'
109
119
  break
110
120
  case '--start':
111
121
  case '--no-start':
@@ -270,21 +280,49 @@ async function askQuestions(manifest: Manifest, opts: CliOptions): Promise<Answe
270
280
  ) as string
271
281
  }
272
282
 
283
+ // Kubernetes or one server (#212), only with a pipeline: bin/server/ deploys by hand without one.
284
+ let deploy = 'none'
285
+ if (ci !== 'none') {
286
+ const deployQuestion = question('deploy')
287
+ const deployOptions = deployQuestion?.choices?.map((c) => ({ value: c.value, label: c.label, hint: c.hint })) ?? [
288
+ { value: 'kubernetes', label: 'A Kubernetes cluster' },
289
+ ]
290
+ if (opts.deploy !== undefined) {
291
+ if (!deployOptions.some((c) => c.value === opts.deploy)) {
292
+ fail(`--deploy ${opts.deploy}: choose one of ${deployOptions.map((c) => c.value).join(', ')}`)
293
+ }
294
+ deploy = opts.deploy
295
+ } else if (opts.yes || deployOptions.length === 1) {
296
+ deploy = deployOptions[0].value
297
+ } else {
298
+ deploy = checkCancel(
299
+ await select({
300
+ message: withHint(deployQuestion?.message ?? 'Deploy to?', deployQuestion?.hint),
301
+ options: deployOptions,
302
+ })
303
+ ) as string
304
+ }
305
+ } else if (opts.deploy !== undefined) {
306
+ fail('--deploy needs a pipeline (--pipeline github or gitlab); without one, bin/server/ deploys by hand')
307
+ }
308
+
273
309
  const featuresQuestion = question('features')
274
310
  const featureChoices =
275
311
  featuresQuestion?.choices?.map((c) => ({ value: c.value, label: c.label, hint: c.hint })) ?? []
312
+ const preselected = featuresQuestion?.choices?.filter((c) => c.selected).map((c) => c.value) ?? []
276
313
 
277
314
  let features: string[]
278
315
  if (opts.features !== undefined) {
279
316
  const all = featureChoices.map((c) => c.value)
280
317
  const flag = opts.features
281
- features = flag.length === 1 && flag[0] === 'all' ? all : flag.length === 1 && flag[0] === 'none' ? [] : flag
318
+ const one = flag.length === 1 ? flag[0] : undefined
319
+ features = one === 'all' ? all : one === 'none' ? [] : one === 'default' ? preselected : flag
282
320
  const unknown = features.filter((f) => !all.includes(f))
283
321
  if (unknown.length) {
284
- fail(`--features: unknown ${unknown.join(', ')}. Choose from ${all.join(', ')}, or "all" or "none"`)
322
+ fail(`--features: unknown ${unknown.join(', ')}. Choose from ${all.join(', ')}, or "default", "all" or "none"`)
285
323
  }
286
324
  } else if (opts.yes) {
287
- features = []
325
+ features = preselected
288
326
  } else {
289
327
  features = checkCancel(
290
328
  await multiselect({
@@ -293,6 +331,7 @@ async function askQuestions(manifest: Manifest, opts: CliOptions): Promise<Answe
293
331
  featuresQuestion?.hint
294
332
  ),
295
333
  options: featureChoices,
334
+ initialValues: preselected,
296
335
  required: false,
297
336
  })
298
337
  ) as string[]
@@ -301,10 +340,7 @@ async function askQuestions(manifest: Manifest, opts: CliOptions): Promise<Answe
301
340
  // Auto-include required features
302
341
  const resolved = new Set(features)
303
342
  for (const feat of features) {
304
- const requires =
305
- manifest.questions
306
- .find((q) => q.id === 'features')
307
- ?.choices?.find((c) => c.value === feat)?.requires ?? []
343
+ const requires = featuresQuestion?.choices?.find((c) => c.value === feat)?.requires ?? []
308
344
  requires.forEach((r) => resolved.add(r))
309
345
  }
310
346
 
@@ -313,22 +349,33 @@ async function askQuestions(manifest: Manifest, opts: CliOptions): Promise<Answe
313
349
  note(`Also enabling: ${added.join(', ')} (required by selected features)`, 'Dependencies')
314
350
  }
315
351
 
316
- const fixturesQuestion = question('fixtures')
317
- const fixtures =
318
- opts.fixtures ??
319
- (opts.yes
320
- ? (fixturesQuestion?.default ?? true)
321
- : (checkCancel(
322
- await confirm({
323
- message: withHint(
324
- fixturesQuestion?.message ?? 'Include database fixtures for selected features?',
325
- fixturesQuestion?.hint
326
- ),
327
- initialValue: fixturesQuestion?.default ?? true,
328
- })
329
- ) as boolean))
352
+ // Starting pages: demo, home or empty. An older template (no content question) has only demo or empty.
353
+ const contentQuestion = question('content')
354
+ const contentOptions = contentQuestion?.choices?.map((c) => ({ value: c.value, label: c.label, hint: c.hint })) ?? [
355
+ { value: 'demo', label: 'Example pages' },
356
+ { value: 'empty', label: 'An empty site', hint: 'only the admin login' },
357
+ ]
358
+ const contentDefault =
359
+ typeof contentQuestion?.default === 'string' ? contentQuestion.default : contentOptions[0].value
360
+ let content: string
361
+ if (opts.content !== undefined) {
362
+ if (!contentOptions.some((c) => c.value === opts.content)) {
363
+ fail(`--content ${opts.content}: choose one of ${contentOptions.map((c) => c.value).join(', ')}`)
364
+ }
365
+ content = opts.content
366
+ } else if (opts.yes) {
367
+ content = contentDefault
368
+ } else {
369
+ content = checkCancel(
370
+ await select({
371
+ message: withHint(contentQuestion?.message ?? 'Start with example pages?', contentQuestion?.hint),
372
+ options: contentOptions,
373
+ initialValue: contentDefault,
374
+ })
375
+ ) as string
376
+ }
330
377
 
331
- return { projectName: projectName.trim(), ci, features: [...resolved], fixtures }
378
+ return { projectName: projectName.trim(), ci, deploy, features: [...resolved], content }
332
379
  }
333
380
 
334
381
  // Files a download would contain: what git tracks or would track, minus export-ignore paths (GitHub's tarball honours them).
@@ -454,22 +501,52 @@ async function replaceProjectName(tempDir: string, projectName: string): Promise
454
501
  }
455
502
 
456
503
  async function generateReadme(tempDir: string, answers: Answers): Promise<void> {
457
- const featureList = answers.features.length
458
- ? answers.features.map((f) => `- ${f}`).join('\n')
459
- : '- Core (Title component)'
504
+ const featureList =
505
+ ['- title (always)', ...answers.features.map((f) => `- ${f}`)].join('\n') +
506
+ '\n\nA component you left out can be added later: `cwa-manifest.json` in the' +
507
+ ' [template](https://github.com/components-web-app/components-web-app) lists the files each one needs.'
460
508
 
461
- const ciSection =
509
+ const pipelineFiles =
510
+ answers.ci === 'github'
511
+ ? 'GitHub Actions workflows are in `.github/workflows/`'
512
+ : 'GitLab CI is configured in `.gitlab-ci.yml`'
513
+ const serverVariables =
462
514
  answers.ci === 'github'
463
- ? '## CI/CD\n\nGitHub Actions workflows are in `.github/workflows/`. See the workflow files for required secrets and variables.\n'
464
- : answers.ci === 'gitlab'
465
- ? '## CI/CD\n\nGitLab CI is configured in `.gitlab-ci.yml`. See `bin/devops/` for the reusable pipeline scripts.\n'
466
- : ''
515
+ ? 'repository variables, and `CWA_CI_SERVER_SSH_KEY` as a secret'
516
+ : 'CI/CD variables (not Protected), with `CWA_CI_SERVER_SSH_KEY` Masked'
517
+ const ciSection =
518
+ answers.ci === 'none'
519
+ ? `## Deploying
520
+
521
+ There's no pipeline yet. \`bin/server/\` runs the site on one server with Docker: on the server, \`sh bin/server/init\`
522
+ writes its settings, then \`sh bin/server/deploy.sh --fixtures\` deploys it (see the comments at the top of each script).
523
+ `
524
+ : answers.deploy === 'server'
525
+ ? `## Deploying to one server
526
+
527
+ ${pipelineFiles}. The pipeline builds and tests every push; the manual production server deploy copies the
528
+ commit to your server over SSH and runs \`bin/server/deploy.sh\` there. Single-server deploys are a preview.
529
+
530
+ 1. On the server: install Docker with the compose plugin, rsync and curl, and add a \`deploy\` user to the
531
+ \`docker\` group with your pipeline's public SSH key in \`~/.ssh/authorized_keys\`.
532
+ 2. Set these ${serverVariables}: \`CWA_CI_SERVER_HOST\` (the server's address; setting it turns the Kubernetes
533
+ jobs off), \`CWA_CI_SERVER_SSH_KEY\` (the private key) and \`CWA_CI_SERVER_KNOWN_HOSTS\` (the output of
534
+ \`ssh-keyscan <host>\`). \`bin/devops/server-deploy.sh\` lists the optional ones.
535
+ 3. Run the production server deploy once: it copies the files, then stops and asks you to run
536
+ \`cd cwa && sh bin/server/init && sh bin/server/deploy.sh --fixtures\` on the server.
537
+ 4. After that, every production server deploy updates the site.
538
+ `
539
+ : `## Deploying to Kubernetes
540
+
541
+ ${pipelineFiles}, with the deploy scripts in \`bin/devops/\` and the Helm chart in \`helm/cwa/\`. See the
542
+ pipeline files for the secrets and variables they need.
543
+ `
467
544
 
468
545
  const fixturesSection = `## Fixtures and the admin account
469
546
 
470
547
  \`bin/up\` loads the fixtures with \`--append\`, which only creates what's missing: the admin
471
548
  (\`ADMIN_USERNAME\` / \`ADMIN_PASSWORD\` / \`ADMIN_EMAIL\` in \`api/.env.local\`, default
472
- \`admin\` / \`admin\` / \`admin@example.com\`)${answers.fixtures ? ' and the sample pages' : ''}. Each load resets the
549
+ \`admin\` / \`admin\` / \`admin@example.com\`)${answers.content === 'demo' ? ' and the example pages' : answers.content === 'home' ? ' and the home page' : ''}. Each load resets the
473
550
  admin's password to \`ADMIN_PASSWORD\`; \`bin/up --skip-fixtures\` keeps one changed in the admin.
474
551
  To load them by hand:
475
552
 
@@ -482,7 +559,7 @@ docker compose exec php bin/console doctrine:fixtures:load --append
482
559
 
483
560
  A [CWA](https://github.com/components-web-app/components-web-app) project.
484
561
 
485
- ## Features
562
+ ## Components
486
563
 
487
564
  ${featureList}
488
565
 
@@ -652,10 +729,11 @@ async function main(): Promise<void> {
652
729
  }
653
730
  }
654
731
 
655
- if (!answers.fixtures) {
656
- // Sample content only: UsersFixture stays, so the admin is still created from ADMIN_* (#142).
657
- await removeExcluded(tempDir, ['api/src/DataFixtures/AppScaffold.php', 'api/src/DataFixtures/Parts/'])
658
- }
732
+ // Starting content: UsersFixture always stays, so the admin is created from ADMIN_* (#142).
733
+ const contentExclude =
734
+ manifest.content?.[answers.content]?.exclude ??
735
+ (answers.content === 'empty' ? ['api/src/DataFixtures/AppScaffold.php', 'api/src/DataFixtures/Parts/'] : [])
736
+ await removeExcluded(tempDir, contentExclude)
659
737
 
660
738
  await processNuxtConfig(tempDir, answers.features)
661
739
  await replaceProjectName(tempDir, answers.projectName)
@@ -680,7 +758,7 @@ async function main(): Promise<void> {
680
758
  '(which your editor reads too) and runs the dev server.',
681
759
  '',
682
760
  'bin/up waits for all that, loads the fixtures (the admin' +
683
- (answers.fixtures ? ' and sample pages' : '') +
761
+ (answers.content === 'demo' ? ' and the example pages' : answers.content === 'home' ? ' and the home page' : '') +
684
762
  '),',
685
763
  'pre-compiles the first pages and prints where to sign in. Run it again any time.',
686
764
  ]
package/src/types.ts CHANGED
@@ -3,6 +3,8 @@ export interface ManifestChoice {
3
3
  label: string
4
4
  hint?: string
5
5
  requires?: string[]
6
+ // Pre-selected in a multiselect, and what --yes picks.
7
+ selected?: boolean
6
8
  }
7
9
 
8
10
  export interface ManifestQuestion {
@@ -11,7 +13,7 @@ export interface ManifestQuestion {
11
13
  message: string
12
14
  placeholder?: string
13
15
  hint?: string
14
- default?: boolean
16
+ default?: boolean | string
15
17
  choices?: ManifestChoice[]
16
18
  }
17
19
 
@@ -34,11 +36,15 @@ export interface Manifest {
34
36
  questions: ManifestQuestion[]
35
37
  features: Record<string, ManifestFeature>
36
38
  ci: Record<string, ManifestCi>
39
+ // Starting content (demo, home, empty): the files each level removes. Missing in templates before 2.0.0-alpha.55.
40
+ content?: Record<string, ManifestCi>
37
41
  }
38
42
 
39
43
  export interface Answers {
40
44
  projectName: string
41
45
  ci: string
46
+ // kubernetes or server; none when there's no pipeline.
47
+ deploy: string
42
48
  features: string[]
43
- fixtures: boolean
49
+ content: string
44
50
  }