Skip to content

Commit 1ada359

Browse files
authored
Feature Μerge core setup models (#316)
- Before this change there were 2 different models and parsers for the core and setup. The model was also JSOn structure. With this PR there is only one Parser and one model. Also the model is now a composite tree structure and has as value the JSON model.
1 parent 9482560 commit 1ada359

File tree

1,269 files changed

+44286
-21098
lines changed

Some content is hidden

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

1,269 files changed

+44286
-21098
lines changed

.github/workflows/ci.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CI Workflow
2+
3+
on:
4+
pull_request:
5+
branches: [feature-merge-core-setup-model]
6+
paths:
7+
- transpiler/**
8+
9+
jobs:
10+
test:
11+
name: Build and Test transpiler
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 10
14+
steps:
15+
- name: '☁️ checkout repository'
16+
uses: actions/checkout@v2
17+
18+
- name: '🔧 setup node'
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: 16
22+
23+
- name: Install Java
24+
uses: actions/setup-java@v3
25+
with:
26+
distribution: 'temurin'
27+
java-version: '17'
28+
29+
- name: Install Antlr
30+
run: |
31+
cd /usr/local/lib
32+
sudo curl -O https://www.antlr.org/download/antlr-4.10.1-complete.jar
33+
34+
- name: npm install
35+
working-directory: ./transpiler
36+
run: npm install
37+
38+
# - name: make antlr jar executable
39+
# run: chmod +x antlr-4.10.1-complete.jar
40+
41+
- name: 'Produce Antlr files'
42+
working-directory: ./transpiler
43+
run: npm run ant
44+
45+
- name: 'Build'
46+
working-directory: ./transpiler
47+
run: npm run build
48+
49+
- name: '🔍 run tests'
50+
working-directory: ./transpiler
51+
run: npm run test-silent

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"eslint.workingDirectories": ["transpiler", "cli"],
3+
"cSpell.words": ["Bitloops"],
4+
"javascript.preferences.importModuleSpecifierEnding": "js",
5+
"typescript.preferences.importModuleSpecifierEnding": "js"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Bitloops Language CLI
3+
* Copyright (C) 2022 Bitloops S.A.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* For further information you can contact legal(at)bitloops.com.
19+
*/
20+
// import { defineFeature, loadFeature } from 'jest-cucumber';
21+
// import path from 'path';
22+
// import {
23+
// getBitloopsModulesPreModelData,
24+
// TGetUseCasesResponse,
25+
// } from '../../src/parser/bitloopsFilesToString/index.js';
26+
27+
// const feature = loadFeature('./__tests__/parser/bitloopsFileToString.feature');
28+
29+
// defineFeature(feature, (test) => {
30+
// test.skip('Valid filepath produces valid string', ({ given, when, then }) => {
31+
// let filePath: string;
32+
// let result: {
33+
// miscFilesString: string;
34+
// useCases: TGetUseCasesResponse;
35+
// };
36+
// given(/^I am sending path (.*)$/, (modulePath: string) => {
37+
// if (modulePath.includes('ABSOLUTE_PATH')) {
38+
// filePath = modulePath.replaceAll('ABSOLUTE_PATH', process.cwd());
39+
// } else {
40+
// filePath = modulePath;
41+
// }
42+
// filePath = path.normalize(filePath);
43+
// });
44+
45+
// when('I call the function', () => {
46+
// result = getBitloopsModulesPreModelData(filePath);
47+
// });
48+
49+
// // TODO add useCases handling
50+
// then(/^I should get a string response not null (.*)$/, (response) => {
51+
// const { miscFilesString } = result; //{, useCases}
52+
// const editedResult = miscFilesString
53+
// .replaceAll('`', '')
54+
// .replaceAll('${', '{')
55+
// .replaceAll('\t', '')
56+
// .replaceAll('\n', ' ')
57+
// .replaceAll(' ', '')
58+
// .replaceAll(' ', '')
59+
// .trim();
60+
// expect(editedResult).toEqual(response);
61+
// });
62+
// });
63+
// });
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Bitloops Language CLI
3+
* Copyright (C) 2022 Bitloops S.A.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* For further information you can contact legal(at)bitloops.com.
19+
*/
20+
21+
// import { defineFeature, loadFeature } from 'jest-cucumber';
22+
// import {
23+
// TBitloopsClassesResult,
24+
// getClassesBLStrings,
25+
// } from '../../src/parser/getClassesBLStrings.js';
26+
27+
// const feature = loadFeature('./__tests__/parser/getClassesBLStrings.feature');
28+
29+
// defineFeature(feature, (test) => {
30+
// test('Empty string sent', ({ given, when, then }) => {
31+
// let result: TBitloopsClassesResult;
32+
// // eslint-disable-next-line @typescript-eslint/no-empty-function
33+
// given('I am sending an empty string', () => {});
34+
35+
// when('I call the function', () => {
36+
// result = getClassesBLStrings('');
37+
// });
38+
39+
// then('I should get an empty array "[]"', () => {
40+
// expect(result).toEqual([]);
41+
// });
42+
// });
43+
44+
// test('No classes found in string', ({ given, when, then }) => {
45+
// let result: TBitloopsClassesResult;
46+
// let wholeString = '';
47+
// given(/^I am sending a string (.*) that doesn't contain any Bitloops classes$/, (string) => {
48+
// wholeString = string;
49+
// });
50+
51+
// when('I call the function', () => {
52+
// result = getClassesBLStrings(wholeString);
53+
// });
54+
55+
// then('I should get an empty array "[]"', () => {
56+
// expect(result).toEqual([]);
57+
// });
58+
// });
59+
60+
// test('Class found in string', ({ given, when, then }) => {
61+
// let result: TBitloopsClassesResult;
62+
// let wholeString: { input: string; output: string };
63+
// given(/^I am sending a string that contains one Bitloops class$/, (docString) => {
64+
// const docStringArray = JSON.parse(docString);
65+
// wholeString = { input: docStringArray[0], output: docStringArray[1] };
66+
// });
67+
68+
// when('I call the function', () => {
69+
// result = getClassesBLStrings(wholeString.input);
70+
// });
71+
72+
// then('I should get a populated array with the expected class', () => {
73+
// expect(result).toEqual(JSON.parse(wholeString.output));
74+
// });
75+
// });
76+
77+
// test('Multiple classes found in string', ({ given, when, then }) => {
78+
// let result: TBitloopsClassesResult;
79+
// let wholeString: { input: string; output: string };
80+
// given(/^I am sending a string that contains multiple Bitloops classes$/, (docString) => {
81+
// const docStringArray = JSON.parse(docString);
82+
// wholeString = { input: docStringArray[0], output: docStringArray[1] };
83+
// });
84+
85+
// when('I call the function', () => {
86+
// result = getClassesBLStrings(wholeString.input);
87+
// });
88+
89+
// then('I should get a populated array with the expected classes', () => {
90+
// expect(result).toEqual(JSON.parse(wholeString.output));
91+
// });
92+
// });
93+
// });

cli/jest.config.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ export default {
1313
},
1414
testRegex: '(/__tests__/.*|(\\.|/)(test|spec|steps))\\.(m)?ts$',
1515
coverageDirectory: 'coverage',
16-
collectCoverageFrom: [
17-
'src/**/*.ts',
18-
'src/**/*.mts',
19-
'!src/**/*.d.ts',
20-
'!src/**/*.d.mts',
21-
],
16+
collectCoverageFrom: ['src/**/*.ts', 'src/**/*.mts', '!src/**/*.d.ts', '!src/**/*.d.mts'],
2217
setupFilesAfterEnv: ['jest-extended/all'],
2318
transform: {},
2419
// "extensionsToTreatAsEsm": [".ts"]

cli/src/commands/transpile.ts

+7-17
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ import ora, { Ora } from 'ora';
2323

2424
import { copyrightSnippet } from './copyright.js';
2525
import { TBoundedContextName, TModuleName } from '../types.js';
26-
import {
27-
generateBitloopsModel,
28-
generateSetupDataModel,
29-
generateTargetFiles,
30-
getBoundedContextModules,
31-
} from '../functions/index.js';
32-
import { SupportedLanguages } from '../helpers/supportedLanguages.js';
26+
import { getBoundedContextModules } from '../functions/index.js';
3327
import { clearFolder } from '../helpers/fileOperations.js';
3428
import { purpleColor, stopSpinner, greenColor, TAB, redColor } from '../utils/oraUtils.js';
3529
import {
@@ -38,6 +32,8 @@ import {
3832
printError,
3933
} from '../utils/inquirer.js';
4034
import { Question } from 'inquirer';
35+
import { transpileCode } from '../functions/transpile.js';
36+
import { writeTranspiledCode } from '../functions/generateTargetFiles.js';
4137

4238
interface ICollection {
4339
targetLanguage: string;
@@ -111,28 +107,22 @@ const transpile = async (source: ICollection): Promise<void> => {
111107
clearFolder(targetDirPath);
112108

113109
throbber = ora(purpleColor('🔨 Transpiling... ')).start();
114-
const setupData = generateSetupDataModel(sourceDirPath);
115110

116-
const bitloopsModel = generateBitloopsModel(boundedContextModules, sourceDirPath, setupData);
111+
const transpiledCode = transpileCode(boundedContextModules, sourceDirPath);
117112

118113
stopSpinner(throbber, greenColor('Transpiled'), '🔨');
119114

120115
throbber = ora(purpleColor('🕒 Writing system files to disk...')).start();
121-
generateTargetFiles({
122-
boundedContextModules,
123-
sourceDirPath: sourceDirPath,
124-
outputDirPath: targetDirPath,
125-
bitloopsModel,
126-
setupData,
127-
targetLanguage: SupportedLanguages.TypeScript,
128-
});
116+
117+
writeTranspiledCode(transpiledCode, targetDirPath);
129118

130119
stopSpinner(throbber, greenColor('System files written'), '⏰');
131120

132121
// console.log(greenColor('Project generated successfully!'));
133122

134123
console.log(greenColor(TAB + '🦎 Project generated successfully!\n'));
135124
} catch (err) {
125+
console.log(err);
136126
console.error(redColor(TAB + '❌ ' + err));
137127
throbber.stop();
138128
}

cli/src/functions/generateBitloopsModel.ts

-52
This file was deleted.

cli/src/functions/generateSetupModel.ts

+9-25
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,19 @@
1818
* For further information you can contact legal(at)bitloops.com.
1919
*/
2020
import { readFromFile } from '../helpers/fileOperations.js';
21-
import { ISetupData } from '../types.js';
22-
import {
23-
BitloopsIntermediateSetupASTParser,
24-
BitloopsLanguageSetupAST,
25-
BitloopsSetupParser,
26-
BitloopsSetupParserError,
27-
} from '@bitloops/bl-transpiler';
21+
import { TParserInputData } from '@bitloops/bl-transpiler';
2822
import path from 'path';
2923
const SETUP_FILE_NAME = 'setup.bl';
3024

31-
const generateSetupDataModel = (sourceDirPath: string): ISetupData => {
25+
const readSetupData = (sourceDirPath: string): TParserInputData['setup'] => {
3226
// TODO handle possibly multiple setup files
3327
const setupFilePath = path.join(sourceDirPath, SETUP_FILE_NAME);
3428
const content = readFromFile(setupFilePath);
35-
// const setupData = main(content);
36-
const parser = new BitloopsSetupParser();
37-
const initialModelOutput = parser.parse(content);
38-
39-
const intermediateParser = new BitloopsIntermediateSetupASTParser();
40-
if (!(initialModelOutput instanceof BitloopsSetupParserError)) {
41-
const result = intermediateParser.parse(
42-
initialModelOutput as unknown as BitloopsLanguageSetupAST,
43-
);
44-
if (result instanceof BitloopsSetupParserError) {
45-
console.log(result);
46-
throw new Error('Error parsing setup file');
47-
}
48-
return result as ISetupData;
49-
}
50-
throw new Error('Error parsing setup file');
29+
return [
30+
{
31+
fileId: SETUP_FILE_NAME,
32+
fileContents: content,
33+
},
34+
];
5135
};
52-
export { generateSetupDataModel };
36+
export { readSetupData };

0 commit comments

Comments
 (0)