Skip to content

Commit 78cd8dd

Browse files
committed
Fix errors of merge conflicts resolution
1 parent 76a98a1 commit 78cd8dd

18 files changed

Lines changed: 1428 additions & 3699 deletions

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ To ensure that code is properly formatted before committing, set up the pre-comm
2525

2626
`chmod +x .git/hooks/pre-commit bin/pre-commit`
2727

28+
### Setting up the .env File
29+
30+
The application requires a `SECRET_KEY` for session management. This key must be securely generated and stored in a `.env` file.
31+
32+
1. Generate `SECRET_KEY`: To generate a secure `SECRET_KEY`, run the following command in your terminal:
33+
34+
`node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"`
35+
36+
2. Create the `.env` File: In the root directory of your project, create a new file named `.env`.
37+
38+
3. Set the `SECRET_KEY` Variable: Add the generated `SECRET_KEY` to the `.env` file using the following format: `SECRET_KEY=your_generated_secret_key_here`. Replace `your_generated_secret_key_here` with the actual key you generated from the previous step.
39+
2840
## How to Create a New Block
2941

3042
Below are the instructions on how to create a new block in a separate file (e.g., `[blockName]Block.js`), and how to integrate it into the existing code generation system (`UnixGenerator`) that we have already implemented.

blockly_unix_database.db

-48 KB
Binary file not shown.

db/blockly_unix_database.db

32 KB
Binary file not shown.

