Skip to content

Commit ce704cd

Browse files
committed
rebase extension
1 parent 0197ec5 commit ce704cd

File tree

14 files changed

+1162
-3712
lines changed

14 files changed

+1162
-3712
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"./packages/lit-dev-server:build",
3333
"./packages/lit-dev-tests:build",
3434
"./packages/lit-dev-tools-cjs:build",
35-
"./packages/lit-dev-tools-esm:build"
35+
"./packages/lit-dev-tools-esm:build",
36+
"./packages/lit-dev-tutorial-plugin:build"
3637
]
3738
},
3839
"start": {

packages/lit-dev-content/site/learn/learn.11tydata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = {eleventyComputed: {learn: async (data) => {
6767
url,
6868
date
6969
} = content;
70-
if (!title || !summary || !['article', 'tutorial', 'video'].includes(kind) || !url || !date) {
70+
if (!title || summary === undefined || !['article', 'tutorial', 'video'].includes(kind) || !url || !date) {
7171
throw new Error(`Invalid content shape for: ${JSON.stringify(content)}`);
7272
}
7373
if (kind === "tutorial") {

packages/lit-dev-tutorial-plugin/package-lock.json

Lines changed: 0 additions & 3538 deletions
This file was deleted.

packages/lit-dev-tutorial-plugin/package.json

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"displayName": "lit.dev Tutorial Editor",
55
"description": "Helps you create tutorials for lit.dev",
6-
"version": "0.0.1",
6+
"version": "0.0.0",
77
"author": "Google LLC",
88
"license": "BSD-3-Clause",
99
"main": "./out/extension.js",
@@ -180,21 +180,42 @@
180180
},
181181
"scripts": {
182182
"vscode:prepublish": "npm run build",
183-
"build": "tsc -p ./",
184-
"watch": "tsc -watch -p ./",
185-
"pretest": "npm run build",
186-
"test": "node ./out/test/runTest.js",
187-
"clean": "rm -rf out .vscode-test .test-bin"
183+
"build": "wireit",
184+
"test": "wireit"
188185
},
189186
"devDependencies": {
190-
"@types/glob": "^7.2.0",
191-
"@types/mocha": "^9.1.0",
192-
"@types/node": "14.x",
193-
"@types/vscode": "^1.65.0",
194-
"@vscode/test-electron": "^2.1.2",
195-
"glob": "^7.2.0",
196-
"mocha": "^9.2.1",
197-
"playground-elements": "^0.15.2",
198-
"typescript": "^4.5.5"
187+
"@types/mocha": "^10.0.6",
188+
"@types/node": "^16.0.0",
189+
"@types/vscode": "^1.87.0",
190+
"@vscode/test-electron": "^2.3.9",
191+
"glob": "^10.3.0",
192+
"mocha": "^10.0.6"
193+
},
194+
"wireit": {
195+
"build": {
196+
"command": "tsc --build --pretty --incremental",
197+
"files": [
198+
"./src/**/*.ts",
199+
"tsconfig.json"
200+
],
201+
"output": [
202+
"./out/",
203+
"./tsconfig.tsbuildinfo"
204+
],
205+
"clean": "if-file-deleted"
206+
},
207+
"test": {
208+
"command": "node ./out/test/runTest.js",
209+
"dependencies": [
210+
"build"
211+
],
212+
"files": [
213+
"./out/test/"
214+
],
215+
"output": [
216+
"./.vscode-test",
217+
"./.test-bin"
218+
]
219+
}
199220
}
200221
}

packages/lit-dev-tutorial-plugin/src/fs-helpers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ export const addTutorialTo11tyData = (
3737
let categoryLines: {cat: TutorialCategory; line: number}[] = [];
3838

3939
for (const [i, line] of lines.entries()) {
40-
if (line.includes(`const tutorials = await Promise.all([`)) {
40+
if (line.includes(`return await Promise.all([`)) {
4141
arrayStartLine = i;
4242
} else if (line.includes(` ]);`)) {
43+
if (arrayStartLine === -1) {
44+
continue;
45+
}
4346
arrayEndLine = i;
4447
break;
4548
} else if (
@@ -54,7 +57,7 @@ export const addTutorialTo11tyData = (
5457
}
5558

5659
if (arrayStartLine === -1 || arrayEndLine === -1) {
57-
vscode.window.showErrorMessage('Malformed tutorials.11tydata.js');
60+
vscode.window.showErrorMessage('Malformed _data/tutorials.js');
5861
return;
5962
}
6063

@@ -71,7 +74,7 @@ export const addTutorialTo11tyData = (
7174

7275
if (line === -1) {
7376
vscode.window.showErrorMessage(
74-
'Cannot find category ${category} in tutorials.11tydata.js'
77+
'Cannot find category ${category} in _data/tutorials.js'
7578
);
7679
return;
7780
}

packages/lit-dev-tutorial-plugin/src/test/suite/extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {beforeEach, afterEach, before} from 'mocha';
1515

1616
suite('Tutorial Extension', () => {
1717
vscode.window.showInformationMessage('Start all tests.');
18+
1819
let litDevPath: string;
1920
let litDevContentPath!: string;
2021
before(async () => {

packages/lit-dev-tutorial-plugin/src/test/suite/index.ts

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,38 @@
66

77
import * as path from 'path';
88
import * as Mocha from 'mocha';
9-
import * as glob from 'glob';
9+
import {glob} from 'glob';
1010

1111
export function run(): Promise<void> {
12-
// Create the mocha test
13-
const mocha = new Mocha({
14-
ui: 'tdd',
15-
color: true
16-
});
12+
// Create the mocha test
13+
const mocha = new Mocha({
14+
ui: 'tdd',
15+
color: true,
16+
});
1717

18-
const testsRoot = path.resolve(__dirname, '..');
18+
const testsRoot = path.resolve(__dirname, '..');
1919

20-
return new Promise((c, e) => {
21-
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
22-
console.log(files);
23-
if (err) {
24-
return e(err);
25-
}
20+
return new Promise(async (c, e) => {
21+
const files = await glob('**/**.test.js', {cwd: testsRoot});
22+
console.log(files);
2623

27-
console.log(path.resolve(testsRoot, files[0]));
24+
console.log(path.resolve(testsRoot, files[0]));
2825

29-
// Add files to the test suite
30-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
26+
// Add files to the test suite
27+
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
3128

32-
try {
33-
// Run the mocha test
34-
mocha.run(failures => {
35-
if (failures > 0) {
36-
e(new Error(`${failures} tests failed.`));
37-
} else {
38-
c();
39-
}
40-
});
41-
} catch (err) {
42-
console.error(err);
43-
e(err);
44-
}
45-
});
46-
});
29+
try {
30+
// Run the mocha test
31+
mocha.run((failures) => {
32+
if (failures > 0) {
33+
e(new Error(`${failures} tests failed.`));
34+
} else {
35+
c();
36+
}
37+
});
38+
} catch (err) {
39+
console.error(err);
40+
e(err);
41+
}
42+
});
4743
}

packages/lit-dev-tutorial-plugin/src/test/util.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export const createEmptyLitDevRepo = async () => {
2626
'site',
2727
'tutorials'
2828
);
29+
const litDevSite11tydataPath = path.join(
30+
litDevContentPath,
31+
'site',
32+
'_data',
33+
'tutorials.js'
34+
);
2935
const litDevSiteTutorialContentPath = path.join(
3036
litDevSiteTutorialPath,
3137
'content'
@@ -76,10 +82,7 @@ export const createEmptyLitDevRepo = async () => {
7682
path.join(litDevSampleTutorialPath, 'base.json'),
7783
JSON.stringify(baseJson, null, 2)
7884
),
79-
fs.writeFile(
80-
path.join(litDevSiteTutorialPath, 'tutorials.11tydata.js'),
81-
tutorials11tyData
82-
),
85+
fs.writeFile(litDevSite11tydataPath, tutorials11tyData),
8386
]);
8487

8588
return {litDevPath, litDevContentPath};
@@ -110,17 +113,19 @@ export const prepopulateTutorial = async (
110113
'site',
111114
'tutorials'
112115
);
116+
const litDevSite11tydataPath = path.join(
117+
litDevContentPath,
118+
'site',
119+
'_data',
120+
'tutorials.js'
121+
);
113122
const litDevSiteTutorialContentPath = path.join(
114123
litDevSiteTutorialPath,
115124
'content'
116125
);
117126

118127
const promises: Promise<unknown>[] = [];
119-
const dataFile = await (
120-
await fs.readFile(
121-
path.join(litDevSiteTutorialPath, 'tutorials.11tydata.js')
122-
)
123-
).toString();
128+
const dataFile = await (await fs.readFile(litDevSite11tydataPath)).toString();
124129
const dataFileLines = dataFile.split('\n');
125130

126131
for (const tutorial of options.tutorials) {
@@ -193,7 +198,7 @@ export const prepopulateTutorial = async (
193198

194199
for (let i = options.tutorials.length - 1; i >= 0; i--) {
195200
const tutorial = options.tutorials[i];
196-
const tutorialSection = tutorial.category;
201+
const tutorialSection = (tutorial as typeof tutorial & {category ?: 'Learn'|'Build'}).category ?? 'Learn';
197202
const tutorialIndex = dataFileLines.findIndex((line) =>
198203
line.includes(`// ${tutorialSection}`)
199204
);
@@ -202,12 +207,7 @@ export const prepopulateTutorial = async (
202207
dataFileLines.splice(tutorialIndex + 1, 0, tutorialLine);
203208
}
204209

205-
promises.push(
206-
fs.writeFile(
207-
path.join(litDevSiteTutorialPath, 'tutorials.11tydata.js'),
208-
dataFileLines.join('\n')
209-
)
210-
);
210+
promises.push(fs.writeFile(litDevSite11tydataPath, dataFileLines.join('\n')));
211211
await Promise.all(promises);
212212
};
213213

packages/lit-dev-tutorial-plugin/src/tree-items/before-after-dir.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export class BeforeAfterDir extends vscode.TreeItem {
6161
}
6262
}
6363

64-
static create(tutorialStep: TutorialStep, name: 'before' | 'after') {
64+
static create(
65+
tutorialStep: TutorialStep,
66+
name: 'before' | 'after',
67+
checkable?: boolean
68+
) {
6569
const provider = tutorialStep.provider;
6670
const newDir = new BeforeAfterDir(provider, tutorialStep, name);
6771
newDir.contextValue = `${name}Dir`;
@@ -89,6 +93,9 @@ export class BeforeAfterDir extends vscode.TreeItem {
8993
extends: '/samples/base.json',
9094
files: {},
9195
};
96+
if (checkable) {
97+
projectJson.extends = '/samples/checkable-tutorial-base.json';
98+
}
9299
GenericFile.create(
93100
provider,
94101
path.join(newDir.path, 'project.json'),
@@ -103,11 +110,31 @@ export class BeforeAfterDir extends vscode.TreeItem {
103110
<html>
104111
<head>
105112
<script type="module" src=""></script>
106-
</head>
113+
${
114+
checkable
115+
? ' <!-- playground-hide --><script type="module" src="./_check-code.js"></script><!-- playground-hide-end -->\n'
116+
: ''
117+
} </head>
107118
<body>
108119
</body>
109120
</html>`
110121
);
122+
if (checkable) {
123+
PlaygroundFile.create(
124+
newDir,
125+
'_check-code.js',
126+
{hidden: true},
127+
`import {installCodeChecker} from './_check-code-helpers.js';
128+
129+
installCodeChecker(async () => {
130+
let passed = true;
131+
let message = '';
132+
133+
window.location.reload();
134+
return {passed, message};
135+
});`
136+
);
137+
}
111138

112139
provider.refresh();
113140

0 commit comments

Comments
 (0)