Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ Blockly.defineBlocksWithJsonArray([fooBlock]);
window.unixGenerator.forBlock['foo'] = window.unixGenerator.forBlock.generic;
```

**Note:** Even though it isnt recommended if the name of the block you are adding has a space in it (eg. `git add`) due to javascript naming convention there is a possibility your block and its unix_description isnt findble.

You can make it findable by adding this snippet of code to your block's file.

```js
// Make the block definition findable on the window object because the type has a space
window['command nameBlock'] = commandNameBlock;
```

#### 2.1 Managing `unix_description`

In the **UnixGenerator** architecture, each **Blockly** block has an associated `unix_description`, which describes how its fields (`fieldValues`) and child blocks (`childCode`) should be translated into a Unix command. Also it is crucial that the keys used in unix_description correspond exactly to the names of the fields defined in args. This ensures that the generator can correctly map field values to their respective parts in the Unix command. Below is a high-level overview of how this works:
Expand Down
61 changes: 61 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
<!-- <script src="https://unpkg.com/@blockly/block-plus-minus"></script> -->

<!-- BLOCKS DEFINITION -->
<script src="blocks/gitStashPopBlock.js"></script>
<script src="blocks/gitStashBlock.js"></script>
<script src="blocks/gitShowBlock.js"></script>
<script src="blocks/gitTagBlock.js"></script>
<script src="blocks/gitViewConfigBlock.js"></script>
<script src="blocks/gitSetConfigBlock.js"></script>
<script src="blocks/gitFetchBlock.js"></script>
<script src="blocks/gitCheckoutBlock.js"></script>
<script src="blocks/gitBranchBlock.js"></script>
<script src="blocks/gitRemoteBlock.js"></script>
<script src="blocks/gitMergeBlock.js"></script>
<script src="blocks/gitPullBlock.js"></script>
<script src="blocks/gitResetBlock.js"></script>
<script src="blocks/gitCleanBlock.js"></script>
<script src="blocks/gitRestoreBlock.js"></script>
<script src="blocks/gitDiffBlock.js"></script>
<script src="blocks/gitLogBlock.js"></script>
<script src="blocks/gitCloneBlock.js"></script>
<script src="blocks/gitInitBlock.js"></script>
<script src="blocks/gitPushBlock.js"></script>
<script src="blocks/gitStatusBlock.js"></script>
<script src="blocks/gitAddBlock.js"></script>
<script src="blocks/gitCommitBlock.js"></script>
<script src="blocks/psBlock.js"></script>
<script src="blocks/argumentsCreateBlock.js"></script>
<script src="blocks/argumentBlock.js"></script>
Expand Down Expand Up @@ -394,6 +417,11 @@
colourSecondary: '#ff0000',
colourTertiary: '#C5EAFF'
},
'Git Version Control': {
colourPrimary: '#D2042D', // Cherry Red
colourSecondary: '#B03B1E',
colourTertiary: '#FFD7C2'
},
'Other Commands': {
colourPrimary: '#009688',
colourSecondary: '#ff0000',
Expand Down Expand Up @@ -710,6 +738,39 @@
{
kind: 'sep'
},
{
kind: 'category',
name: 'Git Version Control',
colour: '#D2042D',
contents: [
{ kind: 'block', type: 'git init' },
{ kind: 'block', type: 'git clone' },
{ kind: 'block', type: 'git add' },
{ kind: 'block', type: 'git commit' },
{ kind: 'block', type: 'git status' },
{ kind: 'block', type: 'git push' },
{ kind: 'block', type: 'git log' },
{ kind: 'block', type: 'git diff' },
{ kind: 'block', type: 'git restore' },
{ kind: 'block', type: 'git clean' },
{ kind: 'block', type: 'git reset' },
{ kind: 'block', type: 'git pull' },
{ kind: 'block', type: 'git branch' },
{ kind: 'block', type: 'git checkout' },
{ kind: 'block', type: 'git merge' },
{ kind: 'block', type: 'git remote -v' },
{ kind: 'block', type: 'git fetch' },
{ kind: 'block', type: 'git config' },
{ kind: 'block', type: 'git config --list' },
{ kind: 'block', type: 'git tag' },
{ kind: 'block', type: 'git show' },
{ kind: 'block', type: 'git stash' },
{ kind: 'block', type: 'git stash pop' }
]
},
{
kind: 'sep'
},
{
kind: 'category',
name: [MSG.OTHER_COMMANDS],
Expand Down
55 changes: 55 additions & 0 deletions public/blocks/gitAddBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var gitAddBlock = {
type: 'git add',
category: 'Git Version Control',
unix_description: [
{
printName: true,
addOption: (fieldValues) => {
if (fieldValues['addOption'] === '.') {
return '.';
}
return '';
},
addPath: (fieldValues) => {
if (fieldValues['addOption'] === 'specific') {
return fieldValues['addPath'];
}
return '';
}
}
],
message0: '%{BKY_GIT_ADD_0}',
args0: [
{
type: 'field_dropdown',
name: 'addOption',
options: [
['all files', '.'],
['specific file', 'specific']
]
}
],
message1: '%{BKY_GIT_ADD_1}',
args1: [
{
type: 'field_input',
name: 'addPath',
text: 'path/to/file.txt'
}
],
previousStatement: 'Action',
nextStatement: 'Action',
style: 'Git Version Control',
tooltip: '%{BKY_GIT_ADD_TOOLTIP}',
helpUrl: '%{BKY_GIT_ADD_HELPURL}'
};

// Register the block with Blockly
Blockly.defineBlocksWithJsonArray([gitAddBlock]);

// Make the block definition findable on the window object because the type has a space
window['git addBlock'] = gitAddBlock;

// Register the generator for this block to use the 'sequence' connector
window.unixGenerator.forBlock['git add'] =
window.unixGenerator.forBlock.sequence;
36 changes: 36 additions & 0 deletions public/blocks/gitBranchBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var gitBranchBlock = {
type: 'git branch',
message0: '%{BKY_GIT_BRANCH} %1',
category: 'Git Version Control',
unix_description: [
{
printName: true,
branchName: (fieldValues) => {
return fieldValues['branchName'];
}
}
],
message0: '%{BKY_GIT_BRANCH}',
args0: [
{
type: 'field_input',
name: 'branchName',
text: 'feature-branch'
}
],
style: 'Git Version Control',
previousStatement: 'Action',
nextStatement: 'Action',
tooltip: '%{BKY_GIT_BRANCH_TOOLTIP}',
helpUrl: '%{BKY_GIT_BRANCH_HELPURL}'
};

// Register the block
Blockly.defineBlocksWithJsonArray([gitBranchBlock]);

// Make the block definition findable
window['git branchBlock'] = gitBranchBlock;

// Register the generator for this block
window.unixGenerator.forBlock['git branch'] =
window.unixGenerator.forBlock.sequence;
35 changes: 35 additions & 0 deletions public/blocks/gitCheckoutBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var gitCheckoutBlock = {
type: 'git checkout',
category: 'Git Version Control',
unix_description: [
{
printName: true,
branchName: (fieldValues) => {
return fieldValues['branchName'];
}
}
],
message0: '%{BKY_GIT_CHECKOUT}',
args0: [
{
type: 'field_input',
name: 'branchName',
text: 'main'
}
],
previousStatement: 'Action',
nextStatement: 'Action',
style: 'Git Version Control',
tooltip: '%{BKY_GIT_CHECKOUT_TOOLTIP}',
helpUrl: '%{BKY_GIT_CHECKOUT_HELPURL}'
};

// Register the block
Blockly.defineBlocksWithJsonArray([gitCheckoutBlock]);

// Make the block definition findable on the window object because the type has a space
window['git checkoutBlock'] = gitCheckoutBlock;

// Register the generator for this block to use the 'sequence' connector
window.unixGenerator.forBlock['git checkout'] =
window.unixGenerator.forBlock.sequence;
40 changes: 40 additions & 0 deletions public/blocks/gitCleanBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var gitCleanBlock = {
type: 'git clean',
category: 'Git Version Control',
unix_description: [
{
printName: true,
options: (fieldValues) => {
return fieldValues['options'];
}
}
],
message0: '%{BKY_GIT_CLEAN}',
args0: [
{
type: 'field_dropdown',
name: 'options',
options: [
['files only (-f)', '-f'],
['directories only (-d)', '-d'],
['both files and directories (-fd)', '-fd'],
['Show what would be deleted (dry run) (-n)', '-n']
]
}
],
previousStatement: 'Action',
nextStatement: 'Action',
style: 'Git Version Control',
tooltip: '%{BKY_GIT_CLEAN_TOOLTIP}',
helpUrl: '%{BKY_GIT_CLEAN_HELPURL}'
};

// Register the block with Blockly
Blockly.defineBlocksWithJsonArray([gitCleanBlock]);

// Make the block definition findable on the window object because the type has a space
window['git cleanBlock'] = gitCleanBlock;

// Register the generator for this block
window.unixGenerator.forBlock['git clean'] =
window.unixGenerator.forBlock.sequence;
35 changes: 35 additions & 0 deletions public/blocks/gitCloneBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var gitCloneBlock = {
type: 'git clone',
category: 'Git Version Control',
unix_description: [
{
printName: true,
repoUrl: (fieldValues) => {
return fieldValues['repoUrl'];
}
}
],
message0: '%{BKY_GIT_CLONE}',
args0: [
{
type: 'field_input',
name: 'repoUrl',
text: 'https://github.com/user/repo.git'
}
],
previousStatement: 'Action',
nextStatement: 'Action',
style: 'Git Version Control',
tooltip: '%{BKY_GIT_CLONE_TOOLTIP}',
helpUrl: '%{BKY_GIT_CLONE_HELPURL}'
};

// Register the block
Blockly.defineBlocksWithJsonArray([gitCloneBlock]);

// Make the block definition findable on the window object because the type has a space
window['git cloneBlock'] = gitCloneBlock;

// Register the generator for this block to use the 'sequence' connector
window.unixGenerator.forBlock['git clone'] =
window.unixGenerator.forBlock.sequence;
35 changes: 35 additions & 0 deletions public/blocks/gitCommitBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var gitCommitBlock = {
type: 'git commit',
category: 'Git Version Control',
unix_description: [
{
printName: true,
commitMessage: (fieldValues) => {
return '-m "' + fieldValues['commitMessage'] + '"';
}
}
],
message0: '%{BKY_GIT_COMMIT}',
args0: [
{
type: 'field_input',
name: 'commitMessage',
text: 'Initial commit'
}
],
previousStatement: 'Action',
nextStatement: 'Action',
style: 'Git Version Control',
tooltip: '%{BKY_GIT_COMMIT_TOOLTIP}',
helpUrl: '%{BKY_GIT_COMMIT_HELPURL}'
};

// Register the block with Blockly
Blockly.defineBlocksWithJsonArray([gitCommitBlock]);

// Make the block definition findable on the window object because the type has a space
window['git commitBlock'] = gitCommitBlock;

// Register the generator handler for this block to use the 'sequence' connector
window.unixGenerator.forBlock['git commit'] =
window.unixGenerator.forBlock.sequence;
30 changes: 30 additions & 0 deletions public/blocks/gitDiffBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var gitDiffBlock = {
type: 'git diff',
category: 'Git Version Control',
unix_description: [
{
printName: true,
// No arguments from fields, so this function returns an empty string.
// The command 'git diff' will be printed due to printName: true and block type.
message: () => {
return '';
}
}
],
message0: '%{BKY_GIT_DIFF}',
previousStatement: 'Action',
nextStatement: 'Action',
style: 'Git Version Control',
tooltip: '%{BKY_GIT_DIFF_TOOLTIP}',
helpUrl: '%{BKY_GIT_DIFF_HELPURL}'
};

// Register the block with Blockly
Blockly.defineBlocksWithJsonArray([gitDiffBlock]);

// Make the block definition findable on the window object because the type has a space
window['git diffBlock'] = gitDiffBlock;

// Register the generator for this block to use the 'sequence' connector
window.unixGenerator.forBlock['git diff'] =
window.unixGenerator.forBlock.sequence;
Loading