public/blocks/appendBlock.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ var appendBlock = {
44
message0: '%{BKY_APPEND} %1',
55
unix_description: [
66
{
7-
append_filename: '>> str'
7+
printName: false,
8+
append_filename: (fieldValues) => {
9+
const userInput = fieldValues['append_filename'] || '';
10+
return ' >> ' + userInput;
11+
}
812
}
913
],
1014
args0: [
@@ -21,3 +25,4 @@ var appendBlock = {
2125
};
2226

2327
Blockly.defineBlocksWithJsonArray([appendBlock]);
28+
window.unixGenerator.forBlock['append'] = window.unixGenerator.forBlock.concat;

public/blocks/awkBlock.js

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,38 @@
11
var awkBlock = {
22
type: 'awk',
3-
category: 'Data Processing',
3+
category: 'Field Processing',
44
unix_description: [
55
{
6-
awkInput_delimiter: "-F'str' ", // Change to awk_delimiter
7-
awkOutput_delimiter: 'OFS"str"', // Change to awk_delimiter
8-
input_variable: '-v"',
9-
regPattern: "'{patt",
10-
awk_cols: "{print str}}'",
11-
begin: 'BEGIN',
12-
end: 'END'
6+
printName: true,
7+
awkInput_delimiter: (fieldValues) => {
8+
return "-F '" + fieldValues['awkInput_delimiter'] + "'";
9+
},
10+
awkConditionAction: (childCode) => {
11+
return "' " + childCode + " '";
12+
}
1313
}
1414
],
1515
message0: '%{BKY_AWK_TEXT_DATA_PROCESSING}',
1616
message1: '%{BKY_AWK_INPUT_DELIMITER} %1',
1717
args1: [
1818
{
1919
type: 'field_input',
20-
name: 'awkInput_delimiter', // Change to awk_delimiter
21-
text: ''
20+
name: 'awkInput_delimiter' // Change to awk_delimiter
2221
}
2322
],
24-
message2: '%{BKY_AWK_OUTPUT_DELIMITER} %1',
23+
message2: '%{BKY_AWK_CONDITION_ACTION} %1',
2524
args2: [
2625
{
27-
type: 'field_input',
28-
name: 'awkOutput_delimiter', // Change to output awk_delimiter
29-
text: '',
30-
align: 'RIGHT'
31-
}
32-
],
33-
message3: '%{BKY_AWK_VARIABLE_INPUT} %1',
34-
args3: [
35-
{
36-
type: 'field_checkbox',
37-
name: 'input_variable',
38-
checked: false // by default it's disabled
39-
}
40-
],
41-
message3: '%{BKY_AWK_BEGIN} %1',
42-
args3: [
43-
{
44-
type: 'input_value',
45-
name: 'begin',
46-
check: 'String'
47-
}
48-
],
49-
message4: '%{BKY_AWK_ACTION} %1',
50-
args4: [
51-
{
52-
type: 'input_value',
53-
name: 'regPattern',
54-
check: 'String'
55-
}
56-
],
57-
message5: '%{BKY_AWK_BEGIN} %1',
58-
args5: [
59-
{
60-
type: 'input_value',
61-
name: 'end',
62-
check: 'String'
63-
}
64-
],
65-
message6: '%{BKY_AWK_PRINT} %1',
66-
args6: [
67-
{
68-
type: 'input_value',
69-
name: 'awk_cols',
70-
text: ''
26+
type: 'input_statement',
27+
name: 'awkConditionAction'
7128
}
7229
],
73-
style: 'Data Processing',
30+
style: 'Field Processing',
7431
previousStatement: 'Action',
7532
nextStatement: 'Action',
7633
tooltip: '%{BKY_AWK_TOOLTIP}',
7734
helpUrl: '%{BKY_AWK_HELPURL}' // URL to further information or documentation.
7835
};
7936

8037
Blockly.defineBlocksWithJsonArray([awkBlock]);
38+
window.unixGenerator.forBlock['awk'] = window.unixGenerator.forBlock.generic;

public/blocks/cdBlock.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
var cdBlock = {
22
type: 'cd',
3-
category: 'File and Directory Operations',
4-
unix_description: [{}],
3+
category: 'Filesystem Operations',
4+
unix_description: [
5+
{
6+
printName: true,
7+
directory: (fieldValues) => {
8+
return fieldValues['directory'];
9+
}
10+
}
11+
],
512
message0: '%{BKY_CD} %1',
613
args0: [
714
{
@@ -10,9 +17,11 @@ var cdBlock = {
1017
text: '............' // empty text for user to define path
1118
}
1219
],
13-
style: 'File and Directory Operations',
20+
style: 'Filesystem Operations',
1421
tooltip: '%{BKY_CD_TOOLTIP}',
1522
helpUrl: '%{BKY_CD_HELPURL}' // URL to further information or documentation.
1623
};
1724

1825
Blockly.defineBlocksWithJsonArray([cdBlock]);
26+
27+
window.unixGenerator.forBlock['cd'] = window.unixGenerator.forBlock.generic;

public/blocks/cutBlock.js

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,64 @@ var cutBlock = {
33
category: 'Text Processing',
44
unix_description: [
55
{
6-
delimiter: "-d 'str'",
7-
columns: '-f str',
8-
charsStart: '-c str',
9-
charsEnd: '-c-str'
6+
printName: true,
7+
delimiter: (fieldValues) => {
8+
return "-d '" + fieldValues['delimiter'] + "'";
9+
}, // Wrap value in -d 'value'
10+
columns: (fieldValues) => {
11+
const columns = fieldValues['columns'] || '';
12+
13+
// Normalize by replacing any whitespace or multiple delimiters with a single comma
14+
return (
15+
'-f ' +
16+
columns
17+
.split(/[\s,]+/) // Split by any whitespace or commas
18+
.filter((col) => col.trim()) // Remove empty entries
19+
.join(',')
20+
); // Join with a comma
21+
}, // Format for specific columns
22+
colsStart: (fieldValues) => {
23+
const { columns, colsStart, colsEnd } = fieldValues;
24+
25+
if (columns) {
26+
// If columns have values, append colsStart and colsEnd next to them
27+
return colsStart
28+
? `,${colsStart}${colsEnd ? `-${colsEnd}` : '-'}`
29+
: '';
30+
}
31+
// If columns were empty, start with '-f' and use colsStart and colsEnd
32+
return colsStart
33+
? `-f ${colsStart}${colsEnd ? `-${colsEnd}` : '-'}`
34+
: '';
35+
},
36+
individualChars: (fieldValues) => {
37+
const individualChars = fieldValues['individualChars'] || '';
38+
39+
// Normalize by replacing any whitespace or multiple delimiters with a single comma
40+
return (
41+
'-c ' +
42+
individualChars
43+
.split(/[\s,]+/) // Split by any whitespace or commas
44+
.filter((char) => char.trim()) // Remove empty entries
45+
.join(',')
46+
); // Join with a comma
47+
},
48+
49+
// Handle starting characters
50+
charsStart: (fieldValues) => {
51+
const { individualChars, charsStart, charsEnd } = fieldValues;
52+
53+
if (individualChars) {
54+
// If individualChars have values, append charsStart and charsEnd next to them
55+
return charsStart
56+
? `,${charsStart}${charsEnd ? `-${charsEnd}` : '-'}`
57+
: '';
58+
}
59+
// If individualChars were empty, start with '-c' and use charsStart and charsEnd
60+
return charsStart
61+
? `-c ${charsStart}${charsEnd ? `-${charsEnd}` : '-'}`
62+
: '';
63+
}
1064
}
1165
],
1266
message0: '%{BKY_CUT}\n',
@@ -26,8 +80,29 @@ var cutBlock = {
2680
text: ''
2781
}
2882
],
29-
message3: '%{BKY_CUT_START} %1 %{BKY_CUT_END} %2',
83+
message3: '%{BKY_CUT_COLUMNS_START} %1 %{BKY_CUT_COLUMNS_END} %2\n',
3084
args3: [
85+
{
86+
type: 'field_input',
87+
name: 'colsStart',
88+
text: ''
89+
},
90+
{
91+
type: 'field_input',
92+
name: 'colsEnd',
93+
text: ''
94+
}
95+
],
96+
message4: '%{BKY_CUT_SPECIFIC_CHARACTERS} %1\n',
97+
args4: [
98+
{
99+
type: 'field_input',
100+
name: 'individualChars',
101+
text: ''
102+
}
103+
],
104+
message5: '%{BKY_CUT_START} %1 %{BKY_CUT_END} %2',
105+
args5: [
31106
{
32107
type: 'field_input',
33108
name: 'charsStart',
@@ -39,17 +114,13 @@ var cutBlock = {
39114
text: ''
40115
}
41116
],
42-
43117
style: 'Text Processing',
44118
previousStatement: 'Action',
45119
nextStatement: 'Action',
46120
tooltip: '%{BKY_CUT_TOOLTIP}',
47-
extensions: [
48-
'cut_validation',
49-
'integer_validation',
50-
'disallow_multiple_filenames'
51-
],
52121
helpUrl: '%{BKY_CUT_HELPURL}' // URL to further information or documentation.
53122
};
54123

55124
Blockly.defineBlocksWithJsonArray([cutBlock]);
125+
126+
window.unixGenerator.forBlock['cut'] = window.unixGenerator.forBlock.generic;

public/blocks/mkdirBlock.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,34 @@
11
var mkdirBlock = {
22
type: 'mkdir',
3-
category: 'File and Directory Operations',
3+
category: 'Filesystem Operations',
44
unix_description: [
55
{
6-
parents: '-p',
7-
verbose: '-v'
6+
printName: true,
7+
parents: '-p'
88
}
99
],
1010
message0: '%{BKY_MKDIR_MESSAGE}',
11-
message1: '%{BKY_MKDIR_MULTIPLE_DIRECTORIES}',
12-
message2: '%{BKY_MKDIR_CREATE_SUBDIRECTORIES}',
13-
args2: [
11+
message1: '%{BKY_MKDIR_CREATE_SUBDIRECTORIES}',
12+
args1: [
1413
{
1514
type: 'field_checkbox',
1615
name: 'parents',
1716
checked: false // by default it's disabled
1817
}
1918
],
20-
message3: '%{BKY_MKDIR_LIST_DIRECTORIES}',
21-
args3: [
22-
{
23-
type: 'field_checkbox',
24-
name: 'verbose',
25-
checked: false // by default it's disabled
26-
}
27-
],
28-
29-
message4: '%{BKY_MKDIR_WRITE_DIRECTORY}',
30-
args4: [
19+
message2: '%{BKY_MKDIR_WRITE_DIRECTORY}',
20+
args2: [
3121
{
3222
type: 'field_input',
3323
name: 'directory',
3424
text: '............'
3525
}
3626
],
37-
38-
style: 'File and Directory Operations',
39-
previousStatement: 'Action',
27+
style: 'Filesystem Operations',
4028
nextStatement: 'Action',
4129
tooltip: '%{BKY_MKDIR_TOOLTIP}',
4230
helpUrl: '' // URL to further information or documentation.
4331
};
4432

4533
Blockly.defineBlocksWithJsonArray([mkdirBlock]);
34+
window.unixGenerator.forBlock['mkdir'] = window.unixGenerator.forBlock.generic;

public/blocks/regAnyOneBlock.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
var regAnyOneBlock = {
22
type: 'regAnyOne',
3+
category: 'Regular Expressions',
34
unix_description: [
45
{
5-
regPattern: '[patt]',
6-
notMatch: 'patt^'
6+
printName: false,
7+
Pattern: (fieldValues) => {
8+
const userInput = fieldValues['Pattern'] || '';
9+
return fieldValues['notMatch'] === 'TRUE'
10+
? '[^' + userInput + ']'
11+
: '[' + userInput + ']';
12+
}
713
}
814
],
9-
category: 'Regular Expressions',
10-
message0: '%{BKY_REGANYONE}',
15+
16+
message0: '%{BKY_REGANYONE} \n %{BKY_REGANYONE_NOT}',
1117
args0: [
1218
{
13-
type: 'input_value',
14-
name: 'regPattern',
15-
check: 'String'
16-
}
17-
],
18-
message1: '%{BKY_REGANYONE_NOT}',
19-
args1: [
19+
type: 'field_input',
20+
name: 'Pattern',
21+
text: 'String'
22+
},
2023
{
2124
type: 'field_checkbox',
2225
name: 'notMatch',
2326
checked: false
2427
}
2528
],
29+
2630
tooltip: '%{BKY_REGANYONE_TOOLTIP}',
27-
previousStatement: 'Action',
28-
nextStatement: 'Action',
31+
previousStatement: null,
32+
nextStatement: null,
2933
style: 'Regular Expressions',
30-
helpUrl: '%{BKY_REGANYONE_HELPURL}' // URL to further information or documentation.
34+
helpUrl: '%{BKY_REGANYONE_HELPURL}'
3135
};
3236

3337
Blockly.defineBlocksWithJsonArray([regAnyOneBlock]);
38+
window.unixGenerator.forBlock['regAnyOne'] =
39+
window.unixGenerator.forBlock.concat;

0 commit comments

Comments
 (0)