generator-chisel 2.0.0-alpha.10 → 2.0.0-alpha.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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  <!-- INSERT-NEW-ENTRIES-HERE -->
4
4
 
5
+ ## 2.0.0-alpha.12 (2024-11-12)
6
+
7
+ - Try adjusting commands ([1c322a0](https://github.com/xfiveco/generator-chisel/commit/1c322a0))
8
+
9
+ ## 2.0.0-alpha.11 (2024-11-12)
10
+
11
+ - V2: Add Devcontainers (#538) ([b878421](https://github.com/xfiveco/generator-chisel/commit/b878421)), closes [#538](https://github.com/xfiveco/generator-chisel/issues/538)
12
+ - composer, wp-config, plugins list updates ([642f983](https://github.com/xfiveco/generator-chisel/commit/642f983))
13
+
5
14
  ## 2.0.0-alpha.10 (2024-10-31)
6
15
 
7
16
  - add assets index ([fed4fd3](https://github.com/xfiveco/generator-chisel/commit/fed4fd3))
package/bin/chisel.js CHANGED
@@ -19,6 +19,12 @@ const createProgram = () => {
19
19
  '--link',
20
20
  'link Chisel packages (yarn link) in created project (for development)',
21
21
  )
22
+ .option('--devcontainer', 'create devcontainer', false)
23
+ .option(
24
+ '--devcontainer-complete <details>',
25
+ 'complete creation inside devcontainer',
26
+ false
27
+ )
22
28
  .action((...args) => {
23
29
  const cmd = args.slice(-1)[0];
24
30
  args = args.slice(0, -1);
@@ -15,6 +15,12 @@ module.exports = class Creator {
15
15
  this.args = opts.args;
16
16
  this.cmd = opts.cmd;
17
17
  this.index = 0;
18
+
19
+ if (this.cmd.devcontainerComplete) {
20
+ this.data.devcontainerComplete = JSON.parse(
21
+ Buffer.from(this.cmd.devcontainerComplete, 'base64').toString(),
22
+ );
23
+ }
18
24
  }
19
25
 
20
26
  schedule(priority, action) {
@@ -4,6 +4,9 @@
4
4
  "composer/installers": true,
5
5
  "php-http/discovery": true,
6
6
  "dealerdirect/phpcodesniffer-composer-installer": true
7
+ },
8
+ "platform": {
9
+ "php": "7.4"
7
10
  }
8
11
  },
9
12
  "require-dev": {
@@ -6,8 +6,12 @@
6
6
  "author": "<%= app.author %>",
7
7
  "description": "Chisel WP",
8
8
  "scripts": {
9
+ "devcontainer": "npx @devcontainers/cli@0.71",
10
+ "devcontainer:up": "npm run --silent devcontainer -- up --workspace-folder ../../..",
11
+ "devcontainer:enter": "../../../.devcontainer/exec bash",
12
+ "devcontainer:start": "../../../.devcontainer/exec npm run --silent start",
9
13
  "start": "chisel-scripts start",
10
- "dev": "npm run start",
14
+ "dev": "npm run --silent start",
11
15
  "build": "chisel-scripts build && npm run lint && npm run phpcs && npm run twigcs",
12
16
  "build-scripts": "chisel-scripts build",
13
17
  "add-page": "chisel-scripts add-page",
@@ -1,6 +1,5 @@
1
1
  const path = require('path');
2
2
  const { startCase } = require('lodash');
3
- const speakingUrl = require('speakingurl');
4
3
  const {
5
4
  execa,
6
5
  run,
@@ -8,6 +7,8 @@ const {
8
7
  installDependencies,
9
8
  } = require('chisel-shared-utils');
10
9
  const packagesVersions = require('../../packages-versions');
10
+ const { prepareName, getWordpressVersion } = require('../utils');
11
+ const fs = require('fs/promises');
11
12
 
12
13
  module.exports = async (api) => {
13
14
  let app;
@@ -20,27 +21,40 @@ module.exports = async (api) => {
20
21
  timeout: 2000,
21
22
  }).catch(() => ({}));
22
23
 
23
- app = await api.prompt([
24
- {
25
- name: 'name',
26
- message: 'Please enter the project name:',
27
- default: () => startCase(path.basename(process.cwd())),
28
- validate: (val) => Boolean(val),
29
- },
30
- {
31
- name: 'author',
32
- message: 'Please enter author name:',
33
- default: async () => (await userName).stdout,
34
- },
35
- ]);
24
+ const { devcontainerComplete } = api.creator.data;
25
+
26
+ app = await api.prompt(
27
+ [
28
+ !devcontainerComplete && {
29
+ name: 'name',
30
+ message: 'Please enter the project name:',
31
+ default: () => startCase(path.basename(process.cwd())),
32
+ validate: (val) => Boolean(val),
33
+ },
34
+ !devcontainerComplete && {
35
+ type: 'number',
36
+ name: 'devcontainerPort',
37
+ message: 'Enter the devcontainer port:',
38
+ default: 3000,
39
+ validate: (val) => Boolean(val),
40
+ },
41
+ {
42
+ name: 'author',
43
+ message: 'Please enter author name:',
44
+ default: async () => (await userName).stdout,
45
+ validate: (val) => Boolean(val),
46
+ },
47
+ ].filter(Boolean),
48
+ );
36
49
 
37
- app.nameSlug = speakingUrl(app.name)
38
- .replace(/(?<=[^\d])-(\d+)/g, (_, d) => d)
39
- .replace(/[^a-z0-9-]/g, '-');
40
- // app.nameCamel = camelCase(app.nameSlug);
41
50
  app.hasJQuery = false;
42
- app.themeName = `${app.nameSlug}-chisel`;
43
- app.themePath = `wp-content/themes/${app.themeName}`;
51
+ app.wordpressVersion = await getWordpressVersion();
52
+
53
+ if (devcontainerComplete) {
54
+ Object.assign(app, devcontainerComplete);
55
+ }
56
+
57
+ Object.assign(app, prepareName(app.name));
44
58
 
45
59
  await api.creator.loadCreator('wp');
46
60
  });
@@ -86,6 +100,25 @@ module.exports = async (api) => {
86
100
  { cwd: api.resolve(app.themePath) },
87
101
  );
88
102
 
103
+ await api.modifyFile(
104
+ '.devcontainer/devcontainer.json',
105
+ async (body) => {
106
+ const extensionsText = await fs.readFile(
107
+ api.resolve(app.themePath, '.vscode/extensions.json'),
108
+ 'utf8',
109
+ );
110
+ const { recommendations } = JSON.parse(extensionsText);
111
+
112
+ return body.replace(
113
+ / +\/\/ EXTENSIONS-FROM-VSCODE-EXTENSIONS-FILE/,
114
+ recommendations
115
+ .map((ext) => ` ${JSON.stringify(ext)}`)
116
+ .join(',\n'),
117
+ );
118
+ },
119
+ { isJson: false },
120
+ );
121
+
89
122
  if (api.creator.cmd.link) {
90
123
  const availablePackages = Object.keys(packagesVersions);
91
124
  const installedAndAvailable = installedPackages.filter((pkg) =>
@@ -0,0 +1,21 @@
1
+ ARG BASE_IMAGE_VERSION
2
+ FROM wordpress:${BASE_IMAGE_VERSION}
3
+
4
+ ARG CHISEL_PORT=3000
5
+
6
+ # Install MariaDB Client
7
+ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
8
+ && apt-get -y install --no-install-recommends mariadb-client
9
+
10
+ # Install WP CLI
11
+ RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
12
+ && chmod +x wp-cli.phar \
13
+ && mv wp-cli.phar /usr/local/bin/wp
14
+
15
+ # Update port
16
+ RUN sed -i 's/80/${CHISEL_PORT}/' /etc/apache2/ports.conf
17
+
18
+ # Use wordpress user to run apache
19
+ ENV APACHE_RUN_USER wordpress
20
+ ENV APACHE_RUN_GROUP wordpress
21
+ ENV CHISEL_PORT=${CHISEL_PORT}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ docker compose -p <%= app.nameSlug %>_devcontainer <%= '"${@}"' %>
@@ -0,0 +1,31 @@
1
+ // For format details, see https://aka.ms/devcontainer.json.
2
+ {
3
+ "name": "WordPress Development",
4
+ "dockerComposeFile": "docker-compose.yml",
5
+ "service": "app",
6
+ // when changing workspace name or theme path, also update the docker-compose.yml file
7
+ "workspaceFolder": "/workspaces/<%= app.nameSlug %>/<%= app.themePath %>",
8
+
9
+ // Features to add to the dev container. More info: https://containers.dev/features.
10
+ "features": {
11
+ "ghcr.io/devcontainers/features/common-utils:2": {
12
+ "username": "wordpress"
13
+ },
14
+ "ghcr.io/devcontainers/features/node:1": {
15
+ "version": "20"
16
+ },
17
+ "ghcr.io/devcontainers/features/git:1": {}
18
+ },
19
+
20
+ "postCreateCommand": "bash ../../../.devcontainer/post-create-command.sh",
21
+
22
+ "remoteUser": "wordpress",
23
+
24
+ "customizations": {
25
+ "vscode": {
26
+ "extensions": [
27
+ // EXTENSIONS-FROM-VSCODE-EXTENSIONS-FILE
28
+ ]
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,42 @@
1
+ version: '3.8'
2
+
3
+ name: <%= app.nameSlug %>_devcontainer
4
+
5
+ services:
6
+ app:
7
+ build:
8
+ context: .
9
+ dockerfile: Dockerfile
10
+ args:
11
+ # Keep this in sync with installed WordPress version and
12
+ # PHP version used in production
13
+ # See https://hub.docker.com/_/wordpress for available versions
14
+ BASE_IMAGE_VERSION: <%= app.wordpressVersion %>-php8.3
15
+ CHISEL_PORT: <%= app.devcontainerPort %>
16
+
17
+ ports:
18
+ - '127.0.0.1:<%= app.devcontainerPort %>:<%= app.devcontainerPort %>' # should be CHISEL_PORT
19
+ - '127.0.0.1:<%= app.devcontainerPort + 1 %>:<%= app.devcontainerPort + 1 %>' # should be CHISEL_PORT + 1
20
+
21
+ volumes:
22
+ - ..:/workspaces/<%= app.nameSlug %>
23
+ - ..:/var/www/html
24
+ - node_modules:/workspaces/<%= app.nameSlug %>/wp-content/themes/<%= app.themeName %>/node_modules
25
+ - vendor:/workspaces/<%= app.nameSlug %>/wp-content/themes/<%= app.themeName %>/vendor
26
+ - vendor:/var/www/html/wp-content/themes/<%= app.themeName %>/vendor
27
+
28
+ db:
29
+ image: mariadb:11.4
30
+ restart: unless-stopped
31
+ volumes:
32
+ - db:/var/lib/mysql
33
+ environment:
34
+ MYSQL_ROOT_PASSWORD: mariadb
35
+ MYSQL_DATABASE: mariadb
36
+ MYSQL_USER: mariadb
37
+ MYSQL_PASSWORD: mariadb
38
+
39
+ volumes:
40
+ db:
41
+ vendor:
42
+ node_modules:
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [ -f /.dockerenv ]; then
4
+ exec "${@}"
5
+ else
6
+ this_file_dir=$(dirname "${BASH_SOURCE[0]}")
7
+ npm run --silent devcontainer -- exec --workspace-folder "${this_file_dir}/.." "${@}"
8
+ fi
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ set -eux
4
+
5
+ sudo chown "$USER:$USER" node_modules vendor
6
+
7
+ pushd ../../..
8
+
9
+ sudo chown "$USER:$USER" . index.php wp-config.php
10
+ if [ -d .git ] ; then sudo chown "$USER:$USER" .git ; fi
11
+ chmod +x .devcontainer/compose .devcontainer/exec
12
+ <% if (app.devcontainer) { %>
13
+ {
14
+ npx --yes generator-chisel@<%= chiselVersion %> --devcontainer-complete <%= app.responsesAsBase64 %>
15
+ exit
16
+ }
17
+ <% } %>
18
+ popd
19
+ <% if (!app.devcontainer) { %>
20
+ npm install
21
+ npm run wp-config -- --devcontainer
22
+ npm run composer install
23
+ npm run build<% } %>
@@ -0,0 +1,62 @@
1
+ const { prepareName, getWordpressVersion } = require('./utils');
2
+ const fsPromises = require('fs/promises');
3
+
4
+ module.exports = async (api) => {
5
+ let app;
6
+
7
+ api.schedule(api.PRIORITIES.PROMPT, async () => {
8
+ app = await api.prompt([
9
+ {
10
+ name: 'name',
11
+ message: 'Please enter the project name:',
12
+ validate: (val) => Boolean(val),
13
+ },
14
+ {
15
+ type: 'number',
16
+ name: 'devcontainerPort',
17
+ message: 'Enter the devcontainer port:',
18
+ default: 3000,
19
+ validate: (val) => Boolean(val),
20
+ },
21
+ ]);
22
+
23
+ const responsesAsBase64 = Buffer.from(JSON.stringify(app)).toString(
24
+ 'base64'
25
+ );
26
+
27
+ Object.assign(app, prepareName(app.name));
28
+ app.devcontainer = true;
29
+ app.responsesAsBase64 = responsesAsBase64;
30
+ app.wordpressVersion = await getWordpressVersion();
31
+ api.creator.data.app = app;
32
+ });
33
+
34
+ api.schedule(api.PRIORITIES.COPY, async () => {
35
+ await api.copy({
36
+ from: '../app/template/.devcontainer',
37
+ to: '.devcontainer',
38
+ });
39
+
40
+ await fsPromises.mkdir(api.creator.data.app.themePath, {
41
+ recursive: true,
42
+ });
43
+
44
+ await fsPromises.writeFile('index.php', '');
45
+ await fsPromises.writeFile('wp-config.php', '');
46
+ });
47
+
48
+ api.schedule(api.PRIORITIES.END_MESSAGE, async () => {
49
+ console.log(`
50
+ Devcontainer definition is ready.
51
+
52
+ To continue creating the project do one of the following:
53
+
54
+ 1. If you are using VS Code, open the folder in VS Code and run
55
+ "Dev Containers: Reopen in Container" from the command palette.
56
+
57
+ 2. Otherwise you have to use Dev Containers CLI to start the container:
58
+ > npx -y @devcontainers/cli@latest up --workspace-folder .
59
+ (dot at the end is part of the command)
60
+ `);
61
+ });
62
+ };
@@ -0,0 +1,28 @@
1
+ module.exports.prepareName = (name) => {
2
+ const speakingUrl = require('speakingurl');
3
+ const nameSlug = speakingUrl(name)
4
+ .replace(/(?<=[^\d])-(\d+)/g, (_, d) => d)
5
+ .replace(/[^a-z0-9-]/g, '-');
6
+
7
+ const themeName = `${nameSlug}-chisel`;
8
+
9
+ return {
10
+ nameSlug,
11
+ themeName,
12
+ themePath: `wp-content/themes/${themeName}`,
13
+ };
14
+ };
15
+
16
+ module.exports.getWordpressVersion = async () => {
17
+ const response = await fetch(
18
+ 'https://api.wordpress.org/core/version-check/1.7/',
19
+ );
20
+
21
+ if (!response.ok) {
22
+ throw new Error('Failed to fetch WordPress version');
23
+ }
24
+
25
+ const data = await response.json();
26
+
27
+ return data.offers.find((offer) => offer.response === 'upgrade').version;
28
+ };
@@ -26,16 +26,31 @@ module.exports = (api) => {
26
26
  const userName = gitConfig('user.name');
27
27
  const userEmail = gitConfig('user.email');
28
28
 
29
+ let url = `http://${api.creator.data.app.nameSlug}.test/`;
30
+ const { devcontainerPort } = api.creator.data.app;
31
+
32
+ if (process.env.CODESPACES === 'true') {
33
+ const {
34
+ CODESPACE_NAME,
35
+ GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN,
36
+ } = process.env;
37
+ url = `https://${CODESPACE_NAME}-${devcontainerPort}.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/`;
38
+ } else if (await fs.exists('/.dockerenv')) {
39
+ url = `http://127.0.0.1:${devcontainerPort}/`;
40
+ }
41
+
29
42
  await api.prompt([
30
43
  {
31
44
  name: 'title',
32
45
  message: 'Enter title for the new site:',
33
46
  default: api.creator.data.app.name,
47
+ validate: (val) => Boolean(val),
34
48
  },
35
49
  {
36
50
  name: 'url',
37
51
  message: 'Enter URL:',
38
- default: `http://${api.creator.data.app.nameSlug}.test/`,
52
+ default: url,
53
+ validate: (val) => Boolean(val),
39
54
  },
40
55
  {
41
56
  name: 'adminUser',
@@ -47,6 +62,7 @@ module.exports = (api) => {
47
62
  nameParts[0].toLowerCase() + Math.floor(1000 + Math.random() * 9000)
48
63
  );
49
64
  },
65
+ validate: (val) => Boolean(val),
50
66
  },
51
67
  {
52
68
  name: 'adminPassword',
@@ -88,7 +104,6 @@ module.exports = (api) => {
88
104
  `${api.creator.data.app.themePath}/package.json`,
89
105
  (body) => {
90
106
  body.chisel = {
91
- url: api.creator.data.wp.url,
92
107
  tablePrefix,
93
108
  };
94
109
  },
@@ -104,7 +119,13 @@ module.exports = (api) => {
104
119
  api.schedule(api.PRIORITIES.WP_CONFIG, async () => {
105
120
  if (api.creator.cmd.skipWpConfig) return;
106
121
 
107
- await runLocal(['chisel-scripts', 'wp-config'], {
122
+ const extraArgs = [];
123
+
124
+ if (api.creator.data.devcontainerComplete) {
125
+ extraArgs.push('--devcontainer');
126
+ }
127
+
128
+ await runLocal(['chisel-scripts', 'wp-config', ...extraArgs], {
108
129
  cwd: api.resolve(themePath),
109
130
  execaOpts: { stdio: 'inherit' },
110
131
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "plugins": {
3
- "WP Premium: Gravity Forms": "https://github.com/wp-premium/gravityforms/archive/master.zip",
3
+ "WP Premium: Gravity Forms": "https://github.com/pronamic/gravityforms/archive/master.zip",
4
4
  "SVG Support": "svg-support",
5
5
  "Yoast SEO": "wordpress-seo",
6
6
  "Yoast SEO ACF": "acf-content-analysis-for-yoast-seo"
@@ -3,8 +3,15 @@ const Creator = require('./Creator');
3
3
  const createCommand = async ({ args, cmd }) => {
4
4
  const creator = new Creator(undefined, { args, cmd });
5
5
 
6
- await creator.loadCreator('init');
7
- await creator.loadCreator('app');
6
+ if (cmd.devcontainer) {
7
+ await creator.loadCreator('devcontainer');
8
+ } else {
9
+ if (!cmd.devcontainerComplete) {
10
+ await creator.loadCreator('init');
11
+ }
12
+
13
+ await creator.loadCreator('app');
14
+ }
8
15
 
9
16
  return creator.run();
10
17
  };
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- 'chisel-scripts': '2.0.0-alpha.3.1',
3
- 'chisel-shared-utils': '2.0.0-alpha.0',
4
- 'generator-chisel': '2.0.0-alpha.10',
2
+ 'chisel-scripts': '2.0.0-alpha.4',
3
+ 'chisel-shared-utils': '2.0.0-alpha.1',
4
+ 'generator-chisel': '2.0.0-alpha.12',
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-chisel",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.12",
4
4
  "description": "A generator for scaffolding front-end and WordPress projects",
5
5
  "bin": {
6
6
  "chisel": "bin/chisel.js"
@@ -26,7 +26,7 @@
26
26
  "babel"
27
27
  ],
28
28
  "dependencies": {
29
- "chisel-shared-utils": "^2.0.0-alpha.0",
29
+ "chisel-shared-utils": "^2.0.0-alpha.1",
30
30
  "commander": "^5.1.0",
31
31
  "execa": "^4.0.2",
32
32
  "fs-extra": "^9.0.1",
@@ -37,5 +37,5 @@
37
37
  "tinyqueue": "^2.0.3",
38
38
  "update-notifier": "^4.1.0"
39
39
  },
40
- "gitHead": "92466fd4d8e4a29e588345c304f5040d428b567a"
40
+ "gitHead": "1935bf86091473b23e1d44fefab87a59c37d80fe"
41
41
  }