Skip to content

Commit e49cebb

Browse files
Merge pull request #66 from React-Proto/bug/filepath
Removing hard coding of src folder.
2 parents b1955f8 + a88bc66 commit e49cebb

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/actions/components.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const handleTransform = (id, {
136136

137137
// Application generation options
138138
// cosnt genOptions = [
139-
// 'Export into existing project.', 'Export with create-react-app.', 'Export with starter repo'
139+
// 'Export into existing project.', 'Export with starter repo.', 'Export with create-react-app.'
140140
// ];
141141

142142
export const createApplication = ({
@@ -155,7 +155,7 @@ export const createApplication = ({
155155
dispatch({
156156
type: CREATE_APPLICATION_SUCCESS,
157157
});
158-
dispatch(exportFiles({ path: `${path}/${appName}/src`, components }));
158+
dispatch(exportFiles({ path: `${path}/${appName}`, components }));
159159
})
160160
.catch(err => dispatch({
161161
type: CREATE_APPLICATION_ERROR,

src/containers/MainContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MainContainer extends Component {
4444
repoUrl: '',
4545
image: '',
4646
modal: null,
47-
genOptions: ['Export into existing project.', 'Export with create-react-app.', 'Export with starter repo'],
47+
genOptions: ['Export into existing project.', 'Export with starter repo.', 'Export with create-react-app.'],
4848
genOption: 0,
4949
draggable: false,
5050
toggleClass: true,
@@ -172,7 +172,7 @@ class MainContainer extends Component {
172172
this.setState({ genOption });
173173
// closeModal
174174
this.closeModal();
175-
if (genOption === 2) {
175+
if (genOption === 1) {
176176
this.displayUrlModal();
177177
} else {
178178
// Choose app dir

src/reducers/componentReducer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ const initialApplicationState = {
6060
const componentReducer = (state = initialApplicationState, action) => {
6161
switch (action.type) {
6262
case LOAD_INIT_DATA:
63-
return { ...state, ...action.payload.data, loading: false };
63+
return {
64+
...state,
65+
...action.payload.data,
66+
loading: false,
67+
appDir: '',
68+
successOpen: false,
69+
errorOpen: false,
70+
};
6471
case ADD_COMPONENT:
6572
return addComponent(state, action.payload);
6673
case UPDATE_COMPONENT:

src/utils/createApplication.util.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ const execFile = util.promisify(require('child_process').execFile);
44

55
// Application generation options
66
// cosnt genOptions = [
7-
// 'Export into existing project.', 'Export with create-react-app.', 'Export with starter repo'
7+
// 'Export into existing project.', 'Export with starter repo', 'Export with create-react-app.'
88
// ];
99

1010
async function createApplicationUtil({
1111
path, appName, genOption, repoUrl,
1212
}) {
1313
if (genOption === 2) {
14-
return repoUrl ? execFile('git', ['clone', repoUrl, appName], { cwd: path }) : null;
14+
return [
15+
await execFile('npm', ['i', '-g', 'create-react-app'], { cwd: path }),
16+
await execFile('create-react-app', [appName], { cwd: path }),
17+
];
1518
}
16-
return [
17-
await execFile('npm', ['i', '-g', 'create-react-app']),
18-
await execFile('create-react-app', [appName], { cwd: path }),
19-
];
19+
return repoUrl ? execFile('git', ['clone', repoUrl, appName], { cwd: path }) : null;
2020
}
2121

2222
export default createApplicationUtil;

src/utils/createFiles.util.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import componentRender from './componentRender.util';
55
const createFiles = (data, path) => {
66
let dir = path;
77
if (!dir.match(/components|\*$/)) {
8+
if (fs.existsSync(`${dir}/src`)) {
9+
dir = `${dir}/src`;
10+
}
811
dir = `${dir}/components`;
912
if (!fs.existsSync(dir)) {
10-
fs.mkdir(dir, (err) => {
11-
if (err) console.error(err);
12-
});
13+
fs.mkdirSync(dir);
1314
}
1415
}
1516
const promises = [];

0 commit comments

Comments
 (0)