Skip to content

Commit 3ca9841

Browse files
authored
Merge pull request #3 from oslabs-beta/feature/checkbox
Feature/checkbox
2 parents c4d5d14 + 18372cf commit 3ca9841

File tree

12 files changed

+754
-64
lines changed

12 files changed

+754
-64
lines changed

app/electron/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ app.on('ready', createWindow);
204204

205205
// Quit when all windows are closed.
206206
app.on('window-all-closed', () => {
207-
require('electron').app.getPath('userData');
208207
win.webContents.executeJavaScript('window.localStorage.clear();');
209208
app.quit();
210209
});

app/src/components/right/ExportButton.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,22 @@ export default function ExportButton() {
6060
<ListItemText primary={option} style={{ textAlign: 'center' }} />
6161
</ListItem>
6262
))}
63+
<ListItem>
64+
<input type="checkbox" id="tests" name="tests"></input>
65+
<label for="tests">Include Tests</label>
66+
</ListItem>
6367
</List>
6468
);
6569

70+
let testchecked = 0;
6671
// helper function called by showGenerateAppModal
6772
// this function will prompt the user to choose an app directory once they've chosen their export option
6873
const chooseGenOptions = (genOpt: number) => {
6974
// set export option: 0 --> export only components, 1 --> export full project
75+
7076
genOption = genOpt;
7177
window.api.chooseAppDir();
78+
testchecked = document.getElementById('tests').checked;
7279
closeModal();
7380
};
7481

