Skip to content

Commit e6aa642

Browse files
committed
nextjs functionality adapted for new project structure
1 parent dfc3074 commit e6aa642

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

app/src/components/left/ComponentPanel.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ import { makeStyles } from '@material-ui/core/styles';
1414

1515
const useStyles = makeStyles({
1616
inputField: {
17-
17+
marginTop: '15px'
1818
},
1919
inputWrapper: {
20-
height: '110px',
20+
height: '115px',
2121
textAlign: 'center',
2222
display: 'flex',
2323
justifyContent: 'center',
24-
paddingLeft: '35px'
24+
paddingLeft: '35px',
25+
marginBottom: '15px'
2526
},
2627
panelWrapper: {
27-
marginTop: '35px',
28-
width: '100%'
28+
width: '100%',
29+
marginTop: '15px',
2930
},
3031
panelWrapperList: {
3132
maxHeight: '675px',

app/src/containers/LeftContainer.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const LeftContainer = (): JSX.Element => {
5656
'Export components with application files',
5757
'Export project as Next.js application'
5858
];
59-
const [genOption, setGenOption] = useState(1);
59+
// const [genOption, setGenOption] = useState(1);
60+
let genOption = 0;
6061
// state to keep track of whether there should be a modal
6162
const [modal, setModal] = useState(null);
6263

@@ -116,20 +117,27 @@ const LeftContainer = (): JSX.Element => {
116117
))}
117118
</List>
118119
);
119-
const chooseAppDir = () => window.api.chooseAppDir();
120+
// const chooseAppDir = () => {
121+
// console.log('CALLED CHOOSE APP DIR: ', genOption);
122+
// window.api.chooseAppDir();
123+
// };
124+
120125
// helper function called by showGenerateAppModal
121126
// this function will prompt the user to choose an app directory once they've chosen their export option
122127
const chooseGenOptions = (genOpt: number) => {
123128
// set export option: 0 --> export only components, 1 --> export full project
124-
console.log('in chooseGenOptions');
125-
setGenOption(genOpt);
126-
console.log('Gen option is ', genOpt);
129+
130+
// setGenOption(genOpt);
131+
genOption = genOpt;
132+
console.log('CALLED CHOOSE GEN OPTION: ', genOption);
127133
// closeModal
128134
// exportProject('/Users', 'NEW PROJECT', genOpt, state.components, state.rootComponents);
129135
// closeModal();
130136
// Choose app dir
131137
// window.api.chooseAppDir;
132-
chooseAppDir();
138+
139+
window.api.chooseAppDir();
140+
133141
// closeModal
134142

135143
closeModal();
@@ -139,7 +147,7 @@ const LeftContainer = (): JSX.Element => {
139147
// when a directory is chosen, the callback will export the project to the chosen folder
140148
// Note: this listener is imported from the main process via preload.js
141149
window.api.appDirChosen(path => {
142-
console.log('App dir chosen : ', path);
150+
console.log('CALLED APPDIRCHOSEN: ', genOption);
143151
exportProject(path, 'NEW PROJECT', genOption, state.components, state.rootComponents);
144152
});
145153

app/src/helperFunctions/generateNextCode.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,14 @@ const generateUnformattedCode = (comps: Component[], componentId: number, rootCo
116116

117117
// formats code with prettier linter
118118
const formatCode = (code: string) => {
119-
return format(code, {
120-
singleQuote: true,
121-
trailingComma: 'es5',
122-
bracketSpacing: true,
123-
jsxBracketSameLine: true,
124-
parser: 'babel'
125-
});
119+
return window.api.formatCode(code);
120+
// return format(code, {
121+
// singleQuote: true,
122+
// trailingComma: 'es5',
123+
// bracketSpacing: true,
124+
// jsxBracketSameLine: true,
125+
// parser: 'babel'
126+
// });
126127
};
127128

128129
// generate code based on component heirarchy and then return the rendered code

app/src/utils/createNextApp.util.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'fs';
1+
// import fs from 'fs';
22
import createNextFiles from './createNextFiles.util';
33
import { Component } from '../interfaces/InterfacesNew';
44

@@ -47,7 +47,7 @@ export const createPackage = (path, appName) => {
4747
}
4848
}
4949
`;
50-
fs.writeFile(filePath, data, err => {
50+
window.api.writeFile(filePath, data, err => {
5151
if (err) {
5252
console.log('package.json error:', err.message);
5353
} else {
@@ -59,7 +59,7 @@ export const createPackage = (path, appName) => {
5959
export const createTsConfig = (path, appName) => {
6060
const filePath = `${path}/${appName}/tsconfig.json`;
6161
//running 'next dev' will autopopulate this with default values
62-
fs.writeFile(filePath, '', err => {
62+
window.api.writeFile(filePath, '', err => {
6363
if (err) {
6464
console.log('TSConfig error:', err.message);
6565
} else {
@@ -84,7 +84,7 @@ export const createDefaultCSS = (path, appName, components) => {
8484
components.forEach(comp => {
8585
data += compToCSS(comp);
8686
})
87-
fs.writeFile(filePath, data, err => {
87+
window.api.writeFile(filePath, data, err => {
8888
if (err) {
8989
console.log('global.css error:', err.message);
9090
} else {
@@ -98,12 +98,12 @@ export const initFolders = (path:string, appName: string) => {
9898
let dirPages;
9999
let dirComponents;
100100
dir = `${dir}/${appName}`;
101-
if(!fs.existsSync(dir)){
102-
fs.mkdirSync(dir);
101+
if(!window.api.existsSync(dir)){
102+
window.api.mkdirSync(dir);
103103
dirPages = `${dir}/pages`;
104-
fs.mkdirSync(dirPages);
104+
window.api.mkdirSync(dirPages);
105105
dirComponents = `${dir}/components`;
106-
fs.mkdirSync(dirComponents);
106+
window.api.mkdirSync(dirComponents);
107107
}
108108
}
109109

@@ -125,7 +125,7 @@ export const createBaseTsx = (path, appName) => {
125125
126126
export default Base;
127127
`;
128-
fs.writeFile(filePath, data, err => {
128+
window.api.writeFile(filePath, data, err => {
129129
if (err) {
130130
console.log('_app.tsx error:', err.message);
131131
} else {

app/src/utils/createNextFiles.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const createNextFiles = (
3232
fileName = `${dir}/components/${component.name}.tsx`
3333
}
3434
const newPromise = new Promise((resolve, reject) => {
35-
fs.writeFileSync(
35+
window.api.writeFileSync(
3636
fileName,
3737
code,
3838
(err: any) => {

app/src/utils/exportProject.util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ const exportProject = (
1111
rootComponents: number[]
1212
) => {
1313
if (genOption === 1) {
14+
console.log('in exportProject, genOption 1')
1415
createApplicationUtil({ path, appName, components })
1516
.then(() => {
1617
console.log('CreateApplicationUtil has finished');
1718
})
1819
.catch(err => console.log(err));
1920
} else if (genOption === 0) {
21+
console.log('in exportProject, genOption 0')
2022
createFiles(components, path, appName, false);
2123
} else if (genOption === 2) {
24+
console.log('in exportProject, genOption 2')
2225
createNextApp({ path, appName, components, rootComponents})
2326
.then(() => {
2427
console.log('CreateNextApp has finished');

0 commit comments

Comments
 (0)