-
Notifications
You must be signed in to change notification settings - Fork 8
Store a version number. #172
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
Closed
Closed
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 |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ import { createGeneratorContext } from '../editor/generator_context'; | |
|
|
||
| // Types, constants, and functions related to modules, regardless of where the modules are stored. | ||
|
|
||
| export const CURRENT_VERSION = '0.1'; | ||
|
|
||
| export type Module = { | ||
| modulePath: string, | ||
| moduleType: string, | ||
|
|
@@ -90,11 +92,13 @@ const MARKER_BLOCKS_CONTENT = 'blocksContent: '; | |
| const MARKER_METHODS = 'methods: '; | ||
| const MARKER_MODULE_TYPE = 'moduleType: '; | ||
| const MARKER_COMPONENTS = 'components: '; | ||
| const MARKER_VERSION = 'version: '; | ||
| const PARTS_INDEX_BLOCKS_CONTENT = 0; | ||
| const PARTS_INDEX_METHODS = 1; | ||
| const PARTS_INDEX_MODULE_TYPE = 2; | ||
| const PARTS_INDEX_COMPONENTS = 3; | ||
| const NUMBER_OF_PARTS = 4; | ||
| const PARTS_INDEX_VERSION = 4; | ||
| const NUMBER_OF_PARTS = 5; | ||
|
|
||
| export const UPLOAD_DOWNLOAD_FILE_EXTENSION = '.blocks'; | ||
|
|
||
|
|
@@ -572,19 +576,26 @@ export function makeModuleContent( | |
| pythonCode: string, | ||
| blocksContent: string, | ||
| methodsContent: string, | ||
| componentsContent: string): string { | ||
| componentsContent: string, | ||
| optVersionContent?: string): string { | ||
|
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. Not sure we want this optional. When one is uploaded without it, we are giving it a default value. |
||
|
|
||
| const versionContent = optVersionContent ? optVersionContent : CURRENT_VERSION; | ||
|
|
||
| let delimiter = DELIMITER_PREFIX; | ||
| while (module.moduleType.includes(delimiter) | ||
| || blocksContent.includes(delimiter) | ||
| || methodsContent.includes(delimiter) | ||
| || componentsContent.includes(delimiter)) { | ||
| || componentsContent.includes(delimiter) | ||
| || versionContent.includes(delimiter)) { | ||
| delimiter += '.'; | ||
| } | ||
| return ( | ||
| '# This file was generated by the Blocks editor.\n\n' + | ||
| pythonCode + '\n\n\n' + | ||
| '"""\n' + | ||
| delimiter + '\n' + | ||
| MARKER_VERSION + versionContent + '\n' + | ||
| delimiter + '\n' + | ||
| MARKER_COMPONENTS + componentsContent + '\n' + | ||
| delimiter + '\n' + | ||
| MARKER_MODULE_TYPE + module.moduleType + '\n' + | ||
|
|
@@ -639,6 +650,10 @@ function getParts(moduleContent: string): string[] { | |
| // This module was saved without components. | ||
| parts.push(MARKER_COMPONENTS + '[]'); | ||
| } | ||
| if (parts.length <= PARTS_INDEX_VERSION) { | ||
| // This module was saved without version. | ||
| parts.push(MARKER_VERSION + '0.0'); | ||
| } | ||
| return parts; | ||
| } | ||
|
|
||
|
|
@@ -692,6 +707,18 @@ export function extractComponents(moduleContent: string): Component[] { | |
| return components; | ||
| } | ||
|
|
||
| /** | ||
| * Extract the version from the given module content. | ||
| */ | ||
| export function extractVersion(moduleContent: string): string { | ||
| const parts = getParts(moduleContent); | ||
| let versionContent = parts[PARTS_INDEX_VERSION]; | ||
| if (versionContent.startsWith(MARKER_VERSION)) { | ||
| versionContent = versionContent.substring(MARKER_VERSION.length); | ||
| } | ||
| return versionContent; | ||
| } | ||
|
|
||
| /** | ||
| * Produce the blob for downloading a project. | ||
| */ | ||
|
|
@@ -737,6 +764,10 @@ function _processModuleContentForDownload( | |
| if (componentsContent.startsWith(MARKER_COMPONENTS)) { | ||
| componentsContent = componentsContent.substring(MARKER_COMPONENTS.length); | ||
| } | ||
| let versionContent = parts[PARTS_INDEX_VERSION]; | ||
| if (versionContent.startsWith(MARKER_VERSION)) { | ||
| versionContent = versionContent.substring(MARKER_VERSION.length); | ||
| } | ||
|
|
||
| const module: Module = { | ||
| modulePath: makeModulePath(projectName, moduleName), | ||
|
|
@@ -750,7 +781,12 @@ function _processModuleContentForDownload( | |
| // Clear out the python content. | ||
| const pythonCode = ''; | ||
| return makeModuleContent( | ||
| module, pythonCode, blocksContent, methodsContent, componentsContent); | ||
| module, | ||
| pythonCode, | ||
| blocksContent, | ||
| methodsContent, | ||
| componentsContent, | ||
| versionContent); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -826,6 +862,10 @@ export function _processUploadedModule( | |
| projectName: string, filename: string, uploadedContent: string) | ||
| : [string, string, string] { | ||
| const parts = getParts(uploadedContent); | ||
| let versionContent = parts[PARTS_INDEX_VERSION]; | ||
| if (versionContent.startsWith(MARKER_VERSION)) { | ||
| versionContent = versionContent.substring(MARKER_VERSION.length); | ||
| } | ||
| let blocksContent = parts[PARTS_INDEX_BLOCKS_CONTENT]; | ||
| if (blocksContent.startsWith(MARKER_BLOCKS_CONTENT)) { | ||
| blocksContent = blocksContent.substring(MARKER_BLOCKS_CONTENT.length); | ||
|
|
@@ -869,6 +909,11 @@ export function _processUploadedModule( | |
| headlessBlocklyWorkspace, generatorContext); | ||
|
|
||
| const moduleContent = makeModuleContent( | ||
| module, pythonCode, blocksContent, methodsContent, componentsContent); | ||
| module, | ||
| pythonCode, | ||
| blocksContent, | ||
| methodsContent, | ||
| componentsContent, | ||
| versionContent); | ||
| return [moduleName, moduleType, moduleContent]; | ||
| } | ||
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 wonder if we should use the blockly version instead of having a version specific for the file format