Skip to content

Commit 2f63219

Browse files
Merge pull request #21 from DhiWise/feature/build-overwrite
Overwrite the application in storage if the application has more than one build
2 parents 14026f2 + 9179f57 commit 2f63219

13 files changed

Lines changed: 155 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# [1.1.0](https://github.com/DhiWise/nodejs-code-generator/compare/v1.0.0...v1.1.0) (2022-01-11)
7+
8+
9+
### Bug Fixes
10+
11+
* **eslint formatting:** resolved eslint errors ([2c71bf2](https://github.com/DhiWise/nodejs-code-generator/commit/2c71bf2661c5e1599de3cb242b5431dce8720137))
12+
13+
14+
### Features
15+
16+
* add confirmation popup when second time build application ([a7fe3c0](https://github.com/DhiWise/nodejs-code-generator/commit/a7fe3c001fab1972a8f2f151feb6deb18220c3e5)), closes [#20](https://github.com/DhiWise/nodejs-code-generator/issues/20)

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"packages/*"
44
],
55
"npmClient": "npm",
6-
"version": "1.0.0",
6+
"version": "1.1.0",
77
"lerna": "4.0.0",
88
"command": {
99
"publish": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"release_patch": "lerna publish patch --conventional-commits && conventional-github-releaser --preset angular",
1616
"release_premajor": "lerna publish premajor --conventional-commits && conventional-github-releaser --preset angular",
1717
"release": "lerna publish --conventional-commits && conventional-github-releaser --preset angular",
18-
"lint": "eslint ."
18+
"lint": "eslint . --ext .js --fix"
1919
},
2020
"jest": {
2121
"modulePathIgnorePatterns": [

packages/client/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# [1.1.0](https://github.com/DhiWise/nodejs-code-generator/compare/v1.0.0...v1.1.0) (2022-01-11)
7+
8+
9+
### Features
10+
11+
* add confirmation popup when second time build application ([a7fe3c0](https://github.com/DhiWise/nodejs-code-generator/commit/a7fe3c001fab1972a8f2f151feb6deb18220c3e5)), closes [#20](https://github.com/DhiWise/nodejs-code-generator/issues/20)

packages/client/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nodejs-code-generator/client",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"private": true,
55
"dependencies": {
66
"@babel/parser": "^7.15.8",
@@ -34,6 +34,8 @@
3434
"prop-types": "^15.7.2",
3535
"rc-drawer": "^4.4.2",
3636
"react": "^17.0.2",
37+
"react-app-rewire-aliases": "^0.2.0",
38+
"react-app-rewired": "^2.1.8",
3739
"react-awesome-query-builder": "^4.7.0",
3840
"react-content-loader": "^6.0.3",
3941
"react-datepicker": "^4.2.1",
@@ -70,9 +72,7 @@
7072
"tailwindcss": "^2.2.17",
7173
"three": "^0.133.1",
7274
"use-onclickoutside": "^0.4.0",
73-
"web-vitals": "^1.1.2",
74-
"react-app-rewire-aliases": "^0.2.0",
75-
"react-app-rewired": "^2.1.8"
75+
"web-vitals": "^1.1.2"
7676
},
7777
"scripts": {
7878
"start": "npm run watch:css && react-app-rewired start",
@@ -101,6 +101,7 @@
101101
]
102102
},
103103
"devDependencies": {
104+
"@babel/eslint-parser": "^7.15.8",
104105
"@babel/plugin-proposal-class-properties": "^7.14.5",
105106
"@babel/plugin-transform-react-jsx": "^7.14.9",
106107
"eslint": "^7.32.0",
@@ -109,7 +110,6 @@
109110
"eslint-plugin-import": "^2.22.2",
110111
"eslint-plugin-jsx-a11y": "^6.4.1",
111112
"eslint-plugin-react": "^7.26.1",
112-
"eslint-plugin-react-hooks": "^4.2.0",
113-
"@babel/eslint-parser": "^7.15.8"
113+
"eslint-plugin-react-hooks": "^4.2.0"
114114
}
115-
}
115+
}

packages/client/src/container/Shared/BuildApp/BuildAppDropdown/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const BuildAppDropdown = () => {
119119
dispatch(setBuildCodeState({ buildArchitecture: val }));
120120
};
121121
const applicationId = useSelector((state) => state.projects.currentApplicationId);
122+
const [isBuild, setBuild, hideBuild] = useBoolean(false);
122123

123124
return (
124125
<>
@@ -166,6 +167,10 @@ export const BuildAppDropdown = () => {
166167
<Button
167168
loading={isBuildLoading}
168169
onClick={() => {
170+
if (generatedId) {
171+
setBuild();
172+
return;
173+
}
169174
dispatch(codeGenerator({ applicationId, projectType: architectureValue }));
170175
}}
171176
className="w-full"
@@ -177,6 +182,18 @@ export const BuildAppDropdown = () => {
177182

178183
</DropdownMenu>
179184
<BuildVSCodePopup />
185+
<ConfirmationAlert
186+
isOpen={isBuild}
187+
description="Building a new application will permanently delete your old build application."
188+
okText="Build app"
189+
variant="primary"
190+
handleSubmit={() => {
191+
hideBuild();
192+
dispatch(codeGenerator({ applicationId, projectType: architectureValue }));
193+
}}
194+
handleClose={hideBuild}
195+
/>
196+
180197
</>
181198
);
182199
};

packages/client/src/container/Shared/TechnologySetStep/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const TechnologySetStep = () => {
3636
} = useForm({ mode: 'onChange' });
3737
React.useEffect(() => {
3838
dispatch(resetBuildState());
39-
if (!location.state?.isNewApp) {
39+
if (!location.state?.isNewApp && applicationId) {
4040
redirectApplication(applicationId).then((response) => {
4141
dispatch(setBuildCodeState({
4242
buildArchitecture: response.data.projectType,

packages/server/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# [1.1.0](https://github.com/DhiWise/nodejs-code-generator/compare/v1.0.0...v1.1.0) (2022-01-11)
7+
8+
9+
### Bug Fixes
10+
11+
* **eslint formatting:** resolved eslint errors ([2c71bf2](https://github.com/DhiWise/nodejs-code-generator/commit/2c71bf2661c5e1599de3cb242b5431dce8720137))

packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nodejs-code-generator/server",
33
"private": true,
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"description": "",
66
"main": "handler.js",
77
"scripts": {

packages/server/usecase/application/generate.js

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* global _,appRootPath */
22
const fs = require('fs');
3+
const path = require('path');
4+
const fsExtra = require('fs-extra');
35
const mongoose = require('mongoose');
46
const os = require('os');
57
const { getAllDirFilesCount } = require('../../util-service/common');
@@ -41,13 +43,12 @@ const ProjectRoleAccessPermissions = new ProjectRoleAccessPermissionsRepo();
4143
const NestedQueryBuilder = new NestedQueryBuilderRepo();
4244

4345
const generateNodeCode = async (
44-
input, applicationRepo, definition, generatedId, dirPath, projectName, applicationId, generatorRepo,
46+
input, applicationRepo, definition, generatedId, dirPath, projectName, applicationId, generatorRepo, isReBuild,
4547
) => {
4648
try {
4749
const updatedApp = await applicationRepo.update(applicationId, { 'inProcessStatus.build_app': IN_PROCESS });
4850
await generatorRepo.update(generatedId, { 'inProcessStatus.build_app': IN_PROCESS });
49-
50-
await generator(input);
51+
await generator(input, isReBuild);
5152
// eslint-disable-next-line max-len
5253
const lastGeneratorRecord = await generatorRepo.getDetails({
5354
find: {
@@ -419,6 +420,46 @@ const nodeExpressRequest = async (applicationId, project, schemaRepo) => {
419420
};
420421
};
421422

423+
const getDirectoryAndFiles = (source) => {
424+
const directory = [];
425+
const files = [];
426+
fs.readdirSync(source).forEach((file) => {
427+
if (fs.lstatSync(path.resolve(source, file)).isDirectory()) {
428+
directory.push(file);
429+
} else {
430+
files.push(file);
431+
}
432+
});
433+
return {
434+
directory,
435+
files,
436+
};
437+
};
438+
439+
const overwriteProject = async (generatedId, projectName) => {
440+
await fsExtra.copy(`./output/${generatedId}/${projectName}/.env`, `./output/${generatedId}/${projectName}_dhiwise_temp_app/.env`);
441+
442+
const outputProjectDir = `./output/${generatedId}/${projectName}`;
443+
// fsExtra.emptyDirSync(directory);
444+
445+
const {
446+
directories, files,
447+
} = await getDirectoryAndFiles(outputProjectDir);
448+
449+
_.forEach(directories, (dirName) => {
450+
if (dirName !== 'node_modules') {
451+
fsExtra.emptyDirSync(`${outputProjectDir}/${dirName}`);
452+
}
453+
});
454+
455+
_.forEach(files, (fileName) => {
456+
fsExtra.remove(`${outputProjectDir}/${fileName}`);
457+
});
458+
459+
await fsExtra.copy(`./output/${generatedId}/${projectName}_dhiwise_temp_app`, `./output/${generatedId}/${projectName}`); // copies file
460+
await fsExtra.remove(`./output/${generatedId}/${projectName}_dhiwise_temp_app`);
461+
};
462+
422463
const generate = (applicationRepo, schemaRepo, generatorRepo) => async (params) => {
423464
try {
424465
if (!params.applicationId) {
@@ -447,6 +488,9 @@ const generate = (applicationRepo, schemaRepo, generatorRepo) => async (params)
447488
};
448489
}
449490

491+
let generated;
492+
let isReBuild = false;
493+
450494
const definition = {
451495
generatorPath: `${appRootPath}/output`,
452496
inputPath: `${appRootPath}/input`,
@@ -457,11 +501,35 @@ const generate = (applicationRepo, schemaRepo, generatorRepo) => async (params)
457501
config: definition,
458502
applicationId: params.applicationId,
459503
type: 1,
460-
status: 1,
504+
status: 2,
461505
versionNumber: '1',
462506
semanticVersionNumber: '1.0',
463507
};
464-
let generated = await generatorRepo.create(obj);
508+
509+
if (params.applicationId) {
510+
const query = {
511+
find: {
512+
applicationId: params.applicationId,
513+
isDeleted: false,
514+
config: definition,
515+
type: 1,
516+
status: 2,
517+
},
518+
sortBy: { _id: -1 },
519+
};
520+
521+
const generatedApps = await generatorRepo.getDetails(query);
522+
523+
if (generatedApps.length > 0) {
524+
// eslint-disable-next-line prefer-destructuring
525+
generated = generatedApps[0]; // latest App
526+
generated.id = generated._id;
527+
isReBuild = true;
528+
} else {
529+
obj.status = 1;
530+
generated = await generatorRepo.create(obj);
531+
}
532+
}
465533
if (!generated) {
466534
return GENERATOR_FAILED_CREATE;
467535
}
@@ -566,9 +634,12 @@ const generate = (applicationRepo, schemaRepo, generatorRepo) => async (params)
566634
await generatorRepo.update(generated.id, { 'inProcessStatus.build_app': IN_QUEUE });
567635

568636
const status = await generateNodeCode(
569-
inputFile, applicationRepo, definition, generated.id, dirPath, project.name, params.applicationId, generatorRepo,
637+
inputFile, applicationRepo, definition, generated.id, dirPath, project.name, params.applicationId, generatorRepo, isReBuild,
570638
);
571639
if (status) {
640+
if (isReBuild) {
641+
await overwriteProject(generated.id, jsonData.config.projectName);
642+
}
572643
return {
573644
...PROJECT_GENERATED,
574645
data: {
@@ -580,7 +651,7 @@ const generate = (applicationRepo, schemaRepo, generatorRepo) => async (params)
580651
}
581652
return SERVER_ERROR;
582653
} catch (err) {
583-
// console.log('error', err);
654+
console.log('error', err);
584655
return SERVER_ERROR;
585656
}
586657
};

0 commit comments

Comments
 (0)