Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add more flexibility tl #421

Merged
merged 17 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions packages/toolkit/PROJECTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,23 @@ 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.

List of commands:

```bash
10up-toolkit project init [--path=<path>] [--template=<Git repository>] [--name=<Project Name>] [--confirm] [--skip-composer]
```

`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.

```bash
10up-toolkit project build
10up-toolkit project init [--path=<path>] [--layout=<layout>] [--template=<Git repository>] [--name=<Project Name>] [--confirm] [--skip-composer] [--skip-ci]
```

`build` simply executes your `scripts/build.sh` file (or other path you specify). `build` will be executed before deploying files.
`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 create-payload
10up-toolkit project build [--type=<type>]
```

This command performs a simulated CI/CD build and creates a payload directory of the built project (including WordPress core). Useful for validating how a build will behave in CI/CD for deployment. Engineers likely won't need to run this command themselves as CI/CD does it automatically.
`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 generate-ci [--confirm] [--path=<path>]
Expand Down
3 changes: 0 additions & 3 deletions packages/toolkit/project/default-variables.json
Original file line number Diff line number Diff line change
@@ -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": []
}
2 changes: 1 addition & 1 deletion packages/toolkit/project/gitlab/.gitlab-ci.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build_plugins_and_themes:
stage: build
script:
- nvm install 18
- npx 10up-toolkit project create-payload
- npx 10up-toolkit project build --type=full
artifacts:
paths:
- payload
Expand Down
20 changes: 0 additions & 20 deletions packages/toolkit/scripts/project/bash/create-payload.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

SHARE_DIR="$(dirname "$(realpath "$0")")"
# Various tasks to determine some things like what kind of project is this
# such as standard, wp-content rooted...something else?
# such as wpparent, wp-content rooted...something else?
function build:preflight {
PROJECT_TYPE="standard"
# Check for a default, standard layout that has a wordpress directory
if [ -d wordpress ] && [ -d build ]; then # this is probably a standard setup
echo "Detected standard WordPress repository layout"
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
Expand All @@ -27,20 +27,10 @@ function build:preflight {
# Routine to determine what version of WordPress to install
function build:version {

WORDPRESS_VERSION="latest"
if [ ${CI:-false} = "true" ]; then
if [ -z ${WORDPRESS_VERSION} ]; then
WORDPRESS_VERSION="latest"
fi
else
GIT_BRANCH=$(git branch --format='%(refname:short)' --show-current)
GIT_BRANCH_SLUG=$(utilities:create-gitlab-slug ${GIT_BRANCH})
ENVIRONMENT=$(yq eval '.environments | to_entries[] | select(.value.branch == "'${GIT_BRANCH_SLUG}'") | .key' ${TENUP_CI_FILE})

if [ ${ENVIRONMENT:-null} != "null" ]; then
WORDPRESS_VERSION=$(yq '.environments.'${ENVIRONMENT}'.wordpress_version' ${TENUP_CI_FILE})
fi
fi
# 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 '"')
Expand All @@ -61,7 +51,7 @@ function build:install {
local WORDPRESS_VERSION=$(build:version)
echo "Installing WordPress version: ${WORDPRESS_VERSION}"

if [ ${PROJECT_TYPE} = "standard" ]; then
if [ ${PROJECT_TYPE} = "wpparent" ]; then
mkdir -p wordpress/wp-content
pushd wordpress
else
Expand All @@ -80,17 +70,17 @@ function build:main {

# don't call this script directly
if [ $(shopt -q login_shell) ]; then
echo "Please call this using build/local.sh rather than directly"
echo "Do not call this script directly."
exit 1
fi

# 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 standard layout or not
# detect if this is a wpparent layout or not

if [ -d wordpress/wp-content ]; then
if [ ${PROJECT_TYPE} == "wpparent" ]; then
pushd wordpress/wp-content
elif [ -d plugins ]; then
pushd . # go no where, we are already in the right spot
Expand Down Expand Up @@ -125,7 +115,10 @@ function build:main {

npm run build
fi
popd

if [ ${PROJECT_TYPE} == "wpparent" ]; then
popd
fi
}

function build:local {
Expand Down Expand Up @@ -160,7 +153,7 @@ function build:full {
RSYNC_EXCLUDES="scripts/rsync-excludes.txt"
fi

if [ ${PROJECT_TYPE} == "standard" ]; then
if [ ${PROJECT_TYPE} == "wpparent" ]; then
rsync -a --exclude-from=${RSYNC_EXCLUDES} wordpress/ payload/
else
for I in themes mu-plugins plugins
Expand All @@ -177,7 +170,7 @@ function build:update-composer {

build:preflight

if [ ${PROJECT_TYPE} == "standard" ]; then
if [ ${PROJECT_TYPE} == "wpparent" ]; then
pushd wordpress/wp-content
else
pushd .
Expand Down Expand Up @@ -220,7 +213,7 @@ function build:package {
fi

if [ ! -d payload ]; then
echo "No payload directory found. Please run 10up-toolkit project create-payload first."
echo "No payload directory found. Please run 10up-toolkit project build --type=full first."
exit 1
fi

Expand Down
27 changes: 15 additions & 12 deletions packages/toolkit/scripts/project/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=<type>] [--environment=<environment>]';

const run = async () => {
const root = getProjectRoot();
Expand All @@ -17,7 +25,7 @@ const run = async () => {
}

// combine project variables with actual environment variables
const variables = { ...getProjectVariables(), ...process.env };
const variables = { ...getProjectVariables(buildEnvironment), ...process.env };

if (!variables) {
log(chalk.red('No .tenup.yml found.'));
Expand All @@ -26,14 +34,9 @@ const run = async () => {

setEnvVariables(variables);

if (fs.existsSync(variables.build_script_path)) {
execSync(`bash -l ${__dirname}/bash/build-setup.sh local`, {
stdio: 'inherit',
});
} else {
log(chalk.red('No build script found.'));
process.exit(1);
}
execSync(`bash -l ${__dirname}/bash/scripts.sh ${buildType}`, {
stdio: 'inherit',
});

log(chalk.green('Build complete.'));
};
Expand Down
44 changes: 0 additions & 44 deletions packages/toolkit/scripts/project/create-payload.js

This file was deleted.

Loading
Loading