-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
301 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /usr/bin/env node | ||
|
||
const program = require('commander') | ||
const generate = require('../lib/generate/index') | ||
|
||
const action = (path) => { | ||
generate(path) | ||
} | ||
|
||
program | ||
.arguments('<path>') | ||
.action(action) | ||
|
||
program.on('--help', () => { | ||
console.log('<path> is the path you want to override in the generated folder.') | ||
console.log('') | ||
console.log(' Examples:') | ||
console.log('') | ||
console.log(' $ rc g reducers/my-path/my-reducer') | ||
console.log(' $ rc g components/MyComponent') | ||
console.log('') | ||
process.exit(0) | ||
}) | ||
|
||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
examples/test-expected/generate/custom/action-creators/unicorn/sumit-signup-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default (base, { actionTypeConstants, store }) => ( | ||
(event) => { | ||
const { } = store.get(); | ||
|
||
return { | ||
type: actionTypeConstants.unicorn.submitSignupForm, | ||
value: event.target.value, | ||
}; | ||
} | ||
); |
1 change: 1 addition & 0 deletions
1
examples/test-expected/generate/custom/action-type-constants/unicorn/change-email.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'UNICORN_CHANGE_EMAIL'; |
1 change: 1 addition & 0 deletions
1
examples/test-expected/generate/custom/action-type-constants/unicorn/sumit-signup-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'UNICORN_SUMIT_SIGNUP_FORM'; |
9 changes: 9 additions & 0 deletions
9
examples/test-expected/generate/custom/components/Unicorn.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default (Base) => { | ||
class Unicorn extends Base { | ||
compoenntWillMount() { | ||
|
||
} | ||
} | ||
|
||
return Unicorn; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import componentsUnicorn from './components/Unicorn'; | ||
import actionTypeConstantsUnicornChangeEmail from './action-type-constants/unicorn-change-email'; | ||
import actionTypeConstantsUnicornSumitSignupForm from './action-type-constants/unicorn/sumit-signup-form'; | ||
import actionCreatorsUnicornSumitSignupForm from './action-creators/unicorn/sumit-signup-form'; | ||
import reducersUnicornName from './reducers/unicorn/name'; | ||
|
||
export default { | ||
'components/Unicorn': componentsUnicorn, | ||
'action-type-constants/unicorn-change-email': actionTypeConstantsUnicornChangeEmail, | ||
'action-type-constants/unicorn/sumit-signup-form': actionTypeConstantsUnicornSumitSignupForm, | ||
'action-creators/unicorn/sumit-signup-form': actionCreatorsUnicornSumitSignupForm, | ||
'reducers/unicorn/name': reducersUnicornName, | ||
}; |
8 changes: 8 additions & 0 deletions
8
examples/test-expected/generate/custom/reducers/unicorn/name.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default (base, { actionTypeConstants }) => ( | ||
(state, action) => { | ||
switch (action.type) { | ||
default: | ||
return base(state, action); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export default { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
examples/test-expected/redux-integration/generated/reducers/redux-example/is-going.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
examples/test-expected/redux-integration/generated/reducers/redux-example/name.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const shell = require('shelljs'); | ||
|
||
module.exports = function actionCreators() { | ||
return `\ | ||
export default (base, { actionTypeConstants, store }) => ( | ||
(event) => { | ||
const { } = store.get(); | ||
return { | ||
type: actionTypeConstants.unicorn.submitSignupForm, | ||
value: event.target.value, | ||
}; | ||
} | ||
); | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const constCase = require('../helpers/const-case'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const shell = require('shelljs'); | ||
|
||
module.exports = function actionTypeConstants({ name, route }) { | ||
return `\ | ||
export default () => '${constCase(route, name)}'; | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const fs = require('fs'); | ||
|
||
module.exports = function components({ name }) { | ||
return `\ | ||
export default (Base) => { | ||
class ${name} extends Base { | ||
compoenntWillMount() { | ||
} | ||
} | ||
return ${name}; | ||
}; | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const modifyCustomIndex = require('./modify-custom-index'); | ||
const ensurePathExist = require('../helpers/ensure-path-exist'); | ||
const generators = { | ||
components: require('./components'), // eslint-disable-line global-require | ||
'action-type-constants': require('./action-type-constants'), // eslint-disable-line global-require | ||
'action-creators': require('./action-creators'), // eslint-disable-line global-require | ||
reducers: require('./reducers'), // eslint-disable-line global-require | ||
}; | ||
|
||
function contentForType ({ type, customFolder, name, route }) { | ||
switch (type) { | ||
case 'components': | ||
ensurePathExist(path.resolve(customFolder, 'components')); | ||
return { | ||
absPath: path.resolve(customFolder, `components/${name}.jsx`), | ||
content: generators[type]({ name, route }), | ||
}; | ||
case 'action-creators': | ||
case 'action-type-constants': | ||
case 'reducers': | ||
ensurePathExist(path.resolve(customFolder, `${type}/${route}`)); | ||
return { | ||
absPath: path.resolve(customFolder, `${type}/${route}/${name}.js`), | ||
content: generators[type]({ name, route }), | ||
}; | ||
default: | ||
throw new Error(`Type ${type} is not supported`); | ||
} | ||
} | ||
|
||
module.exports = function generate(rawPath, projectFolder = '.') { | ||
const customFolder = path.resolve(`${projectFolder}/custom`); | ||
const cleanPath = rawPath.replace(/\.(jsx|js)$/, ''); | ||
const segments = cleanPath.split('/'); | ||
|
||
const type = segments[0]; | ||
const hasRoute = segments.length > 2; | ||
const route = hasRoute && segments[1]; | ||
const name = segments[segments.length - 1]; | ||
|
||
const { absPath, content } = contentForType({ type, customFolder, name, route }); | ||
fs.writeFileSync(absPath, content); | ||
|
||
modifyCustomIndex(cleanPath); | ||
|
||
// generate an action-type-constant after we generate an action-creator | ||
if (type === 'action-creators') { | ||
generate( | ||
rawPath.replace('action-creators', 'action-type-constants'), | ||
projectFolder | ||
) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function modifyCustomIndex() { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const shell = require('shelljs'); | ||
|
||
module.exports = function reducers() { | ||
return `\ | ||
export default (base, { actionTypeConstants }) => ( | ||
(state, action) => { | ||
switch (action.type) { | ||
default: | ||
return base(state, action); | ||
} | ||
} | ||
); | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
const fs = require('fs'); | ||
const shell = require('shelljs'); | ||
|
||
module.exports = function ensurePathExist(outputPath) { | ||
let outputPathExists; | ||
function exist (outputPath) { | ||
try { | ||
outputPathExists = fs.statSync(outputPath).isDirectory(); | ||
return fs.statSync(outputPath).isDirectory(); | ||
} catch (e) { | ||
outputPathExists = false; | ||
return false; | ||
} | ||
} | ||
|
||
if (!outputPathExists) { | ||
module.exports = function ensurePathExist(outputPath) { | ||
if (!exist(outputPath)) { | ||
shell.mkdir('-p', outputPath); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
export default { | ||
'components/App': (self) => ( | ||
self | ||
), | ||
}; |
Oops, something went wrong.