From 5802a4d1aef153033f19737d621e5a2b5ac0b59c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 6 Jun 2024 16:25:16 +0000 Subject: [PATCH 1/4] chore: promote from @next --- .changeset/clean-ravens-film.md | 5 ----- .changeset/fifty-ants-call.md | 5 ----- .changeset/gorgeous-ants-grow.md | 5 ----- .changeset/hip-toys-learn.md | 5 ----- .changeset/poor-birds-rhyme.md | 5 ----- .changeset/pre.json | 22 ---------------------- .changeset/weak-oranges-promise.md | 5 ----- .changeset/yellow-pumpkins-fail.md | 5 ----- packages/eslint-config/CHANGELOG.md | 6 ++++++ packages/eslint-config/package.json | 2 +- packages/toolkit/CHANGELOG.md | 14 ++++++++++++++ packages/toolkit/package.json | 4 ++-- projects/10up-theme/package.json | 2 +- projects/library-ts/package.json | 2 +- projects/library/package.json | 2 +- 15 files changed, 26 insertions(+), 63 deletions(-) delete mode 100644 .changeset/clean-ravens-film.md delete mode 100644 .changeset/fifty-ants-call.md delete mode 100644 .changeset/gorgeous-ants-grow.md delete mode 100644 .changeset/hip-toys-learn.md delete mode 100644 .changeset/poor-birds-rhyme.md delete mode 100644 .changeset/pre.json delete mode 100644 .changeset/weak-oranges-promise.md delete mode 100644 .changeset/yellow-pumpkins-fail.md diff --git a/.changeset/clean-ravens-film.md b/.changeset/clean-ravens-film.md deleted file mode 100644 index 5fbbd440..00000000 --- a/.changeset/clean-ravens-film.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": patch ---- - -Fix: watch close when using modules diff --git a/.changeset/fifty-ants-call.md b/.changeset/fifty-ants-call.md deleted file mode 100644 index a099dd02..00000000 --- a/.changeset/fifty-ants-call.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": minor ---- - -Project Command (BETA) diff --git a/.changeset/gorgeous-ants-grow.md b/.changeset/gorgeous-ants-grow.md deleted file mode 100644 index ebfbacad..00000000 --- a/.changeset/gorgeous-ants-grow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": patch ---- - -Fix project init command diff --git a/.changeset/hip-toys-learn.md b/.changeset/hip-toys-learn.md deleted file mode 100644 index 59492e4a..00000000 --- a/.changeset/hip-toys-learn.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@10up/eslint-config": minor ---- - -Update eslint rule for typescript to use default arguments for default props. diff --git a/.changeset/poor-birds-rhyme.md b/.changeset/poor-birds-rhyme.md deleted file mode 100644 index 1161255d..00000000 --- a/.changeset/poor-birds-rhyme.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": patch ---- - -Fix init command diff --git a/.changeset/pre.json b/.changeset/pre.json deleted file mode 100644 index 70efd46b..00000000 --- a/.changeset/pre.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "mode": "pre", - "tag": "next", - "initialVersions": { - "@10up/babel-preset-default": "2.1.1", - "@10up/eslint-config": "4.0.0", - "@10up/stylelint-config": "3.0.0", - "10up-toolkit": "6.1.0", - "tenup-theme": "1.1.5-next.7", - "@10up/component-accordion": "2.1.5", - "@10up/library-ts-test": "2.1.5" - }, - "changesets": [ - "clean-ravens-film", - "fifty-ants-call", - "gorgeous-ants-grow", - "hip-toys-learn", - "poor-birds-rhyme", - "weak-oranges-promise", - "yellow-pumpkins-fail" - ] -} diff --git a/.changeset/weak-oranges-promise.md b/.changeset/weak-oranges-promise.md deleted file mode 100644 index aa82f875..00000000 --- a/.changeset/weak-oranges-promise.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": patch ---- - -Refactor init command diff --git a/.changeset/yellow-pumpkins-fail.md b/.changeset/yellow-pumpkins-fail.md deleted file mode 100644 index 484cdafd..00000000 --- a/.changeset/yellow-pumpkins-fail.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": patch ---- - -Update `project` command to use latest diff --git a/packages/eslint-config/CHANGELOG.md b/packages/eslint-config/CHANGELOG.md index c4843a82..c982f33d 100644 --- a/packages/eslint-config/CHANGELOG.md +++ b/packages/eslint-config/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 4.1.0 + +### Minor Changes + +- 5ddee2c: Update eslint rule for typescript to use default arguments for default props. + ## 4.1.0-next.0 ### Minor Changes diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 63ce54c6..10f4d496 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@10up/eslint-config", - "version": "4.1.0-next.0", + "version": "4.1.0", "description": "A shareable ESLint configuration", "publishConfig": { "access": "public" diff --git a/packages/toolkit/CHANGELOG.md b/packages/toolkit/CHANGELOG.md index eed15807..6971df6a 100644 --- a/packages/toolkit/CHANGELOG.md +++ b/packages/toolkit/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 6.2.0 + +### Minor Changes + +- dba1534: Project Command (BETA) + +### Patch Changes + +- dcc09bb: Fix: watch close when using modules +- 1aba76c: Fix project init command +- 58d5861: Fix init command +- d9f3642: Refactor init command +- 1f612a2: Update `project` command to use latest + ## 6.2.0-next.4 ### Patch Changes diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index ceba1d9b..ed328b3b 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -13,7 +13,7 @@ "url": "git+https://github.com/10up/10up-toolkit.git", "directory": "packages/toolkit" }, - "version": "6.2.0-next.4", + "version": "6.2.0", "bin": { "10up-toolkit": "bin/10up-toolkit.js" }, @@ -74,7 +74,7 @@ }, "devDependencies": { "@10up/babel-preset-default": ">=2.1.1", - "@10up/eslint-config": ">=4.1.0-next.0", + "@10up/eslint-config": ">=4.1.0", "@10up/stylelint-config": ">=3.0.0" }, "peerDependencies": { diff --git a/projects/10up-theme/package.json b/projects/10up-theme/package.json index ab77a64d..e0b822bc 100644 --- a/projects/10up-theme/package.json +++ b/projects/10up-theme/package.json @@ -20,7 +20,7 @@ "@linaria/babel-preset": "^5.0.3", "@linaria/webpack-loader": "^5.0.3", "@wordpress/env": "^5.0.0", - "10up-toolkit": "^6.2.0-next.4" + "10up-toolkit": "^6.2.0" }, "dependencies": { "@10up/block-components": "^1.18.0", diff --git a/projects/library-ts/package.json b/projects/library-ts/package.json index 3f5a3b2b..e7f0ebc8 100644 --- a/projects/library-ts/package.json +++ b/projects/library-ts/package.json @@ -39,7 +39,7 @@ }, "homepage": "https://github.com/10up/component-accordion#readme", "devDependencies": { - "10up-toolkit": "^6.2.0-next.4" + "10up-toolkit": "^6.2.0" }, "dependencies": { "xss": "^1.0.11" diff --git a/projects/library/package.json b/projects/library/package.json index 354aec04..53c40fb4 100644 --- a/projects/library/package.json +++ b/projects/library/package.json @@ -26,7 +26,7 @@ }, "homepage": "https://github.com/10up/component-accordion#readme", "devDependencies": { - "10up-toolkit": "^6.2.0-next.4", + "10up-toolkit": "^6.2.0", "@testing-library/dom": "9.3.3", "@testing-library/jest-dom": "^6.2.0", "@testing-library/user-event": "^14.5.2", From 5fb8675c322902e1f11c1a225a96499180b09c6f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 4 Jul 2024 00:37:10 +0000 Subject: [PATCH 2/4] chore: version packages --- .changeset/great-plants-fail.md | 5 ----- packages/toolkit/CHANGELOG.md | 6 ++++++ packages/toolkit/package.json | 2 +- projects/10up-theme/package.json | 2 +- projects/library-ts/package.json | 2 +- projects/library/package.json | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 .changeset/great-plants-fail.md diff --git a/.changeset/great-plants-fail.md b/.changeset/great-plants-fail.md deleted file mode 100644 index fc59c7d9..00000000 --- a/.changeset/great-plants-fail.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"10up-toolkit": patch ---- - -Fixing git clone path inside project command to support paths with spaces. diff --git a/packages/toolkit/CHANGELOG.md b/packages/toolkit/CHANGELOG.md index 6971df6a..c1665d4e 100644 --- a/packages/toolkit/CHANGELOG.md +++ b/packages/toolkit/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 6.2.1 + +### Patch Changes + +- 868ffdc: Fixing git clone path inside project command to support paths with spaces. + ## 6.2.0 ### Minor Changes diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index ed328b3b..7fed69e4 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -13,7 +13,7 @@ "url": "git+https://github.com/10up/10up-toolkit.git", "directory": "packages/toolkit" }, - "version": "6.2.0", + "version": "6.2.1", "bin": { "10up-toolkit": "bin/10up-toolkit.js" }, diff --git a/projects/10up-theme/package.json b/projects/10up-theme/package.json index e0b822bc..6512f942 100644 --- a/projects/10up-theme/package.json +++ b/projects/10up-theme/package.json @@ -20,7 +20,7 @@ "@linaria/babel-preset": "^5.0.3", "@linaria/webpack-loader": "^5.0.3", "@wordpress/env": "^5.0.0", - "10up-toolkit": "^6.2.0" + "10up-toolkit": "^6.2.1" }, "dependencies": { "@10up/block-components": "^1.18.0", diff --git a/projects/library-ts/package.json b/projects/library-ts/package.json index e7f0ebc8..4070491a 100644 --- a/projects/library-ts/package.json +++ b/projects/library-ts/package.json @@ -39,7 +39,7 @@ }, "homepage": "https://github.com/10up/component-accordion#readme", "devDependencies": { - "10up-toolkit": "^6.2.0" + "10up-toolkit": "^6.2.1" }, "dependencies": { "xss": "^1.0.11" diff --git a/projects/library/package.json b/projects/library/package.json index 53c40fb4..c4b63b54 100644 --- a/projects/library/package.json +++ b/projects/library/package.json @@ -26,7 +26,7 @@ }, "homepage": "https://github.com/10up/component-accordion#readme", "devDependencies": { - "10up-toolkit": "^6.2.0", + "10up-toolkit": "^6.2.1", "@testing-library/dom": "9.3.3", "@testing-library/jest-dom": "^6.2.0", "@testing-library/user-event": "^14.5.2", From 769278427256468da838b8e0aa33c8c85d054582 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Wed, 21 Aug 2024 15:38:16 -0400 Subject: [PATCH 3/4] Squashed commit of the following: commit 8b74e5a02bdedc2e62b03d338c119629be2afd14 Author: Dustin Rue Date: Wed Aug 21 14:36:32 2024 -0500 Feature/add more flexibility (#413) Co-authored-by: Taylor Lovett --- .changeset/eight-pumpkins-provide.md | 5 + packages/toolkit/PROJECTS.md | 24 +- .../toolkit/project/default-variables.json | 3 - .../toolkit/project/gitlab/.gitlab-ci.tmpl | 2 +- .../deploy-configs/pantheon-production.tmpl | 2 +- .../deploy-configs/pantheon-staging.tmpl | 2 +- .../deploy-configs/rsync-production.tmpl | 2 +- .../gitlab/deploy-configs/rsync-staging.tmpl | 2 +- packages/toolkit/project/local/.gitignore | 26 ++ .../toolkit/project/local/scripts/build.sh | 21 +- ...deploy-excludes.txt => rsync-excludes.txt} | 0 .../toolkit/scripts/project/bash/Dockerfile | 7 + .../scripts/project/bash/build-setup.sh | 13 - .../scripts/project/bash/create-payload.sh | 20 -- .../toolkit/scripts/project/bash/scripts.sh | 239 ++++++++++++++++++ packages/toolkit/scripts/project/build.js | 28 +- .../toolkit/scripts/project/create-payload.js | 62 ----- packages/toolkit/scripts/project/init.js | 169 +++++++------ packages/toolkit/scripts/project/package.js | 35 +++ .../scripts/project/update-composer.js | 35 +++ packages/toolkit/utils/index.js | 2 + packages/toolkit/utils/project.js | 90 +++++-- 22 files changed, 548 insertions(+), 241 deletions(-) create mode 100644 .changeset/eight-pumpkins-provide.md create mode 100644 packages/toolkit/project/local/.gitignore rename packages/toolkit/project/local/scripts/{deploy-excludes.txt => rsync-excludes.txt} (100%) create mode 100644 packages/toolkit/scripts/project/bash/Dockerfile delete mode 100644 packages/toolkit/scripts/project/bash/build-setup.sh delete mode 100644 packages/toolkit/scripts/project/bash/create-payload.sh create mode 100644 packages/toolkit/scripts/project/bash/scripts.sh delete mode 100644 packages/toolkit/scripts/project/create-payload.js mode change 100644 => 100755 packages/toolkit/scripts/project/init.js create mode 100644 packages/toolkit/scripts/project/package.js create mode 100644 packages/toolkit/scripts/project/update-composer.js diff --git a/.changeset/eight-pumpkins-provide.md b/.changeset/eight-pumpkins-provide.md new file mode 100644 index 00000000..81296755 --- /dev/null +++ b/.changeset/eight-pumpkins-provide.md @@ -0,0 +1,5 @@ +--- +"10up-toolkit": patch +--- + +Simple enhancements to toolkit project command to align with devops needs. diff --git a/packages/toolkit/PROJECTS.md b/packages/toolkit/PROJECTS.md index e1f8e2cf..5dcd94fe 100644 --- a/packages/toolkit/PROJECTS.md +++ b/packages/toolkit/PROJECTS.md @@ -58,14 +58,6 @@ In this scenario, `deploy_from` would be set to `wp` and `deploy_to_subdir` woul `deploy_type` currently supports `rsync`, `wpe` (WP Engine), and `pantheon`. It defaults to `rsync`. If WPE or Pantheon is choosen, `deploy_to` should contain a Git URL. More deploy types will be added in the future. -The following are additional optional variables that allow you to use custom scripts different than the ones provided by 10up Toolkit. You shouldn't need to use these unless you are doing something super custom. All these paths are relative from the root of your project. - -```yaml -deploy_script_path: "" # Custom deploy script -build_script_path: "" # For using a build script in a different location -create_payload_script_path: "" # Custom create payload script -``` - ## Commands The project subcommand provides a variety of utlities for creating, building, and deploying 10up-specific projects. @@ -73,27 +65,27 @@ The project subcommand provides a variety of utlities for creating, building, an List of commands: ```bash -10up-toolkit project init [] [--template=] [--name=] [--confirm] [--skip-composer] +10up-toolkit project init [--path=] [--layout=] [--template=] [--name=] [--confirm] [--skip-composer] [--skip-ci] ``` -`init` creates a project. You can optionally provide it a number of parameters or answer the prompts. If no path is provided, it will initialize the project in the current directory. You will be prompted to choose a template e.g. [WP Scaffold](https://github.com/10up/wp-scaffold). Init will automatically search and replace prefixes using the project name you provide. +`init` creates a project. You can optionally provide it a number of parameters or answer the prompts. If no path is provided, it will initialize the project in the current directory. If no layout is provided, it will default to `wpcontent` which means the project is rooted in `wp-content` (The other option is `wpparent` where the root of the project is one directory above WordPress). You will be prompted to choose a template e.g. [WP Scaffold](https://github.com/10up/wp-scaffold). Init will automatically search and replace prefixes using the project name you provide. ```bash -10up-toolkit project build +10up-toolkit project build [--type=] ``` -`build` simply executes your `scripts/build.sh` file (or other path you specify). `build` will be executed before deploying files. +`build` will build your project e.g. `composer install`, `npm install`, and `npm run build`. It will execute all the `.sh` files in your `scripts/` directory where you can add custom build logic for your particular project. `--type` defaults to local e.g. build for your local environment. In CI, type will be set to `full`. ```bash -10up-toolkit project create-payload +10up-toolkit project generate-ci [--confirm] [--path=] ``` -This command creates a payload directory of the built project (including WordPress) for deployment. Engineers likely won't need to run this command themselves as GitLab does it automatically. You must provide a branch that corresponds to an environment in `.tenup.yml`. +This command generates necessary CI files. For GitLab, this would be `.gitlab-ci.yml`. Right now this only supports GitLab but we will add support for GitHub in the future. ```bash -10up-toolkit project generate-ci [--confirm] [--path=] +10up-toolkit project update-composer ``` -This command generates necessary CI files. For GitLab, this would be `.gitlab-ci.yml`. Right now this only supports GitLab but we will add support for GitHub in the future. +Convenience function to update all dependencies in all found composer.json files. Also generates updated lock files. **Note that generating CI files is currently in alpha and may require manual editing to fix issues.** diff --git a/packages/toolkit/project/default-variables.json b/packages/toolkit/project/default-variables.json index b1b1a4a7..f15098cb 100644 --- a/packages/toolkit/project/default-variables.json +++ b/packages/toolkit/project/default-variables.json @@ -1,9 +1,6 @@ { "project_name": "10up Project", "php_version": "8.2", - "build_script_path": "", "wordpress_version": "", - "deploy_script_path": "", - "create_payload_script_path": "", "environments": [] } diff --git a/packages/toolkit/project/gitlab/.gitlab-ci.tmpl b/packages/toolkit/project/gitlab/.gitlab-ci.tmpl index 81fc5b15..2f8bc3e1 100644 --- a/packages/toolkit/project/gitlab/.gitlab-ci.tmpl +++ b/packages/toolkit/project/gitlab/.gitlab-ci.tmpl @@ -25,7 +25,7 @@ build_plugins_and_themes: stage: build script: - nvm install 18 - - npx 10up-toolkit project create-payload $CI_COMMIT_REF_NAME + - npx 10up-toolkit project build --type=full artifacts: paths: - payload diff --git a/packages/toolkit/project/gitlab/deploy-configs/pantheon-production.tmpl b/packages/toolkit/project/gitlab/deploy-configs/pantheon-production.tmpl index a3b01e80..a89db894 100644 --- a/packages/toolkit/project/gitlab/deploy-configs/pantheon-production.tmpl +++ b/packages/toolkit/project/gitlab/deploy-configs/pantheon-production.tmpl @@ -7,7 +7,7 @@ deploy_production: MULTI_DEV_ENVIRONMENT: "{{branch}}" WORDPRESS_VERSION: {{wordpress_version}} GIT_URL: {{deploy_to}} - EXCLUDES: {{deploy_file_excludes}} + EXCLUDES: {{rsync_file_excludes}} allow_failure: false only: refs: diff --git a/packages/toolkit/project/gitlab/deploy-configs/pantheon-staging.tmpl b/packages/toolkit/project/gitlab/deploy-configs/pantheon-staging.tmpl index a4bc4a2f..24b2bbf3 100644 --- a/packages/toolkit/project/gitlab/deploy-configs/pantheon-staging.tmpl +++ b/packages/toolkit/project/gitlab/deploy-configs/pantheon-staging.tmpl @@ -7,7 +7,7 @@ deploy_{{branch}}: MULTI_DEV_ENVIRONMENT: "{{branch}}" WORDPRESS_VERSION: {{wordpress_version}} GIT_URL: {{deploy_to}} - EXCLUDES: {{deploy_file_excludes}} + EXCLUDES: {{rsync_file_excludes}} allow_failure: false only: refs: diff --git a/packages/toolkit/project/gitlab/deploy-configs/rsync-production.tmpl b/packages/toolkit/project/gitlab/deploy-configs/rsync-production.tmpl index 36820df4..5862fe35 100644 --- a/packages/toolkit/project/gitlab/deploy-configs/rsync-production.tmpl +++ b/packages/toolkit/project/gitlab/deploy-configs/rsync-production.tmpl @@ -7,7 +7,7 @@ deploy_production: variables: DESTINATION: {{deploy_to}} SUBDIR: {{deploy_to_subdir}} - EXCLUDES: {{deploy_file_excludes}} + EXCLUDES: {{rsync_file_excludes}} only: refs: - {{branch}} diff --git a/packages/toolkit/project/gitlab/deploy-configs/rsync-staging.tmpl b/packages/toolkit/project/gitlab/deploy-configs/rsync-staging.tmpl index 5f47a7f5..0a6ffe71 100644 --- a/packages/toolkit/project/gitlab/deploy-configs/rsync-staging.tmpl +++ b/packages/toolkit/project/gitlab/deploy-configs/rsync-staging.tmpl @@ -7,7 +7,7 @@ deploy_{{branch}}: variables: DESTINATION: {{deploy_to}} SUBDIR: {{deploy_to_subdir}} - EXCLUDES: {{deploy_file_excludes}} + EXCLUDES: {{rsync_file_excludes}} only: refs: - {{branch}} diff --git a/packages/toolkit/project/local/.gitignore b/packages/toolkit/project/local/.gitignore new file mode 100644 index 00000000..14fb7d13 --- /dev/null +++ b/packages/toolkit/project/local/.gitignore @@ -0,0 +1,26 @@ +payload +build/vendor +build/composer.lock +build/composer.json +/vendor +wordpress/.env +wordpress/*php +wordpress/wp-content/uploads +wordpress/wp-includes +wordpress/wp-admin +wordpress/license.txt +wordpress/readme.html +!wordpress/wp-config.php +docker-compose.override.yml +.config.json +wordpress/wp-content/advanced-cache.php +wordpress/wp-content/mu-plugins/10up-experience.php +wordpress/wp-content/mu-plugins/10up-experience/ +wordpress/wp-content/mu-plugins/batcache.php +wordpress/wp-content/mu-plugins/batcache/ +wordpress/wp-content/mu-plugins/redis-cache.php +wordpress/wp-content/mu-plugins/redis-cache/ +wordpress/wp-content/mu-plugins/s3-uploads.php +wordpress/wp-content/mu-plugins/s3-uploads/ +wordpress/wp-content/object-cache.php +.lock diff --git a/packages/toolkit/project/local/scripts/build.sh b/packages/toolkit/project/local/scripts/build.sh index 888d0435..1c372aed 100644 --- a/packages/toolkit/project/local/scripts/build.sh +++ b/packages/toolkit/project/local/scripts/build.sh @@ -1,5 +1,18 @@ -# Add builds scripts here. This script will be run from the root of your project (same directory as .tenup.yml). +#!/usr/bin/env bash -l +# NOTE: you should keep the above line, at line 1. Only modify if you know what you are doing. -nvm install -node -v -npm install +# You should use npx 10up-toolkit build to build your project. When you do, there are a number of things +# you get "for free" including nvm handling and the basics of building are handled automatically. You +# only need to provide additional build routines if the default build system doesn't quite get things +# right. Adding build scripts is easy. Create as many .sh files as you need in this scripts directory. + +# Here is an example script you can use to get you started It assumes you are using a "modern" layout. + +# change directories to your theme or plugin +pushd . + +# run your build commands +echo "Hello World!" + +# return to where we were so the next build script starts off from the same place +popd diff --git a/packages/toolkit/project/local/scripts/deploy-excludes.txt b/packages/toolkit/project/local/scripts/rsync-excludes.txt similarity index 100% rename from packages/toolkit/project/local/scripts/deploy-excludes.txt rename to packages/toolkit/project/local/scripts/rsync-excludes.txt diff --git a/packages/toolkit/scripts/project/bash/Dockerfile b/packages/toolkit/scripts/project/bash/Dockerfile new file mode 100644 index 00000000..666890b4 --- /dev/null +++ b/packages/toolkit/scripts/project/bash/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:latest + +USER root +WORKDIR /var/www/html +COPY payload . +RUN mkdir wp-content/uploads && \ + chown 33:33 wp-content/uploads diff --git a/packages/toolkit/scripts/project/bash/build-setup.sh b/packages/toolkit/scripts/project/bash/build-setup.sh deleted file mode 100644 index a6c5eb7b..00000000 --- a/packages/toolkit/scripts/project/bash/build-setup.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -maybe_init_nvm() { - - if [ $(find . -name .nvmrc | wc -l) -gt 0 ] && [ ! -f $NVM_DIR/nvm.sh ]; then - echo "This project requires nvm. Please install nvm and try again" - exit 1 - fi - - . $NVM_DIR/nvm.sh -} - -maybe_init_nvm diff --git a/packages/toolkit/scripts/project/bash/create-payload.sh b/packages/toolkit/scripts/project/bash/create-payload.sh deleted file mode 100644 index 91309781..00000000 --- a/packages/toolkit/scripts/project/bash/create-payload.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -download() { - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - fi -} - -rm -rf payload -mkdir payload -cd payload - -echo "Downloading WordPress $WORDPRESS_VERSION..." -download https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz wordpress.tar.gz -tar --strip-components=1 -zxmf wordpress.tar.gz -C . -rm wordpress.tar.gz - -rsync -avz --exclude-from=$deploy_file_excludes_absolute $project_root/$deploy_from $deploy_to_subdir diff --git a/packages/toolkit/scripts/project/bash/scripts.sh b/packages/toolkit/scripts/project/bash/scripts.sh new file mode 100644 index 00000000..1874770d --- /dev/null +++ b/packages/toolkit/scripts/project/bash/scripts.sh @@ -0,0 +1,239 @@ +#!/usr/bin/env bash -l + +SHARE_DIR="$(dirname "$(realpath "$0")")" +# Various tasks to determine some things like what kind of project is this +# such as wpparent, wp-content rooted...something else? +function build:preflight { + + # load nvm if it exists + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + + PROJECT_TYPE="wpparent" + # Check for a parent layout that has a wordpress directory + if [ -d wordpress ] && [ -d build ]; then # this is probably a wpparent setup + echo "Detected wpparent WordPress repository layout" + + WORDPRESS_BUILD_ROOT="wordpress/wp-content" + return + fi + + # Check for a wp-content rooted style repository + if [ -d plugins ] || [ -d themes ]; then # this is probably a wp-root repo + echo "Detected wp-content rooted WordPress repository layout" + PROJECT_TYPE="wpcontent" + WORDPRESS_BUILD_ROOT="." + return + fi + +} + + +# Routine to determine what version of WordPress to install +function build:version { + + # If the WORDPRESS_VERSION is not set, set to "latest" + if [[ -z ${WORDPRESS_VERSION} ]]; then + WORDPRESS_VERSION="latest" + fi + + if [[ "${WORDPRESS_VERSION}" == "latest" ]]; then + WORDPRESS_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq '.offers[0].current' | tr -d '"') + fi + + echo ${WORDPRESS_VERSION} +} + +function build:install { + build:preflight + + # we use command in case wp-cli is installed as an alias + if [[ -z $(command -v wp) ]]; then + echo "wp-cli is not installed or in your path but it is required" + exit 1 + fi + + local WORDPRESS_VERSION=$(build:version) + echo "Installing WordPress version: ${WORDPRESS_VERSION}" + + if [ ${PROJECT_TYPE} = "wpparent" ]; then + mkdir -p wordpress/wp-content + pushd wordpress + else + mkdir -p payload/wp-content + pushd payload + fi + wp core download --version=${WORDPRESS_VERSION} --skip-content --force + popd + +} + +function build:main { + set -eo pipefail + + build:preflight + + # This is your "main" build file. By default, it builds a 10up/wp-scaffold style project + # but you are free to modify it as required for your project. Remember, you can also + # drop in any number of scripts and they will be run in alphabetical order AFTER main.sh + + # detect if this is a wpparent layout or not + if [[ ${PROJECT_TYPE} == "wpparent" ]]; then + pushd wordpress/wp-content + elif [ -d plugins ]; then + pushd . # go no where, we are already in the right spot + fi + + if [[ ! -z $(command -v nvm) ]]; then + # Ensure we have the correct node version installed + nvm install + nvm use + fi + + if [[ "${CI:-false}" = "true" ]] && [[ -f composer.json ]]; then + if [ ! -f composer.lock ] && [ -f composer.json ]; then + echo "No composer.lock file detected. You should create/commit an up to date composer.lock file!" + exit 1 + else + composer install --no-dev + fi + elif [[ -f composer.json ]]; then + composer install + fi + + + if [[ -f package.json ]]; then + if [[ "${CI:-false}" = "true" ]] && [[ -f package.json ]]; then + if [[ -f package-lock.json ]]; then + npm ci + else + echo "No package-lock.json file detected. You should create/commit an up to date package-lock.json file!" + exit 1 + fi + else + npm install + fi + + npm run build + fi + + if [[ ${PROJECT_TYPE} == "wpparent" ]]; then + popd + fi +} + +function build:local { + set -eo pipefail + # Create additional build scripts in the build directory with a .sh + # extension. They should do their work inside the wordpress directory. + + # We always call main.sh first + build:preflight + build:main + + # Then call any other drop in scripts next + for I in $(ls scripts/*sh) + do + . $I + done +} + +# Perform a CI like build +function build:full { + set -eo pipefail + + build:preflight + build:install + build:local + + # This rsync will typically work but if you have integrated the CI Library + # into a non project template based project you should adjust it + + # First determine if we are using a project rsync-exclude or the included one + if [[ -f scripts/rsync-excludes.txt ]]; then + RSYNC_EXCLUDES="scripts/rsync-excludes.txt" + fi + + if [[ ${PROJECT_TYPE} == "wpparent" ]]; then + rsync -a --exclude-from=${RSYNC_EXCLUDES} wordpress/ payload/ + else + for I in themes mu-plugins plugins + do + if [ -d $I ]; then + rsync -a --exclude-from=${RSYNC_EXCLUDES} $I/ payload/wp-content/$I + fi + done + fi + +} + +function build:update-composer { + + build:preflight + + if [[ ${PROJECT_TYPE} == "wpparent" ]]; then + pushd wordpress/wp-content + else + pushd . + fi + + if [[ ! composer.json ]]; then + echo "No composer.json file found. Run this from the root of a project and try again." + exit 1 + fi + + for I in $(find . -maxdepth 1 -name composer.json) + do + composer update --no-install + done + + pushd themes + for I in $(find . -maxdepth 2 -name composer.json) + do + pushd $(dirname $I) + composer update --no-install + popd + done + + popd + popd +} + +function build:initialize-git { + git init . + echo + echo + echo 'Git has been initialized. Please run "git remote add origin " to set the remote repository location.' +} + +function build:package { + + if [[ -z $(which docker) ]]; then + echo "You don't seem to have Docker installed but it is required for this to work." + exit 1 + fi + + if [[ ! -d payload ]]; then + echo "No payload directory found. Please run 10up-toolkit project build --type=full first." + exit 1 + fi + + # First determine if we are using a project Dockerfile or the included one + if [[ -f Dockerfile ]]; then + DOCKERFILE="Dockerfile" + else + DOCKERFILE="${SHARE_DIR:?}/Dockerfile" + fi + # FIXME: This should be updated to use variables from .tenup-ci.yml + docker buildx build --load -f ${DOCKERFILE} . -t tenup-project:latest +} + + +# Converts a git branch to a gitlab compatible slug +function utilities:create-gitlab-slug { + local VALUE=$(echo $1 | sed 's/[^a-zA-Z0-9]/-/g' | awk '{print tolower($0)}') + + echo ${VALUE} +} + +eval build:$@ diff --git a/packages/toolkit/scripts/project/build.js b/packages/toolkit/scripts/project/build.js index 92e789af..f71d8a41 100644 --- a/packages/toolkit/scripts/project/build.js +++ b/packages/toolkit/scripts/project/build.js @@ -3,10 +3,18 @@ const chalk = require('chalk'); const { log } = console; -const fs = require('fs'); -const { getProjectRoot, getProjectVariables, setEnvVariables } = require('../../utils'); +const { + getProjectRoot, + getProjectVariables, + setEnvVariables, + hasArgInCLI, + getArgFromCLI, +} = require('../../utils'); -const description = '10up-toolkit project build'; +const buildType = hasArgInCLI('--type') ? getArgFromCLI('--type') : 'local'; +const buildEnvironment = hasArgInCLI('--environment') ? getArgFromCLI('--environment') : null; + +const description = '10up-toolkit project build [--type=] [--environment=]'; const run = async () => { const root = getProjectRoot(); @@ -16,7 +24,8 @@ const run = async () => { process.exit(1); } - const variables = getProjectVariables(); + // combine project variables with actual environment variables + const variables = { ...getProjectVariables(buildEnvironment), ...process.env }; if (!variables) { log(chalk.red('No .tenup.yml found.')); @@ -25,14 +34,9 @@ const run = async () => { setEnvVariables(variables); - if (fs.existsSync(variables.build_script_path)) { - execSync(`. ${__dirname}/bash/build-setup.sh; . ${variables.build_script_path}`, { - stdio: 'inherit', - }); - } else { - log(chalk.red('No build script found.')); - process.exit(1); - } + execSync(`${process.env.SHELL} ${__dirname}/bash/scripts.sh ${buildType}`, { + stdio: 'inherit', + }); log(chalk.green('Build complete.')); }; diff --git a/packages/toolkit/scripts/project/create-payload.js b/packages/toolkit/scripts/project/create-payload.js deleted file mode 100644 index 81134707..00000000 --- a/packages/toolkit/scripts/project/create-payload.js +++ /dev/null @@ -1,62 +0,0 @@ -const { execSync } = require('child_process'); -const chalk = require('chalk'); - -const { log } = console; - -const fs = require('fs'); -const { - getProjectRoot, - getProjectVariables, - setEnvVariables, - getEnvironmentFromBranch, -} = require('../../utils'); - -const description = '10up-toolkit project create-payload '; - -const run = async () => { - const branch = process.argv.slice(3)[0]; - - if (!branch || branch.match(/--/)) { - log(description); - log(chalk.red('No branch specified.')); - process.exit(1); - } - - const root = getProjectRoot(); - - if (!root) { - log(chalk.red('This is not a project.')); - process.exit(1); - } - - let variables = getProjectVariables(); - - if (!variables) { - log(chalk.red('No .tenup.yml found.')); - process.exit(1); - } - - const matchedEnvironment = getEnvironmentFromBranch(branch, variables.environments); - - if (!matchedEnvironment) { - log(chalk.red(`No environment found matching branch \`${branch}\`.`)); - process.exit(0); - } - - variables = { ...variables, ...matchedEnvironment }; - - log(`Creating payload for environment ${matchedEnvironment.environment}.`); - - setEnvVariables(variables); - - // First run build - await require('./build').run(); - - if (fs.existsSync(variables.create_payload_script_path)) { - execSync(`bash ${variables.create_payload_script_path}`, { stdio: 'inherit' }); - } - - log(chalk.green('Payload created.')); -}; - -module.exports = { run, description }; diff --git a/packages/toolkit/scripts/project/init.js b/packages/toolkit/scripts/project/init.js old mode 100644 new mode 100755 index d8d815e6..3123ca86 --- a/packages/toolkit/scripts/project/init.js +++ b/packages/toolkit/scripts/project/init.js @@ -14,18 +14,22 @@ const { getArgFromCLI, hasArgInCLI } = require('../../utils'); const cliPath = hasArgInCLI('--path') ? getArgFromCLI('--path') : '.'; +const projectLayout = hasArgInCLI('--layout') ? getArgFromCLI('--layout') : 'wpcontent'; + const name = hasArgInCLI('--name') ? getArgFromCLI('--name') : ''; const confirm = !!hasArgInCLI('--confirm'); const skipComposer = !!hasArgInCLI('--skip-composer'); +const skipCI = !!hasArgInCLI('--skip-ci'); + let template = hasArgInCLI('--template') ? getArgFromCLI('--template') : ''; const variables = require(`../../project/default-variables.json`); const description = - '10up-toolkit project init [--path=] [--name=] [--template=