forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add open in IDX support (angular#57099)
This change adds a menu to the in-browser code editor on adev and adds the option for open in IDX. PR Close angular#57099
- Loading branch information
1 parent
56816bb
commit ca8bd5b
Showing
12 changed files
with
273 additions
and
3 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
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
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,51 @@ | ||
/*! | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import {EnvironmentInjector, Injectable, inject} from '@angular/core'; | ||
import {injectAsync} from '../core/services/inject-async'; | ||
import * as IDX from 'open-in-idx'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class IDXLauncher { | ||
private readonly environmentInjector = inject(EnvironmentInjector); | ||
|
||
async openCurrentSolutionInIDX(): Promise<void> { | ||
const nodeRuntimeSandbox = await injectAsync(this.environmentInjector, () => | ||
import('./node-runtime-sandbox.service').then((c) => c.NodeRuntimeSandbox), | ||
); | ||
|
||
const runtimeFiles = await nodeRuntimeSandbox.getSolutionFiles(); | ||
const workspaceFiles: Record<string, string> = {}; | ||
|
||
for (let i = 0; i < runtimeFiles.length; i++) { | ||
const file = runtimeFiles[i]; | ||
|
||
//don't include config.json, BUILD.bazel, package-lock.json, package.json.template | ||
const doNotAllowList = [ | ||
'config.json', | ||
'BUILD.bazel', | ||
'package-lock.json', | ||
'package.json.template', | ||
]; | ||
|
||
const path = file.path.replace(/^\//, ''); | ||
|
||
//don't include binary formats | ||
if (!doNotAllowList.includes(path) && typeof file.content === 'string') { | ||
if (path === 'idx/dev.nix') { | ||
workspaceFiles['.idx/dev.nix'] = file.content as string; | ||
} else { | ||
workspaceFiles[path] = file.content as string; | ||
} | ||
} | ||
} | ||
IDX.newAdhocWorkspace({files: workspaceFiles}); | ||
} | ||
} |
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,35 @@ | ||
# To learn more about how to use Nix to configure your environment | ||
# see: https://developers.google.com/idx/guides/customize-idx-env | ||
{ pkgs, ... }: { | ||
# Which nixpkgs channel to use. | ||
channel = "stable-23.11"; # or "unstable" | ||
# Use https://search.nixos.org/packages to find packages | ||
packages = [ | ||
pkgs.nodejs_18 | ||
]; | ||
# Sets environment variables in the workspace | ||
env = {}; | ||
idx = { | ||
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" | ||
extensions = [ | ||
"angular.ng-template" | ||
]; | ||
workspace = { | ||
# Runs when a workspace is first created with this \`dev.nix\` file | ||
onCreate = { | ||
npm-install = "npm install --no-audit --prefer-offline"; | ||
}; | ||
# To run something each time the environment is rebuilt, use the \`onStart\` hook | ||
}; | ||
# Enable previews and customize configuration | ||
previews = { | ||
enable = true; | ||
previews = { | ||
web = { | ||
command = ["npm" "run" "start" "--" "--port" "$PORT" "--host" "0.0.0.0"]; | ||
manager = "web"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
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,35 @@ | ||
# To learn more about how to use Nix to configure your environment | ||
# see: https://developers.google.com/idx/guides/customize-idx-env | ||
{ pkgs, ... }: { | ||
# Which nixpkgs channel to use. | ||
channel = "stable-23.11"; # or "unstable" | ||
# Use https://search.nixos.org/packages to find packages | ||
packages = [ | ||
pkgs.nodejs_18 | ||
]; | ||
# Sets environment variables in the workspace | ||
env = {}; | ||
idx = { | ||
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" | ||
extensions = [ | ||
"angular.ng-template" | ||
]; | ||
workspace = { | ||
# Runs when a workspace is first created with this \`dev.nix\` file | ||
onCreate = { | ||
npm-install = "npm install --no-audit --prefer-offline"; | ||
}; | ||
# To run something each time the environment is rebuilt, use the \`onStart\` hook | ||
}; | ||
# Enable previews and customize configuration | ||
previews = { | ||
enable = true; | ||
previews = { | ||
web = { | ||
command = ["npm" "run" "start" "--" "--port" "$PORT" "--host" "0.0.0.0"]; | ||
manager = "web"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
35 changes: 35 additions & 0 deletions
35
adev/src/content/tutorials/learn-angular/common/idx/dev.nix
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,35 @@ | ||
# To learn more about how to use Nix to configure your environment | ||
# see: https://developers.google.com/idx/guides/customize-idx-env | ||
{ pkgs, ... }: { | ||
# Which nixpkgs channel to use. | ||
channel = "stable-23.11"; # or "unstable" | ||
# Use https://search.nixos.org/packages to find packages | ||
packages = [ | ||
pkgs.nodejs_18 | ||
]; | ||
# Sets environment variables in the workspace | ||
env = {}; | ||
idx = { | ||
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" | ||
extensions = [ | ||
"angular.ng-template" | ||
]; | ||
workspace = { | ||
# Runs when a workspace is first created with this \`dev.nix\` file | ||
onCreate = { | ||
npm-install = "npm install --no-audit --prefer-offline"; | ||
}; | ||
# To run something each time the environment is rebuilt, use the \`onStart\` hook | ||
}; | ||
# Enable previews and customize configuration | ||
previews = { | ||
enable = true; | ||
previews = { | ||
web = { | ||
command = ["npm" "run" "start" "--" "--port" "$PORT" "--host" "0.0.0.0"]; | ||
manager = "web"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
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,35 @@ | ||
# To learn more about how to use Nix to configure your environment | ||
# see: https://developers.google.com/idx/guides/customize-idx-env | ||
{ pkgs, ... }: { | ||
# Which nixpkgs channel to use. | ||
channel = "stable-23.11"; # or "unstable" | ||
# Use https://search.nixos.org/packages to find packages | ||
packages = [ | ||
pkgs.nodejs_18 | ||
]; | ||
# Sets environment variables in the workspace | ||
env = {}; | ||
idx = { | ||
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" | ||
extensions = [ | ||
"angular.ng-template" | ||
]; | ||
workspace = { | ||
# Runs when a workspace is first created with this \`dev.nix\` file | ||
onCreate = { | ||
npm-install = "npm install --no-audit --prefer-offline"; | ||
}; | ||
# To run something each time the environment is rebuilt, use the \`onStart\` hook | ||
}; | ||
# Enable previews and customize configuration | ||
previews = { | ||
enable = true; | ||
previews = { | ||
web = { | ||
command = ["npm" "run" "start" "--" "--port" "$PORT" "--host" "0.0.0.0"]; | ||
manager = "web"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -13260,6 +13260,11 @@ onetime@^5.1.0, onetime@^5.1.2: | |
dependencies: | ||
mimic-fn "^2.1.0" | ||
|
||
open-in-idx@^0.1.1: | ||
version "0.1.1" | ||
resolved "https://registry.yarnpkg.com/open-in-idx/-/open-in-idx-0.1.1.tgz#390cb0985146a461f5a662ed1fd0db3fce55b2f0" | ||
integrity sha512-4Cks2eY4bnWpBP/fEj1deRrVYbHME36g0w4/IFDG4iwnkD7CwmK9HrF3A3LR/RKHs5AXUMj49YxnwdIxEizDpA== | ||
|
||
[email protected]: | ||
version "8.4.2" | ||
resolved "https://registry.yarnpkg.com/open/-/open-8.4.2.tgz#5b5ffe2a8f793dcd2aad73e550cb87b59cb084f9" | ||
|