Skip to content

Commit 2ebd2a7

Browse files
committed
builtin: manage extensions
1 parent 1a4c15e commit 2ebd2a7

File tree

8 files changed

+235
-4
lines changed

8 files changed

+235
-4
lines changed

build/builtin/.eslintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es6": true,
5+
"browser": true
6+
},
7+
"rules": {
8+
"no-console": 0,
9+
"no-cond-assign": 0,
10+
"no-unused-vars": 1,
11+
"no-extra-semi": "warn",
12+
"semi": "warn"
13+
},
14+
"extends": "eslint:recommended",
15+
"parserOptions": {
16+
"ecmaFeatures": {
17+
"experimentalObjectRestSpread": true
18+
}
19+
}
20+
}

build/builtin/browser-main.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
const os = require('os');
9+
const { remote } = require('electron');
10+
const dialog = remote.dialog;
11+
12+
const builtInExtensionsPath = path.join(__dirname, '..', 'builtInExtensions.json');
13+
const controlFilePath = path.join(os.homedir(), '.vscode-oss-dev', 'extensions', 'control.json');
14+
15+
function readJson(filePath) {
16+
return JSON.parse(fs.readFileSync(filePath));
17+
}
18+
19+
function writeJson(filePath, obj) {
20+
fs.writeFileSync(filePath, JSON.stringify(obj, null, 2));
21+
}
22+
23+
function renderOption(form, id, title, value, checked) {
24+
const input = document.createElement('input');
25+
input.type = 'radio';
26+
input.id = id;
27+
input.name = 'choice';
28+
input.value = value;
29+
input.checked = !!checked;
30+
form.appendChild(input);
31+
32+
const label = document.createElement('label');
33+
label.setAttribute('for', id);
34+
label.textContent = title;
35+
form.appendChild(label);
36+
37+
return input;
38+
}
39+
40+
function render(el, state) {
41+
function setState(state) {
42+
try {
43+
writeJson(controlFilePath, state.control);
44+
} catch (err) {
45+
console.error(err);
46+
}
47+
48+
el.innerHTML = '';
49+
render(el, state);
50+
}
51+
52+
const ul = document.createElement('ul');
53+
const { builtin, control } = state;
54+
55+
for (const ext of builtin) {
56+
const controlState = control[ext.name] || 'marketplace';
57+
58+
const li = document.createElement('li');
59+
ul.appendChild(li);
60+
61+
const name = document.createElement('code');
62+
name.textContent = ext.name;
63+
li.appendChild(name);
64+
65+
const form = document.createElement('form');
66+
li.appendChild(form);
67+
68+
const marketplaceInput = renderOption(form, `marketplace-${ext.name}`, 'Marketplace', 'marketplace', controlState === 'marketplace');
69+
marketplaceInput.onchange = function () {
70+
control[ext.name] = 'marketplace';
71+
setState({ builtin, control });
72+
};
73+
74+
const disabledInput = renderOption(form, `disabled-${ext.name}`, 'Disabled', 'disabled', controlState === 'disabled');
75+
disabledInput.onchange = function () {
76+
control[ext.name] = 'disabled';
77+
setState({ builtin, control });
78+
};
79+
80+
let local = undefined;
81+
82+
if (controlState !== 'marketplace' && controlState !== 'disabled') {
83+
local = controlState;
84+
}
85+
86+
const localInput = renderOption(form, `local-${ext.name}`, 'Local', 'local', !!local);
87+
localInput.onchange = function () {
88+
const result = dialog.showOpenDialog(remote.getCurrentWindow(), {
89+
title: 'Choose Folder',
90+
properties: ['openDirectory']
91+
});
92+
93+
if (result && result.length >= 1) {
94+
control[ext.name] = result[0];
95+
}
96+
97+
setState({ builtin, control });
98+
};
99+
100+
if (local) {
101+
const localSpan = document.createElement('code');
102+
localSpan.className = 'local';
103+
localSpan.textContent = local;
104+
form.appendChild(localSpan);
105+
}
106+
}
107+
108+
el.appendChild(ul);
109+
}
110+
111+
function main() {
112+
const el = document.getElementById('extensions');
113+
const builtin = readJson(builtInExtensionsPath);
114+
let control;
115+
116+
try {
117+
control = readJson(controlFilePath);
118+
} catch (err) {
119+
control = {};
120+
}
121+
122+
render(el, { builtin, control });
123+
}
124+
125+
window.onload = main;

