-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(repo): add VS Code workspace file (#3929)
Make it easier to navigate around the various sub projects in the mono repo by using a workspace configuration file https://code.visualstudio.com/docs/editor/multi-root-workspaces Not exactly sure if that structure makes sense, but it's a starting point. ![Screenshot 2023-08-23 at 13 51 04](https://github.com/winglang/wing/assets/136789/defbf0cd-f98e-489a-a363-f507d5fa9bce) Thoughts? ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
11 changed files
with
307 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "docs", | ||
"private": true, | ||
"volta": { | ||
"extends": "../../../package.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generate-Workspace CLI | ||
|
||
The `generate-workspace` CLI is a tool that generates a Visual Studio Code [multi-root](https://code.visualstudio.com/docs/editor/multi-root-workspaces) workspace file based on the configuration of a pnpm [workspace](https://pnpm.io/workspaces). | ||
|
||
![screenshot](./screenshot.png) | ||
|
||
## How it works | ||
|
||
The CLI scans the pnpm workspace configuration and creates a `wing.code-workspace` file that Visual Studio Code can use to open multiple projects in the same window. This is particularly useful in a monorepo setup where you might have multiple packages that you want to work with at the same time. | ||
|
||
The generated workspace file includes all the packages in the pnpm workspace, except for those specified in the `ignoreList` in `cli.ts`. The names of the packages in the workspace file are either their actual package names or the names specified in the `nameMapping` in `cli.ts`, if present. | ||
|
||
## Usage | ||
|
||
To use the `generate-workspace` CLI, run the following command in your terminal in the this directory: `npx generate-workspace` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env -S node | ||
const { execSync } = require("node:child_process"); | ||
const { resolve, relative } = require("node:path"); | ||
|
||
const which = require("npm-which")(__dirname); | ||
const tsx = relative(process.cwd(), which.sync("tsx")); | ||
const cliSource = relative(process.cwd(), resolve(__dirname, "../src/cli.ts")); | ||
execSync(`${tsx} ${cliSource} ${process.argv.slice(2).join(" ")}`, { | ||
stdio: "inherit", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "generate-workspace", | ||
"version": "0.0.0", | ||
"private": true, | ||
"bin": { | ||
"generate-workspace": "./bin/generate-workspace.cjs" | ||
}, | ||
"exports": null, | ||
"sideEffects": false, | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
"scripts": {}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^11", | ||
"@types/node": "^18.16.18", | ||
"@types/semver": "^7.5.0", | ||
"typescript": "^5.1.3" | ||
}, | ||
"dependencies": { | ||
"@pnpm/find-workspace-dir": "^6.0.2", | ||
"@pnpm/workspace.find-packages": "^1.0.1", | ||
"tsx": "^3.12.7", | ||
"npm-which": "^3.0.1" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { findWorkspacePackages } from "@pnpm/workspace.find-packages"; | ||
import { findWorkspaceDir } from "@pnpm/find-workspace-dir"; | ||
import { writeFileSync } from "fs"; | ||
import { join } from "path"; | ||
|
||
// Define ignore list and name mapping | ||
const ignoreList = [ | ||
"construct-library", | ||
"@wingconsole/eslint-plugin", | ||
"generate-workspace", | ||
"bump-pack", | ||
"@winglang/wingii", | ||
"@winglang/wingc", | ||
"@winglang/tree-sitter-wing", | ||
"@wingconsole/error-message", | ||
"@wingconsole/use-loading", | ||
"@wingconsole/tsconfig", | ||
"hangar", | ||
"@wingconsole/design-system", | ||
]; | ||
|
||
const nameMapping: Record<string, string> = { | ||
"@winglang/monorepo": "ROOT", | ||
"winglang": "CLI", | ||
"@winglang/compiler": "Compiler", | ||
"@winglang/sdk": "SDK", | ||
"examples-sdk": "SDK Tests", | ||
"docs": "Docs", | ||
"@wingconsole/app": "Console App", | ||
"@wingconsole/server": "Console Server", | ||
"@wingconsole/ui": "Console UI", | ||
"vscode-wing": "VSCode", | ||
"@winglang/jsii-docgen": "API Docs Generator", | ||
"wing-api-checker": "API Checker", | ||
"examples-valid": "Tests: Valid", | ||
"examples-invalid": "Tests: Invalid", | ||
"examples-error": "Tests: Error", | ||
}; | ||
|
||
async function getWorkspaceDir() { | ||
const workspaceDir = await findWorkspaceDir(process.cwd()); | ||
if (!workspaceDir) { | ||
throw new Error("No workspace found"); | ||
} | ||
return workspaceDir; | ||
} | ||
|
||
async function getWorkspacePackages(workspaceDir: string) { | ||
const workspacePackages = await findWorkspacePackages(workspaceDir); | ||
return workspacePackages; | ||
} | ||
|
||
function getFolders(workspacePackages: any[], workspaceDir: string) { | ||
const folders: Record<string, string>[] = []; | ||
for (const pkg of workspacePackages) { | ||
const pkgName = pkg.manifest.name; | ||
// Skip unwanted packages | ||
if (pkgName == undefined) throw new Error("Package name is undefined"); | ||
if (ignoreList.includes(pkgName)) continue; | ||
|
||
// Use name mapping if present, else use the package name | ||
const name = nameMapping[pkgName] || pkgName; | ||
const path = pkg.dir.replace(workspaceDir, "").substring(1); // Remove workspaceDir from the path | ||
|
||
folders.push({ name, path: `./${path}` }); | ||
} | ||
return folders; | ||
} | ||
|
||
function sortFolders(folders: any[]) { | ||
let sortedFolders = Object.keys(nameMapping).map(key => { | ||
return folders.find(folder => folder.name === key || folder.name === nameMapping[key]); | ||
}).filter(Boolean); | ||
return sortedFolders; | ||
} | ||
|
||
function warnAboutPackages(workspacePackages: any[]) { | ||
workspacePackages.forEach(pkg => { | ||
const pkgName = pkg.manifest.name; | ||
if (pkgName && (!ignoreList.includes(pkgName) && !Object.keys(nameMapping).includes(pkgName))) { | ||
console.warn(`Warning: Package ${pkgName} is not present in ignore list or name mappings. Please check ./tools/generate-workspace/src/cli.ts`); | ||
} | ||
}); | ||
} | ||
|
||
function checkIgnoreListAndNameMapping(workspacePackages: any[]) { | ||
ignoreList.forEach(ignoreItem => { | ||
if (!workspacePackages.some(pkg => pkg.manifest.name === ignoreItem)) { | ||
console.error(`Error: ${ignoreItem} from ignore list is not present as a workspace package. Please check ./tools/generate-workspace/src/cli.ts`); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
Object.keys(nameMapping).forEach(mappingItem => { | ||
if (!workspacePackages.some(pkg => pkg.manifest.name === mappingItem)) { | ||
console.error(`Error: ${mappingItem} from name mapping is not present as a workspace package. Please check ./tools/generate-workspace/src/cli.ts`); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
|
||
function writeWorkspaceFile(workspaceDir: string, sortedFolders: any[]) { | ||
const workspaceFilePath = join(workspaceDir, "wing.code-workspace"); | ||
writeFileSync(workspaceFilePath, JSON.stringify({ folders: sortedFolders, settings: {}}, null, 2)); | ||
console.log(`Workspace file written to ${workspaceFilePath}`); | ||
} | ||
|
||
async function main() { | ||
const workspaceDir = await getWorkspaceDir(); | ||
const workspacePackages = await getWorkspacePackages(workspaceDir); | ||
const folders = getFolders(workspacePackages, workspaceDir); | ||
const sortedFolders = sortFolders(folders); | ||
warnAboutPackages(workspacePackages); | ||
checkIgnoreListAndNameMapping(workspacePackages); | ||
writeWorkspaceFile(workspaceDir, sortedFolders); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"target": "ES2022", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"name": "ROOT", | ||
"path": "./" | ||
}, | ||
{ | ||
"name": "CLI", | ||
"path": "./apps/wing" | ||
}, | ||
{ | ||
"name": "Compiler", | ||
"path": "./libs/wingcompiler" | ||
}, | ||
{ | ||
"name": "SDK", | ||
"path": "./libs/wingsdk" | ||
}, | ||
{ | ||
"name": "SDK Tests", | ||
"path": "./examples/tests/sdk_tests" | ||
}, | ||
{ | ||
"name": "Docs", | ||
"path": "./docs/docs" | ||
}, | ||
{ | ||
"name": "Console App", | ||
"path": "./apps/wing-console/console/app" | ||
}, | ||
{ | ||
"name": "Console Server", | ||
"path": "./apps/wing-console/console/server" | ||
}, | ||
{ | ||
"name": "Console UI", | ||
"path": "./apps/wing-console/console/ui" | ||
}, | ||
{ | ||
"name": "VSCode", | ||
"path": "./apps/vscode-wing" | ||
}, | ||
{ | ||
"name": "API Docs Generator", | ||
"path": "./apps/jsii-docgen" | ||
}, | ||
{ | ||
"name": "API Checker", | ||
"path": "./apps/wing-api-checker" | ||
}, | ||
{ | ||
"name": "Tests: Valid", | ||
"path": "./examples/tests/valid" | ||
}, | ||
{ | ||
"name": "Tests: Invalid", | ||
"path": "./examples/tests/invalid" | ||
}, | ||
{ | ||
"name": "Tests: Error", | ||
"path": "./examples/tests/error" | ||
} | ||
], | ||
"settings": {} | ||
} |