-
Notifications
You must be signed in to change notification settings - Fork 634
allow tutorials and examples to remove dependencies from blocksprj #11397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
riknoll
wants to merge
3
commits into
master
Choose a base branch
from
dev/riknoll/microbit-markdown-remove-dependency
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−26
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5839,7 +5839,9 @@ export async function buildCoreDeclarationFiles(parsed: commandParser.ParsedComm | |
| nodeutil.mkdirP(builtFolder); | ||
| process.chdir(cwd); | ||
|
|
||
| const host = shareId ? new Host() : new SnippetHost("decl-build", { "main.ts" : "" }, { "blocksprj": "*" }); | ||
| const blocksprjConfig = readBlocksprjConfig(); | ||
|
|
||
| const host = shareId ? new Host() : new SnippetHost("decl-build", { "main.ts" : "" }, { ...blocksprjConfig.dependencies }); | ||
| const mainPkg = new pxt.MainPackage(host); | ||
|
|
||
| if (shareId) { | ||
|
|
@@ -6223,6 +6225,16 @@ function checkDocsAsync(parsed?: commandParser.ParsedCommand): Promise<void> { | |
| ) | ||
| } | ||
|
|
||
| function readBlocksprjConfig(): pxt.PackageConfig { | ||
| const configPath = path.join("libs", pxt.BLOCKS_PROJECT_NAME, "pxt.json"); | ||
|
|
||
| if (!nodeutil.fileExistsSync(configPath)) { | ||
| return undefined; | ||
| } | ||
| const config = nodeutil.readJson(configPath) as pxt.PackageConfig; | ||
| return config; | ||
| } | ||
|
|
||
| function checkFileSize(files: string[]): number { | ||
| if (!pxt.appTarget.cloud) | ||
| return 0; | ||
|
|
@@ -6262,6 +6274,8 @@ function internalCheckDocsAsync(compileSnippets?: boolean, re?: string, fix?: bo | |
| const existingSnippets: pxt.Map<boolean> = {}; | ||
| let snippets: CodeSnippet[] = []; | ||
|
|
||
| const blocksprjConfig = readBlocksprjConfig(); | ||
|
|
||
| const maxFileSize = checkFileSize(nodeutil.allFiles("docs", { maxDepth: 10, allowMissing: true, includeDirs: true, ignoredFileMarker: ".ignorelargefiles" })); | ||
| if (!pxt.appTarget.ignoreDocsErrors | ||
| && maxFileSize > (pxt.appTarget.cloud.maxFileSize || (30000000))) | ||
|
|
@@ -6434,7 +6448,7 @@ function internalCheckDocsAsync(compileSnippets?: boolean, re?: string, fix?: bo | |
| } | ||
|
|
||
| // look for snippets | ||
| getCodeSnippets(entrypath, md).forEach((snippet, snipIndex) => addSnippet(snippet, entrypath, snipIndex, entrypath)); | ||
| getCodeSnippets(entrypath, md, blocksprjConfig).forEach((snippet, snipIndex) => addSnippet(snippet, entrypath, snipIndex, entrypath)); | ||
| } | ||
|
|
||
| nodeutil.mkdirP("temp"); | ||
|
|
@@ -6479,8 +6493,7 @@ function internalCheckDocsAsync(compileSnippets?: boolean, re?: string, fix?: bo | |
| continue; | ||
| } | ||
| const tutorial = pxt.tutorial.parseTutorial(tutorialMd); | ||
| const pkgs: pxt.Map<string> = { "blocksprj": "*" }; | ||
| pxt.Util.jsonMergeFrom(pkgs, pxt.gallery.parsePackagesFromMarkdown(tutorialMd) || {}); | ||
| const pkgs = pxt.tutorial.mergeTutorialDependencies(blocksprjConfig.dependencies, pxt.gallery.parsePackagesFromMarkdown(tutorialMd) || {}); | ||
|
|
||
| let extraFiles: Map<string> = null; | ||
|
|
||
|
|
@@ -6497,7 +6510,7 @@ function internalCheckDocsAsync(compileSnippets?: boolean, re?: string, fix?: bo | |
| || (tutorial.language == "python")) { | ||
| tutorial.steps | ||
| .filter(step => !!step.contentMd) | ||
| .forEach((step, stepIndex) => getCodeSnippets(`${card.name}-step${stepIndex}`, step.contentMd) | ||
| .forEach((step, stepIndex) => getCodeSnippets(`${card.name}-step${stepIndex}`, step.contentMd, blocksprjConfig) | ||
| .forEach((snippet, snippetIndex) => { | ||
| snippet.packages = pkgs; | ||
| snippet.extraFiles = extraFiles; | ||
|
|
@@ -6539,8 +6552,7 @@ function internalCheckDocsAsync(compileSnippets?: boolean, re?: string, fix?: bo | |
| continue; | ||
| } | ||
| const prj = pxt.gallery.parseExampleMarkdown(card.name, exMd); | ||
| const pkgs: pxt.Map<string> = { "blocksprj": "*" }; | ||
| pxt.U.jsonMergeFrom(pkgs, prj.dependencies); | ||
| const pkgs = pxt.tutorial.mergeTutorialDependencies(blocksprjConfig.dependencies, prj.dependencies); | ||
|
|
||
| let extraFiles: Map<string> = undefined; | ||
|
|
||
|
|
@@ -6616,6 +6628,8 @@ function internalCacheUsedBlocksAsync(): Promise<Map<pxt.BuiltTutorialInfo>> { | |
| const mdRegex = /\.md$/; | ||
| const targetDirs = pxt.appTarget.cacheusedblocksdirs; | ||
| const builtTututorialInfo: Map<pxt.BuiltTutorialInfo> = {}; | ||
| const blocksprjConfig = readBlocksprjConfig(); | ||
|
|
||
| if (targetDirs) { | ||
| targetDirs.forEach(dir => { | ||
| pxt.log(`looking for tutorial markdown in ${dir}`); | ||
|
|
@@ -6633,8 +6647,9 @@ function internalCacheUsedBlocksAsync(): Promise<Map<pxt.BuiltTutorialInfo>> { | |
| pxt.log(`error resolving tutorial markdown at ${path}`); | ||
| } | ||
| const tutorial = pxt.tutorial.parseTutorial(md) as TutorialInfo; | ||
| const pkgs: pxt.Map<string> = { "blocksprj": "*" }; | ||
| pxt.Util.jsonMergeFrom(pkgs, pxt.gallery.parsePackagesFromMarkdown(md) || {}); | ||
| const tutorialDeps = pxt.gallery.parsePackagesFromMarkdown(md) || {}; | ||
| const pkgs: pxt.Map<string> = pxt.tutorial.mergeTutorialDependencies(blocksprjConfig.dependencies, tutorialDeps); | ||
|
|
||
| tutorial.pkgs = pkgs; | ||
| tutorial.path = path; | ||
|
|
||
|
|
@@ -6752,7 +6767,7 @@ export interface CodeSnippet { | |
| src?: string; | ||
| } | ||
|
|
||
| export function getCodeSnippets(fileName: string, md: string): CodeSnippet[] { | ||
| export function getCodeSnippets(fileName: string, md: string, baseConfig: pxt.PackageConfig): CodeSnippet[] { | ||
| const supported: pxt.Map<string> = { | ||
| "blocks": "ts", | ||
| "block": "ts", | ||
|
|
@@ -6778,21 +6793,20 @@ export function getCodeSnippets(fileName: string, md: string): CodeSnippet[] { | |
| }; | ||
| } | ||
|
|
||
|
|
||
| const pkgs: pxt.Map<string> = { | ||
| "blocksprj": "*" | ||
| } | ||
| snippets.filter(snip => snip.type == "package") | ||
| const tutorialDeps = snippets.filter(snip => snip.type == "package") | ||
| .map(snip => snip.code.split('\n')) | ||
| .forEach(lines => lines | ||
| .map(l => l.replace(/\s*$/, '')) | ||
| .filter(line => !!line) | ||
| .forEach(line => { | ||
| .reduce((acc, lines) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious why this was changed? |
||
| for (let line of lines) { | ||
| line = line.replace(/\s*$/, ''); | ||
| if (!line) continue; | ||
| const i = line.indexOf('='); | ||
| if (i < 0) pkgs[line] = "*"; | ||
| else pkgs[line.substring(0, i)] = line.substring(i + 1); | ||
| }) | ||
| ); | ||
| if (i < 0) acc[line] = "*"; | ||
| else acc[line.substring(0, i).trim()] = line.substring(i + 1); | ||
| } | ||
| return acc; | ||
| }, {} as pxt.Map<string>); | ||
|
|
||
| const pkgs = pxt.tutorial.mergeTutorialDependencies(baseConfig.dependencies, tutorialDeps); | ||
|
|
||
| const pkgName = fileName.replace(/\\/g, '-').replace(/.md$/i, ''); | ||
| return codeSnippets.map((snip, i) => { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some checking around this because if
readBlocksprjConfigreturns undefined, trying to expandblocksprjConfigwill throw an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throwing in cli on an invalid project build seems fine, though maybe an explicit exception would narrow in a bit quicker