From 1e1995197db24c7bf83ba839f000cf0c4eb6f299 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Fri, 24 May 2024 10:46:38 -0400 Subject: [PATCH 01/11] 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 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 90abbd9773a0175869f326be63ddcb8fd397e856 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Thu, 30 May 2024 09:03:59 -0400 Subject: [PATCH 08/11] Move init command to node --- package-lock.json | 249 +++++++++++++++++- packages/toolkit/package.json | 1 + packages/toolkit/scripts/project/bash/init.sh | 101 ------- packages/toolkit/scripts/project/init.js | 135 +++++++--- 4 files changed, 344 insertions(+), 142 deletions(-) delete mode 100644 packages/toolkit/scripts/project/bash/init.sh diff --git a/package-lock.json b/package-lock.json index c76e482f..71dc22d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20827,6 +20827,116 @@ "node": ">=0.10" } }, + "node_modules/replace-in-file": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/replace-in-file/-/replace-in-file-7.2.0.tgz", + "integrity": "sha512-CiLXVop3o8/h2Kd1PwKPPimmS9wUV0Ki6Fl8+1ITD35nB3Gl/PrW5IONpTE0AXk0z4v8WYcpEpdeZqMXvSnWpg==", + "dependencies": { + "chalk": "^4.1.2", + "glob": "^8.1.0", + "yargs": "^17.7.2" + }, + "bin": { + "replace-in-file": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/replace-in-file/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/replace-in-file/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/replace-in-file/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/replace-in-file/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/replace-in-file/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/replace-in-file/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/replace-in-file/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/replace-in-file/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/require-directory": { "version": "2.1.1", "license": "MIT", @@ -25479,7 +25589,7 @@ "core-js": "^3.35.0" }, "devDependencies": { - "@10up/eslint-config": "^4.0.0", + "@10up/eslint-config": "^4.1.0-next.0", "@wordpress/element": "^4.20.0", "babel-jest": "^27.5.1", "eslint": "^8.40.0", @@ -25488,7 +25598,7 @@ }, "packages/eslint-config": { "name": "@10up/eslint-config", - "version": "4.0.0", + "version": "4.1.0-next.0", "license": "GPL-2.0-or-later", "dependencies": { "@10up/babel-preset-default": "^2.1.1" @@ -25535,7 +25645,7 @@ "stylelint-stylistic": "^0.4.3" }, "devDependencies": { - "@10up/eslint-config": "^4.0.0", + "@10up/eslint-config": "^4.1.0-next.0", "jest": "^29.7.0" }, "engines": { @@ -26683,7 +26793,7 @@ }, "packages/toolkit": { "name": "10up-toolkit", - "version": "6.1.0", + "version": "6.2.0-next.0", "license": "GPL-2.0-or-later", "dependencies": { "@babel/eslint-parser": "^7.23.3", @@ -26725,6 +26835,7 @@ "react-refresh": "^0.14.0", "read-pkg": "^5.2.0", "read-pkg-up": "^7.0.1", + "replace-in-file": "^7.2.0", "resolve-bin": "^1.0.1", "sass": "^1.69.7", "sass-loader": "^13.3.3", @@ -26745,7 +26856,7 @@ }, "devDependencies": { "@10up/babel-preset-default": ">=2.1.1", - "@10up/eslint-config": ">=4.0.0", + "@10up/eslint-config": ">=4.1.0-next.0", "@10up/stylelint-config": ">=3.0.0" }, "engines": { @@ -26754,7 +26865,7 @@ }, "peerDependencies": { "@10up/babel-preset-default": ">=2.1.1", - "@10up/eslint-config": ">=4.0.0", + "@10up/eslint-config": ">=4.1.0-next.0", "@10up/stylelint-config": ">=3.0.0", "@linaria/babel-preset": ">=4.3.3", "@linaria/webpack-loader": ">=4.1.11", @@ -26911,6 +27022,46 @@ } } }, + "packages/toolkit/node_modules/@jest/reporters/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "packages/toolkit/node_modules/@jest/reporters/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "packages/toolkit/node_modules/@jest/reporters/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "packages/toolkit/node_modules/@jest/source-map": { "version": "29.6.3", "license": "MIT", @@ -27679,6 +27830,46 @@ } } }, + "packages/toolkit/node_modules/jest-config/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "packages/toolkit/node_modules/jest-config/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "packages/toolkit/node_modules/jest-config/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "packages/toolkit/node_modules/jest-diff": { "version": "29.7.0", "license": "MIT", @@ -27912,6 +28103,46 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "packages/toolkit/node_modules/jest-runtime/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "packages/toolkit/node_modules/jest-runtime/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "packages/toolkit/node_modules/jest-runtime/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "packages/toolkit/node_modules/jest-snapshot": { "version": "29.7.0", "license": "MIT", @@ -28300,7 +28531,7 @@ "@linaria/babel-preset": "^5.0.3", "@linaria/webpack-loader": "^5.0.3", "@wordpress/env": "^5.0.0", - "10up-toolkit": "^6.1.0" + "10up-toolkit": "^6.2.0-next.0" }, "engines": { "node": ">=12.0.0" @@ -28317,7 +28548,7 @@ "@testing-library/dom": "9.3.3", "@testing-library/jest-dom": "^6.2.0", "@testing-library/user-event": "^14.5.2", - "10up-toolkit": "^6.1.0", + "10up-toolkit": "^6.2.0-next.0", "jest-axe": "^8.0.0", "jest-environment-jsdom": "~29.7.0" } @@ -28330,7 +28561,7 @@ "xss": "^1.0.11" }, "devDependencies": { - "10up-toolkit": "^6.1.0" + "10up-toolkit": "^6.2.0-next.0" } }, "projects/library/node_modules/@jest/console": { diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index d9edec5f..517d5a25 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -57,6 +57,7 @@ "react-refresh": "^0.14.0", "read-pkg": "^5.2.0", "read-pkg-up": "^7.0.1", + "replace-in-file": "^7.2.0", "resolve-bin": "^1.0.1", "sass": "^1.69.7", "sass-loader": "^13.3.3", diff --git a/packages/toolkit/scripts/project/bash/init.sh b/packages/toolkit/scripts/project/bash/init.sh deleted file mode 100644 index 25014c0f..00000000 --- a/packages/toolkit/scripts/project/bash/init.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash - -# Create dir if it does not exist -if [ ! -d "$init_path" ]; then - mkdir -p "$init_path" -fi - -# Check if init_path direcfory is not empty -if [ $(ls -A "$init_path" | wc -l) -gt 0 ]; then - echo "Directory $init_path is not empty. Please provide an empty directory to initialize the project." - exit 1 -fi - - -# If template is not empty, git clone template to init_path -if [ ! -z "$template" ]; then - git clone "$template" "$init_path" - rm -rf "$init_path/.git" -fi - -# Fixes weird sed error -LANG=C - -if [ "$(uname)" = "Darwin" ]; then - sediopt=( -i '' ) -else - sediopt=( -i ) -fi - -# 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" {} \; -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 "${sediopt[@]}" -e "s/TENUP_/${project_name_uppercase_underscore}_/g" {} \; - -# Replace tenup_ -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" -mu_plugin_path="$init_path/mu-plugins/${project_name_lowercase_hypen}-plugin" - -# Rename directory themes/tenup-theme to themes/$project_name_lowercase_hypen-theme -if [ -d "$init_path/themes/tenup-theme" ]; then - mv "$init_path/themes/tenup-theme" "$theme_path" -fi - -# Rename directory plugins/tenup-plugin to plugins/$project_name_lowercase_hypen-plugin -if [ -d "$init_path/plugins/tenup-plugin" ]; then - mv "$init_path/plugins/tenup-plugin" "$plugin_path" -fi - -# Rename directory themes/tenup-theme to themes/$project_name_lowercase_hypen-theme -if [ -d "$init_path/themes/10up-theme" ]; then - mv "$init_path/themes/10up-theme" "$theme_path" -fi - -# Rename directory plugins/tenup-plugin to plugins/$project_name_lowercase_hypen-plugin -if [ -d "$init_path/plugins/10up-plugin" ]; then - mv "$init_path/plugins/10up-plugin" "$plugin_path" -fi - -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 "${sediopt[@]}" -e "s/tenup-theme/${project_name_lowercase_hypen}-theme/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 "${sediopt[@]}" -e "s/10up-plugin/${project_name_lowercase_hypen}-plugin/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 "${sediopt[@]}" -e "s/10up\/wp-theme/10up\/${project_name_lowercase_hypen}-theme/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 "${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" - -composer update --no-interaction --working-dir="$init_path" - -if [ -d "$theme_path" ]; then - composer update --no-interaction --working-dir="$theme_path" -fi - -if [ -d "$plugin_path" ]; then - composer update --no-interaction --working-dir="$plugin_path" -fi - -if [ -d "$mu_plugin_path" ]; then - composer update --no-interaction --working-dir="$mu_plugin_path" -fi diff --git a/packages/toolkit/scripts/project/init.js b/packages/toolkit/scripts/project/init.js index b5be9b96..ac487eda 100644 --- a/packages/toolkit/scripts/project/init.js +++ b/packages/toolkit/scripts/project/init.js @@ -4,35 +4,35 @@ const chalk = require('chalk'); const { log } = console; const fs = require('fs'); - +const path = require('path'); const { execSync } = require('child_process'); +const replace = require('replace-in-file'); +const fg = require('fast-glob'); -const { - getWordPressLatestVersion, - replaceVariables, - setEnvVariables, -} = require('../../utils/project'); +const { getWordPressLatestVersion, replaceVariables } = require('../../utils/project'); const { getArgFromCLI, hasArgInCLI } = require('../../utils'); -const path = hasArgInCLI('--path') ? getArgFromCLI('--path') : '.'; +const cliPath = hasArgInCLI('--path') ? getArgFromCLI('--path') : '.'; const name = hasArgInCLI('--name') ? getArgFromCLI('--name') : ''; const confirm = !!hasArgInCLI('--confirm'); -const template = hasArgInCLI('--template') ? getArgFromCLI('--template') : ''; +const skipComposer = !!hasArgInCLI('--skip-composer'); + +let template = hasArgInCLI('--template') ? getArgFromCLI('--template') : ''; const variables = require(`../../project/default-variables.json`); const description = - '10up-toolkit project init [--path=] [--name=] [--template=