Skip to content

Commit 12eea31

Browse files
Merge pull request #184 from laravel/configure-basepath
Allow configuration of project base path
2 parents 2243926 + e3a1f6a commit 12eea31

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
"type": "string",
101101
"description": "Template for running PHP code. Use {code} as a placeholder for the php file to run. e.g. `php \"{code}\"`"
102102
},
103+
"Laravel.basePath": {
104+
"type": "string",
105+
"default": "",
106+
"markdownDescription": "_Relative_ base path for the Laravel project. This is used to resolve paths in the project. e.g. src, code/backend\n\n_Requires extension reload after changing._"
107+
},
103108
"Laravel.showErrorPopups": {
104109
"type": "boolean",
105110
"default": true,

src/support/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GeneratedConfigKey } from "./generated-config";
33

44
type ConfigKey =
55
| GeneratedConfigKey
6+
| "basePath"
67
| "phpEnvironment"
78
| "phpCommand"
89
| "tests.docker.enabled"

src/support/php.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ export const runInLaravel = <T>(
211211

212212
const command = template("bootstrapLaravel", {
213213
output: code,
214-
vendor_autoload_path: projectPath("vendor/autoload.php", true),
215-
bootstrap_path: projectPath("bootstrap/app.php", true),
216214
});
217215

218216
return runPhp(command, description)

src/support/project.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from "fs";
22
import * as path from "path";
33
import * as vscode from "vscode";
4+
import { config } from "./config";
45

56
let internalVendorExists: boolean | null = null;
67

@@ -28,26 +29,19 @@ const trimFirstSlash = (srcPath: string): string => {
2829
return srcPath[0] === path.sep ? srcPath.substring(1) : srcPath;
2930
};
3031

31-
export const projectPath = (srcPath = "", forCode = false): string => {
32-
srcPath = srcPath.replace(/\//g, path.sep);
33-
srcPath = trimFirstSlash(srcPath);
34-
35-
let basePath = "";
36-
// let basePath = config<string>("basePath", "");
37-
38-
if (forCode === false && basePath.length > 0) {
39-
return resolvePath(basePath, srcPath);
40-
}
41-
42-
let basePathForCode = "";
43-
// let basePathForCode = config<string>("basePathForCode", "");
32+
export const basePath = (srcPath = ""): string => {
33+
return path.join(config<string>("basePath", ""), srcPath);
34+
};
4435

45-
if (forCode && basePathForCode.length > 0) {
46-
return resolvePath(basePathForCode, srcPath);
47-
}
36+
export const projectPath = (srcPath = ""): string => {
37+
srcPath = basePath(srcPath);
4838

4939
for (let workspaceFolder of getWorkspaceFolders()) {
50-
if (fs.existsSync(path.join(workspaceFolder.uri.fsPath, "artisan"))) {
40+
if (
41+
fs.existsSync(
42+
path.join(workspaceFolder.uri.fsPath, basePath("artisan")),
43+
)
44+
) {
5145
return path.join(workspaceFolder.uri.fsPath, srcPath);
5246
}
5347
}
@@ -59,7 +53,10 @@ export const relativePath = (srcPath: string): string => {
5953
for (let workspaceFolder of getWorkspaceFolders()) {
6054
if (srcPath.startsWith(workspaceFolder.uri.fsPath)) {
6155
return trimFirstSlash(
62-
srcPath.replace(workspaceFolder.uri.fsPath, ""),
56+
srcPath.replace(
57+
path.join(workspaceFolder.uri.fsPath, basePath()),
58+
"",
59+
),
6360
);
6461
}
6562
}

0 commit comments

Comments
 (0)