build/builtin/index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
2+
3+
<!DOCTYPE html>
4+
<html>
5+
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
9+
<title>Manage Built-in Extensions</title>
10+
<meta name="viewport" content="width=device-width, initial-scale=1">
11+
<script src="browser-main.js"></script>
12+
<style>
13+
body {
14+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
15+
font-size: 10pt;
16+
}
17+
18+
code {
19+
font-family: 'Menlo', 'Courier New', 'Courier', monospace;
20+
}
21+
22+
ul {
23+
padding-left: 1em;
24+
}
25+
26+
li {
27+
list-style: none;
28+
padding: 0.3em 0;
29+
}
30+
31+
label {
32+
margin-right: 1em;
33+
}
34+
35+
form {
36+
padding: 0.3em 0 0.3em 0.3em;
37+
}
38+
</style>
39+
</head>
40+
41+
<body>
42+
<h1>Built-in Extensions</h1>
43+
<div id="extensions"></div>
44+
</body>
45+
46+
</html>

build/builtin/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const { app, BrowserWindow } = require('electron');
7+
const url = require('url');
8+
const path = require('path');
9+
10+
let window = null;
11+
12+
app.once('ready', () => {
13+
window = new BrowserWindow({ width: 800, height: 600 });
14+
window.setMenuBarVisibility(false);
15+
window.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true }));
16+
// window.webContents.openDevTools();
17+
window.once('closed', () => window = null);
18+
});
19+
20+
app.on('window-all-closed', () => app.quit());

build/builtin/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "builtin",
3+
"version": "0.1.0",
4+
"main": "main.js"
5+
}

build/lib/builtInExtensions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function syncExtension(extension, controlState) {
7575
return es.readArray([]);
7676
}
7777

78-
util.log(util.colors.blue('[local]'), `${extension.name}: ${controlState}`, util.colors.green('✔︎'));
78+
util.log(util.colors.blue('[local]'), `${extension.name}: ${util.colors.cyan(controlState)}`, util.colors.green('✔︎'));
7979
return es.readArray([]);
8080
}
8181
}
@@ -95,7 +95,7 @@ function writeControlFile(control) {
9595

9696
function main() {
9797
util.log('Syncronizing built-in extensions...');
98-
util.log('Control file:', controlFilePath);
98+
util.log(`You can manage built-in extensions with the ${util.colors.cyan('--builtin')} flag`);
9999

100100
const control = readControlFile();
101101
const streams = [];
@@ -115,7 +115,6 @@ function main() {
115115
process.exit(1);
116116
})
117117
.on('end', () => {
118-
util.log(`${streams.length} built-in extensions processed.`);
119118
process.exit(0);
120119
});
121120
}

scripts/code.bat

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ set CODE=".build\electron\%NAMESHORT%"
1717
node build\lib\electron.js
1818
if %errorlevel% neq 0 node .\node_modules\gulp\bin\gulp.js electron
1919

20+
:: Manage build-in extensions
21+
if "%1"=="--builtin" goto builtin
22+
2023
:: Sync built-in extensions
2124
node build\lib\builtInExtensions.js
2225

@@ -37,6 +40,13 @@ set ELECTRON_ENABLE_STACK_DUMPING=1
3740
:: %CODE% --js-flags="--trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces" . %*
3841

3942
%CODE% . %*
43+
goto end
44+
45+
:builtin
46+
%CODE% build/builtin
47+
48+
:end
49+
4050
popd
4151

42-
endlocal
52+
endlocal

scripts/code.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function code() {
2424
# Get electron
2525
node build/lib/electron.js || ./node_modules/.bin/gulp electron
2626

27+
# Manage built-in extensions
28+
if [[ "$1" == "--builtin" ]]; then
29+
exec "$CODE" build/builtin
30+
return
31+
fi
32+
2733
# Sync built-in extensions
2834
node build/lib/builtInExtensions.js
2935

0 commit comments

Comments
 (0)