From 1e1995197db24c7bf83ba839f000cf0c4eb6f299 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Fri, 24 May 2024 10:46:38 -0400 Subject: [PATCH 1/8] Fix init sed --- packages/toolkit/scripts/project/bash/init.sh | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/packages/toolkit/scripts/project/bash/init.sh b/packages/toolkit/scripts/project/bash/init.sh index 5b6b1e70..df76a7ab 100644 --- a/packages/toolkit/scripts/project/bash/init.sh +++ b/packages/toolkit/scripts/project/bash/init.sh @@ -19,17 +19,25 @@ fi # Fixes weird sed error LANG=C +if [ "$(uname)" = "Darwin" ]; then + sediopt=( -i '') +else + sediopt=( -i ) +fi + +set -o xtrace + # Replace TenUpTheme in all files inside init_path with $name_camel_case recursively -find "$init_path" -type f -exec sed -i -e "s/TenUpTheme/${project_name_camel_case}Theme/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/TenupTheme/${project_name_camel_case}Theme/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/TenUpPlugin/${project_name_camel_case}Plugin/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/TenupPlugin/${project_name_camel_case}Plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TenUpTheme/${project_name_camel_case}Theme/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TenupTheme/${project_name_camel_case}Theme/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TenUpPlugin/${project_name_camel_case}Plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TenupPlugin/${project_name_camel_case}Plugin/g" {} \; # Replace TENUP_ -find "$init_path" -type f -exec sed -i -e "s/TENUP_/${project_name_uppercase_underscore}_/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TENUP_/${project_name_uppercase_underscore}_/g" {} \; # Replace tenup_ -find "$init_path" -type f -exec sed -i -e "s/tenup_/${project_name_lowercase_underscore}_/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/tenup_/${project_name_lowercase_underscore}_/g" {} \; theme_path="$init_path/themes/${project_name_lowercase_hypen}-theme" plugin_path="$init_path/plugins/${project_name_lowercase_hypen}-plugin" @@ -59,22 +67,22 @@ if [ -d "$init_path/mu-plugins/10up-plugin" ]; then mv "$init_path/mu-plugins/10up-plugin" "$mu_plugin_path" fi -find "$init_path" -type f -exec sed -i -e "s/tenup-theme/${project_name_lowercase_hypen}-theme/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/tenup-theme/${project_name_lowercase_hypen}-theme/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/tenup-plugin/${project_name_lowercase_hypen}-plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/tenup-plugin/${project_name_lowercase_hypen}-plugin/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/10up-plugin/${project_name_lowercase_hypen}-plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/10up-plugin/${project_name_lowercase_hypen}-plugin/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/tenup-wp-scaffold/${project_name_lowercase_hypen}/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/tenup-wp-scaffold/${project_name_lowercase_hypen}/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/10up\/wp-theme/10up\/${project_name_lowercase_hypen}-theme/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/10up\/wp-theme/10up\/${project_name_lowercase_hypen}-theme/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/10up\/wp-plugin/10up\/${project_name_lowercase_hypen}-plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/10up\/wp-plugin/10up\/${project_name_lowercase_hypen}-plugin/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/10up Plugin/${project_name} Plugin/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/Tenup Plugin/Project Plugin/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/10up Theme/${project_name} Theme/g" {} \; -find "$init_path" -type f -exec sed -i -e "s/Tenup Theme/${project_name} Theme/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/10up Plugin/${project_name} Plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/Tenup Plugin/Project Plugin/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/10up Theme/${project_name} Theme/g" {} \; +find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/Tenup Theme/${project_name} Theme/g" {} \; rsync -rc "$toolkit_path/project/local/" "$init_path" From 2262aea0c5e19f339215d10ef5cc5348ec48e8bb Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Fri, 24 May 2024 10:48:02 -0400 Subject: [PATCH 2/8] Remove trace --- packages/toolkit/scripts/project/bash/init.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/toolkit/scripts/project/bash/init.sh b/packages/toolkit/scripts/project/bash/init.sh index df76a7ab..4a54316d 100644 --- a/packages/toolkit/scripts/project/bash/init.sh +++ b/packages/toolkit/scripts/project/bash/init.sh @@ -25,8 +25,6 @@ else sediopt=( -i ) fi -set -o xtrace - # Replace TenUpTheme in all files inside init_path with $name_camel_case recursively find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TenUpTheme/${project_name_camel_case}Theme/g" {} \; find "$init_path" -type f -exec sed "${sediopt[@]}" -e "s/TenupTheme/${project_name_camel_case}Theme/g" {} \; From 14afadffa64a53a1e44ee1951619739472e5d809 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Tue, 28 May 2024 12:05:16 -0400 Subject: [PATCH 3/8] Add space --- packages/toolkit/scripts/project/bash/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/scripts/project/bash/init.sh b/packages/toolkit/scripts/project/bash/init.sh index 4a54316d..4585c02f 100644 --- a/packages/toolkit/scripts/project/bash/init.sh +++ b/packages/toolkit/scripts/project/bash/init.sh @@ -20,7 +20,7 @@ fi LANG=C if [ "$(uname)" = "Darwin" ]; then - sediopt=( -i '') + sediopt=( -i '' ) else sediopt=( -i ) fi From d07de40411d8a92838ccf40fbfc04e73eb3a5255 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Tue, 28 May 2024 12:15:56 -0400 Subject: [PATCH 4/8] Fix bash script --- packages/toolkit/scripts/project/bash/init.sh | 2 ++ packages/toolkit/scripts/project/init.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/toolkit/scripts/project/bash/init.sh b/packages/toolkit/scripts/project/bash/init.sh index 4585c02f..25014c0f 100644 --- a/packages/toolkit/scripts/project/bash/init.sh +++ b/packages/toolkit/scripts/project/bash/init.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Create dir if it does not exist if [ ! -d "$init_path" ]; then mkdir -p "$init_path" diff --git a/packages/toolkit/scripts/project/init.js b/packages/toolkit/scripts/project/init.js index 054f6504..b5be9b96 100644 --- a/packages/toolkit/scripts/project/init.js +++ b/packages/toolkit/scripts/project/init.js @@ -126,7 +126,7 @@ const run = async () => { const initScript = `${__dirname}/bash/init.sh`; - execSync(`sh ${initScript}`, { stdio: 'inherit' }); + execSync(`bash ${initScript}`, { stdio: 'inherit' }); // Load the contents of the .tenup.yml file into a string let configFile = fs.readFileSync(`${path}/.tenup.yml`, 'utf8'); From d85bc501bcad9a56a64f9dc4ea5ac8a7b331e7fb Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Tue, 28 May 2024 14:34:32 -0400 Subject: [PATCH 5/8] Use bash --- packages/toolkit/scripts/project/bash/build-setup.sh | 2 ++ packages/toolkit/scripts/project/bash/create-payload.sh | 2 ++ packages/toolkit/scripts/project/create-payload.js | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/toolkit/scripts/project/bash/build-setup.sh b/packages/toolkit/scripts/project/bash/build-setup.sh index 642fa0b6..a6c5eb7b 100644 --- a/packages/toolkit/scripts/project/bash/build-setup.sh +++ b/packages/toolkit/scripts/project/bash/build-setup.sh @@ -1,3 +1,5 @@ +#!/bin/bash + maybe_init_nvm() { if [ $(find . -name .nvmrc | wc -l) -gt 0 ] && [ ! -f $NVM_DIR/nvm.sh ]; then diff --git a/packages/toolkit/scripts/project/bash/create-payload.sh b/packages/toolkit/scripts/project/bash/create-payload.sh index bab0e5bb..3288ca79 100644 --- a/packages/toolkit/scripts/project/bash/create-payload.sh +++ b/packages/toolkit/scripts/project/bash/create-payload.sh @@ -1,3 +1,5 @@ +#!/bin/bash + download() { if [ `which curl` ]; then curl -s "$1" > "$2"; diff --git a/packages/toolkit/scripts/project/create-payload.js b/packages/toolkit/scripts/project/create-payload.js index ddd840fd..81134707 100644 --- a/packages/toolkit/scripts/project/create-payload.js +++ b/packages/toolkit/scripts/project/create-payload.js @@ -53,7 +53,7 @@ const run = async () => { await require('./build').run(); if (fs.existsSync(variables.create_payload_script_path)) { - execSync(`sh ${variables.create_payload_script_path}`, { stdio: 'inherit' }); + execSync(`bash ${variables.create_payload_script_path}`, { stdio: 'inherit' }); } log(chalk.green('Payload created.')); From 4193d9da7119f48a4ea407f9fb4169f038fe00d1 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Wed, 29 May 2024 10:08:35 -0400 Subject: [PATCH 6/8] Fix deploy excludes; install toolkit in ci --- .../toolkit/project/gitlab/.gitlab-ci.tmpl | 18 ++---------------- .../scripts/deploy-excludes.txt} | 0 packages/toolkit/utils/project.js | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) rename packages/toolkit/project/{deploy-file-excludes.txt => local/scripts/deploy-excludes.txt} (100%) diff --git a/packages/toolkit/project/gitlab/.gitlab-ci.tmpl b/packages/toolkit/project/gitlab/.gitlab-ci.tmpl index 235d7e86..18f6ff5d 100644 --- a/packages/toolkit/project/gitlab/.gitlab-ci.tmpl +++ b/packages/toolkit/project/gitlab/.gitlab-ci.tmpl @@ -7,21 +7,6 @@ include: ref: trunk file: /main.yml -setup_10up_toolkit: - stage: .pre - script: | - if [ ! -d "toolkit" ] ; then - git clone --verbose -b project-command https://github.com/10up/10up-toolkit.git toolkit - fi - rm -rf 10up-toolkit - ln -s toolkit/packages/toolkit/bin/10up-toolkit.js 10up-toolkit - cd toolkit - npm install - artifacts: - paths: - - toolkit - - 10up-toolkit - test_syntax: stage: test script: @@ -39,7 +24,8 @@ test_virusscan: build_plugins_and_themes: stage: build script: - - ./10up-toolkit project create-payload $CI_COMMIT_REF_NAME + - nvm install 18 + - npx 10up-toolkit@next project create-payload $CI_COMMIT_REF_NAME artifacts: paths: - payload diff --git a/packages/toolkit/project/deploy-file-excludes.txt b/packages/toolkit/project/local/scripts/deploy-excludes.txt similarity index 100% rename from packages/toolkit/project/deploy-file-excludes.txt rename to packages/toolkit/project/local/scripts/deploy-excludes.txt diff --git a/packages/toolkit/utils/project.js b/packages/toolkit/utils/project.js index 4bbf5603..e1dced92 100644 --- a/packages/toolkit/utils/project.js +++ b/packages/toolkit/utils/project.js @@ -137,7 +137,7 @@ const getProjectVariables = (path = '.') => { } if (!data.deploy_file_excludes) { - data.deploy_file_excludes = `./toolkit/packages/toolkit/project/deploy-file-excludes.txt`; + data.deploy_file_excludes = `./scripts/deploy-excludes.txt`; } data.toolkit_path = resolve(`${__dirname}/../`); From 959f9cc44c071b618b564dad5c45e69a9afdb0da Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Wed, 29 May 2024 10:20:34 -0400 Subject: [PATCH 7/8] Hardcode file excludes path --- packages/toolkit/PROJECTS.md | 1 - packages/toolkit/project/default-variables.json | 1 - packages/toolkit/scripts/project/bash/create-payload.sh | 4 +--- packages/toolkit/utils/project.js | 5 ++--- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/toolkit/PROJECTS.md b/packages/toolkit/PROJECTS.md index a14d71c7..6b1f8ca2 100644 --- a/packages/toolkit/PROJECTS.md +++ b/packages/toolkit/PROJECTS.md @@ -64,7 +64,6 @@ The following are additional optional variables that allow you to use custom scr 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 -deploy_file_excludes: "" # Custom deploy file exclusions ``` ## Commands diff --git a/packages/toolkit/project/default-variables.json b/packages/toolkit/project/default-variables.json index 7c0c1351..b1b1a4a7 100644 --- a/packages/toolkit/project/default-variables.json +++ b/packages/toolkit/project/default-variables.json @@ -4,7 +4,6 @@ "build_script_path": "", "wordpress_version": "", "deploy_script_path": "", - "deploy_file_excludes": "", "create_payload_script_path": "", "environments": [] } diff --git a/packages/toolkit/scripts/project/bash/create-payload.sh b/packages/toolkit/scripts/project/bash/create-payload.sh index 3288ca79..91309781 100644 --- a/packages/toolkit/scripts/project/bash/create-payload.sh +++ b/packages/toolkit/scripts/project/bash/create-payload.sh @@ -17,6 +17,4 @@ download https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz wordpress.t tar --strip-components=1 -zxmf wordpress.tar.gz -C . rm wordpress.tar.gz -echo "rsync -avz --exclude-from=$deploy_file_excludes $project_root/$deploy_from $deploy_to_subdir" - -rsync -avz --exclude-from=$deploy_file_excludes $project_root/$deploy_from $deploy_to_subdir +rsync -avz --exclude-from=$deploy_file_excludes_absolute $project_root/$deploy_from $deploy_to_subdir diff --git a/packages/toolkit/utils/project.js b/packages/toolkit/utils/project.js index e1dced92..762eb5a1 100644 --- a/packages/toolkit/utils/project.js +++ b/packages/toolkit/utils/project.js @@ -136,9 +136,8 @@ const getProjectVariables = (path = '.') => { data.build_script_path = `${projectRoot}/scripts/build.sh`; } - if (!data.deploy_file_excludes) { - data.deploy_file_excludes = `./scripts/deploy-excludes.txt`; - } + data.deploy_file_excludes = `./scripts/deploy-excludes.txt`; + data.deploy_file_excludes_absolute = `${projectRoot}/scripts/deploy-excludes.txt`; data.toolkit_path = resolve(`${__dirname}/../`); From 245a387b1587da56934f9d312c4a230dce8fdd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Wed, 29 May 2024 11:22:06 -0300 Subject: [PATCH 8/8] changeset --- .changeset/poor-birds-rhyme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/poor-birds-rhyme.md diff --git a/.changeset/poor-birds-rhyme.md b/.changeset/poor-birds-rhyme.md new file mode 100644 index 00000000..1161255d --- /dev/null +++ b/.changeset/poor-birds-rhyme.md @@ -0,0 +1,5 @@ +--- +"10up-toolkit": patch +--- + +Fix init command