Skip to content

Commit

Permalink
Fix init replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed May 21, 2024
1 parent 8288ab5 commit 542ede2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
39 changes: 33 additions & 6 deletions packages/toolkit/scripts/project/bash/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
19 changes: 14 additions & 5 deletions packages/toolkit/scripts/project/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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):',
});
}

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 542ede2

Please sign in to comment.