diff --git a/packages/toolkit/scripts/project/bash/init.sh b/packages/toolkit/scripts/project/bash/init.sh index 21271073..2cb05688 100644 --- a/packages/toolkit/scripts/project/bash/init.sh +++ b/packages/toolkit/scripts/project/bash/init.sh @@ -4,7 +4,7 @@ if [ ! -d "$init_path" ]; then fi # Check if init_path direcfory is not empty -if [ "$(ls -A $init_path)" ]; then +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 @@ -20,13 +20,40 @@ fi LANG=C # Replace TenUpTheme in all files inside init_path with $name_camel_case recursively -find "$init_path" -type f -exec sed -i '' -e "s/TenUpTheme/${name_camel_case}Theme/g" {} \; -find "$init_path" -type f -exec sed -i '' -e "s/TenUpPlugin/${name_camel_case}Plugin/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/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" {} \; # Replace TENUP_ -find "$init_path" -type f -exec sed -i '' -e "s/TENUP_/${name_uppercase_underscore}_/g" {} \; +find "$init_path" -type f -exec sed -i '' -e "s/TENUP_/${project_name_uppercase_underscore}_/g" {} \; # Replace tenup_ -find "$init_path" -type f -exec sed -i '' -e "s/tenup_/${name_lowercase_underscore}_/g" {} \; +find "$init_path" -type f -exec sed -i '' -e "s/tenup_/${project_name_lowercase_underscore}_/g" {} \; -rsync -rc $toolkit_path/project/local/ $init_path +# 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" "$init_path/themes/${project_name_lowercase_hypen}-theme" +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" "$init_path/plugins/${project_name_lowercase_hypen}-plugin" +fi + +# Replace tenup-theme +find "$init_path" -type f -exec sed -i '' -e "s/tenup-theme/${project_name_lowercase_hypen}-theme/g" {} \; + +# Replace tenup-plugin +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 -i '' -e "s/10up Plugin/${project_name} Plugin/g" {} \; +find "$init_path" -type f -exec sed -i '' -e "s/Tenup Plugin/${project_name} 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" {} \; + +rsync -rc "$toolkit_path/project/local/" "$init_path" + +composer update --no-interaction --working-dir="$init_path" +composer update --no-interaction --working-dir="$init_path/themes/${project_name_lowercase_hypen}-theme" +composer update --no-interaction --working-dir="$init_path/plugins/${project_name_lowercase_hypen}-plugin" diff --git a/packages/toolkit/scripts/project/init.js b/packages/toolkit/scripts/project/init.js index 14823481..f2e79cfe 100644 --- a/packages/toolkit/scripts/project/init.js +++ b/packages/toolkit/scripts/project/init.js @@ -61,7 +61,8 @@ const run = async () => { return true; }, - message: 'Project name (Letters, numbers, and spaces only. Must start with a letter.):', + message: + 'Project name (Letters, numbers, and spaces only. Must start with a letter. Minimum 4 characters):', }); } @@ -99,18 +100,26 @@ const run = async () => { variables.init_path = resolve(path); variables.template = results.template || template; - variables.name = results.name || name; + variables.project_name = results.name || name; // Make name camel case - variables.name_camel_case = variables.name + variables.project_name_camel_case = variables.project_name .replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }) .replace(/ /g, ''); - variables.name_lowercase_underscore = variables.name.replace(/ /g, '_').toLowerCase(); + variables.project_name_lowercase_underscore = variables.project_name + .replace(/ /g, '_') + .toLowerCase(); - variables.name_uppercase_underscore = variables.name.replace(/ /g, '_').toUpperCase(); + variables.project_name_lowercase_hypen = variables.project_name + .replace(/ /g, '-') + .toLowerCase(); + + variables.project_name_uppercase_underscore = variables.project_name + .replace(/ /g, '_') + .toUpperCase(); Object.keys(variables).forEach((key) => { process.env[key] = variables[key];