Skip to content

Commit 8e1bd3b

Browse files
Merge pull request #56 from dreamsicle-io/release/3.3.2
Release/3.3.2
2 parents bbdcbe7 + f6013f3 commit 8e1bd3b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,7 @@ function putPackage() {
904904
}
905905

906906
function initGitRepo() {
907-
// Cache the current working directory and change
908-
// working directory to the theme path.
909-
const cwd = process.cwd();
910-
process.chdir(themePath);
911-
// Initialize repository.
907+
// Initialize git repository.
912908
const stdoutInit = execSync(`git init -b main`, { stdio: 'pipe' });
913909
logInfo({
914910
title: 'Repo initialized',
@@ -939,13 +935,20 @@ function initGitRepo() {
939935
dataLabel: 'Commit response',
940936
data: stdoutCommit.toString().trim(),
941937
});
942-
// Return the process back to the original working directory.
943-
process.chdir(cwd);
944938
}
945939

946940
function initRepo() {
941+
// Cache the current working directory and change
942+
// working directory to the theme path. At the end of repo
943+
// initialization, or on error, the process will be moved
944+
// back to the cached current working directory (cwd).
945+
const cwd = process.cwd();
946+
process.chdir(themePath);
947947
try {
948948
// Switch on the repo type and initialize a repo with remote origin.
949+
// Note that by this time, we have moved the process from the current
950+
// working directory into the theme, and the theme has already been
951+
// moved to its final location.
949952
switch (options.themeRepoType) {
950953
case 'git': {
951954
initGitRepo();
@@ -960,7 +963,12 @@ function initRepo() {
960963
break;
961964
}
962965
}
966+
// Return the process back to the cached working directory.
967+
process.chdir(cwd);
963968
} catch (error) {
969+
// Return the process back to the cached working directory. Make sure
970+
// this happens before the error is thrown to ensure it returns no matter what.
971+
process.chdir(cwd);
964972
// If `failExternals` option is true, throw an error. If it's false, we don't
965973
// want repo init errors to exit the process, so don't throw. Instead, catch them
966974
// and log them so the user is aware, while allowing the process to continue.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dreamsicle.io/create-wp-theme",
3-
"version": "3.3.1",
3+
"version": "3.3.2",
44
"type": "module",
55
"description": "A command line tool for creating modern, optimized WordPress themes.",
66
"main": "index.js",

0 commit comments

Comments
 (0)