@@ -86,6 +93,7 @@ export default function ExportButton() {
8693
? state.name
8794
: 'New_ReacType_Project_' + Math.ceil(Math.random() * 99).toString(),
8895
genOption,
96+
testchecked,
8997
state.projectType,
9098
state.components,
9199
state.rootComponents

app/src/helperFunctions/generateCode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const generateUnformattedCode = (
188188
.join('\n')
189189
: imports
190190
.map((comp: string) => {
191-
return `import ${comp} from './${comp}.tsx'`;
191+
return `import ${comp} from './${comp}'`;
192192
})
193193
.join('\n');
194194

@@ -206,7 +206,7 @@ const generateUnformattedCode = (
206206
${
207207
classBased
208208
? `class ${currentComponent.name} extends Component {`
209-
: `const ${currentComponent.name} = (props): JSX.Element => {`
209+
: `const ${currentComponent.name} = (props: any): JSX.Element => {`
210210
}
211211
212212
${
@@ -274,7 +274,7 @@ const generateUnformattedCode = (
274274
${links ? `import { Link } from 'gatsby'` : ``}
275275
276276
277-
const ${currentComponent.name} = (props): JSX.Element => {
277+
const ${currentComponent.name} = (props: any): JSX.Element => {
278278
279279
const [value, setValue] = useState<any | undefined>("INITIAL VALUE");
280280

app/src/utils/createApplication.util.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import createFiles from './createFiles.util';
44
import { Component} from '../interfaces/Interfaces';
55

6+
import createTestSuiteClassic from './createTestSuiteClassic.util'
7+
68
const camelToKebab= (camel:string) => {
79
return camel.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
810
};
@@ -108,8 +110,19 @@ export const createDefaultCSS = (path, appName, components) => {
108110
});
109111
};
110112

111-
export const createPackage = (path, appName) => {
113+
export const createPackage = (path, appName, test) => {
112114
const filePath = `${path}/${appName}/package.json`;
115+
let tsjest = `,
116+
"@types/enzyme": "^3.10.9",
117+
"@types/jest": "^27.0.1",
118+
"babel-jest": "^27.2.0",
119+
"enzyme": "^3.11.0",
120+
"enzyme-adapter-react-16": "^1.15.6",
121+
"jest": "^27.2.0",
122+
"@types/enzyme-adapter-react-16": "^1.0.6",
123+
"ts-jest": "^27.0.5",
124+
"enzyme-to-json": "^3.6.2"`;
125+
113126
const data = `
114127
{
115128
"name": "reactype",
@@ -119,7 +132,9 @@ export const createPackage = (path, appName) => {
119132
"scripts": {
120133
"start": "node server/server.js",
121134
"build": "cross-env NODE_ENV=production webpack",
122-
"dev": "cross-env NODE_ENV=development webpack-dev-server"
135+
"dev": "cross-env NODE_ENV=development webpack-dev-server"${
136+
test ? `,
137+
"test": "jest"`: '' }
123138
},
124139
"nodemonConfig": {
125140
"ignore": [
@@ -160,7 +175,8 @@ export const createPackage = (path, appName) => {
160175
"typescript": "^3.8.3",
161176
"webpack": "^4.29.6",
162177
"webpack-cli": "^3.3.0",
163-
"webpack-dev-server": "^3.2.1"
178+
"webpack-dev-server": "^3.2.1"${
179+
test ? tsjest : '' }
164180
}
165181
}
166182
`;
@@ -252,18 +268,20 @@ export const createBabel = (path, appName) => {
252268
export const createTsConfig = (path, appName) => {
253269
const filePath = `${path}/${appName}/tsconfig.json`;
254270
const data = `
255-
{
256-
"compilerOptions": {
257-
"outDir": "./dist/",
258-
"sourceMap": true,
259-
"noImplicitAny": true,
260-
"module": "commonjs",
261-
"target": "es6",
262-
"jsx": "react",
263-
"allowSyntheticDefaultImports": true
264-
},
265-
"include": ["./src/**/*"]
266-
}
271+
{
272+
"compilerOptions": {
273+
"outDir": "./dist/",
274+
"sourceMap": true,
275+
"noImplicitAny": true,
276+
"module": "commonjs",
277+
"target": "es6",
278+
"jsx": "react",
279+
"lib": ["dom", "es6"],
280+
"moduleResolution": "node",
281+
"esModuleInterop": true
282+
},
283+
"include": ["./src/**/*"]
284+
}
267285
`;
268286
window.api.writeFile(filePath, data, err => {
269287
if (err) {
@@ -340,22 +358,26 @@ app.listen(8080, () => {
340358
async function createApplicationUtil({
341359
path,
342360
appName,
343-
components
361+
components,
362+
testchecked,
344363
}: {
345364
path: string;
346365
appName: string;
347366
components: Component[];
367+
testchecked: boolean;
348368
}) {
349-
350369
await createIndexHtml(path, appName);
351370
await createIndexTsx(path, appName);
352371
await createDefaultCSS(path, appName, components);
353-
await createPackage(path, appName);
372+
await createPackage(path, appName, testchecked);
354373
await createWebpack(path, appName);
355374
await createBabel(path, appName);
356375
await createTsConfig(path, appName);
357376
await createTsLint(path, appName);
358377
await createServer(path, appName);
378+
if (testchecked) {
379+
await createTestSuiteClassic({path, appName, components, testchecked});
380+
}
359381
await createFiles(components, path, appName, true);
360382
}
361383
export default createApplicationUtil;

app/src/utils/createGatsbyApp.util.ts

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Create all files necessary to run a gatsby.js application
22

33
import createGatsbyFiles from './createGatsbyFiles.util';
4+
import createTestSuite from './createTestSuite.util';
45
import { Component } from '../interfaces/Interfaces';
56

67
const camelToKebab= (camel:string) => {
@@ -24,30 +25,48 @@ const compToCSS = (component: Component) => {
2425
}
2526

2627
//createPackage
27-
export const createPackage = (path, appName) => {
28+
export const createPackage = (path, appName, test) => {
2829
const filePath = `${path}/${appName}/package.json`;
30+
31+
let tsjest = `,
32+
"@types/enzyme": "^3.10.9",
33+
"@types/jest": "^27.0.1",
34+
"babel-jest": "^27.2.0",
35+
"enzyme": "^3.11.0",
36+
"enzyme-adapter-react-16": "^1.15.6",
37+
"jest": "^27.2.0",
38+
"@types/react-dom": "^17.0.9",
39+
"@types/enzyme-adapter-react-16": "^1.0.6",
40+
"@types/react-test-renderer": "^17.0.1",
41+
"babel-preset-gatsby": "^1.13.0",
42+
"identity-obj-proxy": "^3.0.0",
43+
"ts-jest": "^27.0.5"`;
44+
2945
const data = `
30-
{
31-
"name": "reactype-gatsby",
32-
"version": "1.0.0",
33-
"description": "",
34-
"scripts": {
35-
"dev": "gatsby develop",
36-
"build": "gatsby build",
37-
"start": "npm run dev"
38-
},
39-
"dependencies": {
40-
"gatsby": "^2.26.1",
41-
"react": "16.13.1",
42-
"react-dom": "16.13.1"
43-
},
44-
"devDependencies": {
45-
"@types/node": "^14.0.20",
46-
"@types/react": "^16.9.41",
47-
"typescript": "^3.9.6"
48-
}
49-
}
50-
`;
46+
{
47+
"name": "reactype-gatsby",
48+
"version": "1.0.0",
49+
"description": "",
50+
"scripts": {
51+
"dev": "gatsby develop",
52+
"build": "gatsby build",
53+
"start": "npm run dev"${
54+
test ? `,
55+
"test": "jest"`: '' }
56+
},
57+
"dependencies": {
58+
"gatsby": "^2.26.1",
59+
"react": "16.13.1",
60+
"react-dom": "16.13.1"
61+
},
62+
"devDependencies": {
63+
"@types/node": "^14.0.20",
64+
"@types/react": "^16.9.41",
65+
"typescript": "^3.9.6"${
66+
test ? tsjest : '' }
67+
}
68+
}
69+
`;
5170
window.api.writeFile(filePath, data, err => {
5271
if (err) {
5372
console.log('package.json error:', err.message);
@@ -58,9 +77,24 @@ export const createPackage = (path, appName) => {
5877
};
5978
//createTSConfig (empty)
6079
export const createTsConfig = (path, appName) => {
61-
const filePath = `${path}/${appName}/tsconfig.json`;
80+
const filePath:string = `${path}/${appName}/tsconfig.json`;
6281
//running 'gatsby dev' will autopopulate this with default values
63-
window.api.writeFile(filePath, '', err => {
82+
const data:string = `{
83+
"compilerOptions": {
84+
"outDir": "./dist/",
85+
"sourceMap": true,
86+
"noImplicitAny": true,
87+
"module": "commonjs",
88+
"target": "esnext",
89+
"jsx": "react",
90+
"lib": ["dom", "esnext"],
91+
"moduleResolution": "node",
92+
"esModuleInterop": true
93+
},
94+
"include": ["./src/**/*"]
95+
}
96+
`;
97+
window.api.writeFile(filePath, data, err => {
6498
if (err) {
6599
console.log('TSConfig error:', err.message);
66100
} else {
@@ -110,7 +144,7 @@ export const initFolders = (path:string, appName: string) => {
110144
};
111145

112146
//createBaseTsx
113-
export const createBaseTsx = (path, appName) => {
147+
export const createBaseTsx = (path: string, appName: string) => {
114148

115149
const filePath:string = `${path}/${appName}/src/pages/_app.tsx`;
116150
const data:string = `
@@ -140,18 +174,23 @@ async function createGatsbyAppUtil({
140174
path,
141175
appName,
142176
components,
143-
rootComponents
177+
rootComponents,
178+
testchecked,
144179
}: {
145180
path: string;
146181
appName: string;
147182
components: Component[];
148183
rootComponents: number[];
184+
testchecked: boolean;
149185
}) {
150186
await initFolders(path, appName);
151187
await createBaseTsx(path, appName);
152188
await createDefaultCSS(path, appName, components);
153-
await createPackage(path, appName);
189+
await createPackage(path, appName, testchecked);
154190
await createTsConfig(path, appName);
191+
if (testchecked) {
192+
await createTestSuite({path, appName, components, rootComponents, testchecked});
193+
}
155194
await createGatsbyFiles(components, path, appName, rootComponents);
156195
}
157196
export default createGatsbyAppUtil;

0 commit comments

Comments
 (0)