Skip to content

Commit fe0230f

Browse files
Merge branch 'master' into blockly-keyboard-experiment
2 parents 6b26e10 + 4f75b09 commit fe0230f

File tree

215 files changed

+4109
-1959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+4109
-1959
lines changed

cli/cli.ts

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,18 @@ ${gcards.map(gcard => `[${gcard.name}](${gcard.url})`).join(',\n')}
19461946
targetStrings[`{id:hardware-description}${opt.description}`] = opt.description;
19471947
}
19481948
}
1949+
1950+
const themeFiles = getThemeFilePaths();
1951+
for(const themePath of themeFiles) {
1952+
if (nodeutil.fileExistsSync(themePath)) {
1953+
const theme = nodeutil.readJson(themePath);
1954+
const name = theme["name"];
1955+
if (name) {
1956+
targetStrings[`{id:color-theme-name}${name}`] = name;
1957+
}
1958+
}
1959+
}
1960+
19491961
// extract strings from editor
19501962
["editor", "fieldeditors", "cmds"]
19511963
.filter(d => nodeutil.existsDirSync(d))
@@ -2153,6 +2165,7 @@ function buildReactAppAsync(app: string, parsed: commandParser.ParsedCommand, op
21532165
if (!opts.expandedPxtTarget) {
21542166
// read pxtarget.json, save into 'pxtTargetBundle' global variable
21552167
let cfg = readLocalPxTarget();
2168+
updateColorThemes(cfg);
21562169
nodeutil.writeFileSync(`${appRoot}/public/blb/target.js`, "// eslint-disable-next-line \n" + targetJsPrefix + JSON.stringify(cfg));
21572170
} else {
21582171
nodeutil.cp("built/target.js", `${appRoot}/public/blb`);
@@ -2169,6 +2182,7 @@ function buildReactAppAsync(app: string, parsed: commandParser.ParsedCommand, op
21692182

21702183
nodeutil.cp("targetconfig.json", `${appRoot}/public/blb`);
21712184
nodeutil.cp("node_modules/pxt-core/built/pxtlib.js", `${appRoot}/public/blb`);
2185+
nodeutil.cp("node_modules/pxt-core/built/web/pxtrcdeps.js", `${appRoot}/public/blb`);
21722186
if (opts.includePxtSim) {
21732187
nodeutil.cp("node_modules/pxt-core/built/pxtsim.js", `${appRoot}/public/blb`);
21742188
nodeutil.cp("node_modules/pxt-core/built/web/worker.js", `${appRoot}/public/blb`);
@@ -2282,6 +2296,75 @@ function updateTOC(cfg: pxt.TargetBundle) {
22822296
}
22832297
}
22842298

2299+
function getThemeFilePaths() {
2300+
const sharedThemeFiles = fs.existsSync("node_modules/pxt-core/theme/color-themes")
2301+
? nodeutil
2302+
.allFiles("node_modules/pxt-core/theme/color-themes", { maxDepth: 1, includeDirs: false })
2303+
.filter((f) => /\.json$/i.test(f))
2304+
: [];
2305+
2306+
const targetThemeFiles = fs.existsSync("theme/color-themes")
2307+
? nodeutil
2308+
.allFiles("theme/color-themes", { maxDepth: 1, includeDirs: false })
2309+
.filter((f) => /\.json$/i.test(f))
2310+
: [];
2311+
2312+
// Target takes precedence, so include those at the end (will overwrite shared themes)
2313+
return sharedThemeFiles.concat(targetThemeFiles);
2314+
}
2315+
2316+
function updateColorThemes(cfg: pxt.TargetBundle) {
2317+
pxt.log("Loading color themes...");
2318+
const themeFiles = getThemeFilePaths();
2319+
2320+
for (const themeFile of themeFiles) {
2321+
const themeFileDir = path.dirname(themeFile);
2322+
const fileData = fs.readFileSync(themeFile, "utf8");
2323+
const themeData = JSON.parse(fileData);
2324+
const theme: pxt.ColorThemeInfo = {
2325+
id: themeData.id,
2326+
name: themeData.name,
2327+
weight: themeData.weight,
2328+
monacoBaseTheme: themeData.monacoBaseTheme,
2329+
colors: themeData.colors
2330+
};
2331+
2332+
for (const overrideFile of themeData.overrideFiles ?? []) {
2333+
if (!overrideFile) {
2334+
// Skip empty entries
2335+
continue;
2336+
}
2337+
2338+
// Strip leading slashes, convert \ to /, and lowercase the path
2339+
const combinedPath = path.join(themeFileDir, overrideFile);
2340+
let cssText = fs.readFileSync(combinedPath, "utf8");
2341+
theme.overrideCss = theme.overrideCss ? `${theme.overrideCss}\n${cssText}` : cssText;
2342+
}
2343+
2344+
if (!cfg.colorThemeMap) {
2345+
cfg.colorThemeMap = {};
2346+
}
2347+
2348+
if (cfg.colorThemeMap[theme.id]) {
2349+
// Only overwrite specified fields
2350+
// This allows target themes to be built off of shared base themes and only specify certain changes.
2351+
const existingTheme = cfg.colorThemeMap[theme.id];
2352+
cfg.colorThemeMap[theme.id] = {
2353+
...existingTheme,
2354+
...theme,
2355+
colors: {
2356+
...existingTheme.colors,
2357+
...theme.colors
2358+
}
2359+
};
2360+
} else {
2361+
cfg.colorThemeMap[theme.id] = theme;
2362+
}
2363+
2364+
pxt.log(`Loaded theme ${theme.id}`);
2365+
}
2366+
}
2367+
22852368
function rebundleAsync() {
22862369
return buildTargetCoreAsync({ quick: true })
22872370
.then(() => buildSimAsync());
@@ -2355,6 +2438,7 @@ async function buildTargetCoreAsync(options: BuildTargetOptions = {}) {
23552438
let cfg = readLocalPxTarget()
23562439
updateDefaultProjects(cfg);
23572440
updateTOC(cfg);
2441+
updateColorThemes(cfg);
23582442

23592443
cfg.bundledpkgs = {}
23602444
pxt.setAppTarget(cfg);
@@ -2579,6 +2663,7 @@ async function buildTargetCoreAsync(options: BuildTargetOptions = {}) {
25792663
delete targetlight.compile.compilerExtension;
25802664
const targetlightjson = nodeutil.stringify(targetlight);
25812665
nodeutil.writeFileSync("built/targetlight.json", targetlightjson)
2666+
nodeutil.writeFileSync("built/targetlight.js", targetJsPrefix + targetlightjson)
25822667
nodeutil.writeFileSync("built/sim.webmanifest", nodeutil.stringify(webmanifest))
25832668

25842669
console.log("target.json built.");
@@ -7284,10 +7369,10 @@ ${pxt.crowdin.KEY_VARIABLE} - crowdin key
72847369
name: "buildskillmap",
72857370
aliases: ["skillmap"],
72867371
advanced: true,
7287-
help: "Serves the skill map webapp",
7372+
help: "Serves the skillmap webapp",
72887373
flags: {
72897374
serve: {
7290-
description: "Serve the skill map locally after building (npm start)"
7375+
description: "Serve the skillmap locally after building (npm start)"
72917376
},
72927377
docs: {
72937378
description: "Path to local docs folder to copy into skillmap",

common-docs/blocks.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
### @description Language constructs for the Block editor.
44

55
## #blocksbase
6-
Blocks snap into each other to define the program that your @boardname@ will run.
6+
7+
Blocks snap into each other to define the program that will run.
78
Blocks can be event (buttons, shake, ...) or need to be snapped into an event to run.
89
The [on-start](/blocks/on-start) event runs first.
910

common-docs/javascript/call.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Call a function
22

3-
The simplest way to get started in JavaScript with your @boardname@ is to
4-
call one of the @boardname@'s built-in JavaScript functions. Just like how Blocks
5-
are organized into categories/drawers, the @boardname@ functions are organized by
3+
The simplest way to get started in JavaScript is to
4+
call one of the built-in JavaScript functions. Just like how Blocks
5+
are organized into categories/drawers, the functions are organized by
66
namespaces, with names corresponding to the drawer names.
77

88
```typescript-ignore
@@ -11,6 +11,8 @@ Math.abs(-1)
1111

1212
### ~ hint
1313

14+
#### Functions in a namespace
15+
1416
If you want to see all functions available in the `Math` namespace, simply type `Math`
1517
followed by `.` and a list of all the functions will appear.
1618

common-docs/javascript/functions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ let sum = add(1, 2);
1414

1515
### ~ hint
1616

17-
For the @boardname@, you must specify a [type](/javascript/types) for each function parameter.
17+
#### Parameter types
18+
19+
You must specify a [type](/javascript/types) for each function parameter.
1820

1921
### ~
2022

common-docs/javascript/operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Operators
22

3-
The following JavaScript operators are supported for the @boardname@.
3+
The following JavaScript operators are supported:
44

55
## Assignment, arithmetic and bitwise
66

common-docs/javascript/sequence.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ doSomething(); // THIS LINE WILL NEVER EXECUTE!
3636

3737
### ~hint
3838

39+
#### No 'empty' statements
40+
3941
To avoid this problem, we don't allow a program to contain an empty statement, such as shown above.
4042
If you really want an empty statement, you need to use curly braces to delimit an empty statement block:
4143
```typescript-ignore

common-docs/javascript/statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Statements
22

3-
The following JavaScript statements are supported for the @boardname@:
3+
The following JavaScript statements are supported:
44

55
## Variable declarations
66
* [`const` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const)

common-docs/python/call.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Call a function
22

3-
The simplest way to get started in Python with your @boardname@ is to
4-
call one of the @boardname@'s built-in Python functions. Just like how Blocks
5-
are organized into categories/drawers, the @boardname@ functions are organized by
6-
namespaces, with names corresponding to the drawer names.
3+
The simplest way to get started in Python is to
4+
call one of the built-in Python functions. Just like how Blocks
5+
are organized into categories/drawers, functions are organized by
6+
namespaces too, with names corresponding to the drawer names.
77

88
```python-ignore
99
Math.abs(-1)
1010
```
1111

1212
### ~ hint
1313

14+
#### Functions in a namespace
15+
1416
If you want to see all functions available in the `Math` namespace, simply type `Math`
1517
followed by `.` and a list of all the functions will appear.
1618

common-docs/python/functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The default value of `lastName` disappears in the type, only leaving behind the
9696
Handler functions are functions that take some action when an event or change of state occurs. Usually, some other code saves, or registers, the handler function in a variable in order to call
9797
it at a later time. When an event happens, like a new input value or an elapsed timer, the handler is called to run a response action.
9898

99-
As an example, the `Thermal` class will check for changes in temperature and run a registered handler when the temperature drops to a set thershold:
99+
As an example, the `Thermal` class will check for changes in temperature and run a registered handler when the temperature drops to a set threshold:
100100

101101
```python-ignore
102102
# the handler function when it's cold...
@@ -122,9 +122,9 @@ thermal.whenCold(whenCold)
122122
thermal.checkCold()
123123
```
124124

125-
## Lamda Functions
125+
## Lambda Functions
126126

127-
Lamda functions serve as a kind of shortcut to return a result of an expression. A lamda is often saved to a variable and then used like a function to return the expression result:
127+
Lambda functions serve as a kind of shortcut to return a result of an expression. A lambda is often saved to a variable and then used like a function to return the expression result:
128128

129129
```python-ignore
130130
def square(x):

common-docs/python/operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Operators
22

3-
The following Python operators are supported for the @boardname@.
3+
The following Python operators are supported:
44

55
## Assignment, arithmetic and bitwise
66

0 commit comments

Comments
 (0)