-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generate): added generate types for other components
- Loading branch information
Showing
6 changed files
with
87 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const replace = require('replace-in-file') | ||
const cwd = process.cwd() | ||
|
||
const dest = `${cwd}/src/models/` | ||
const src = path.resolve(__dirname, '..', '..', '..', 'files/model.js') | ||
const copy = require('../../../helper/copy') | ||
|
||
module.exports = (names, options) => { | ||
fs.ensureDir(dest).then(() => { | ||
const copyAction = [] | ||
names.forEach((name) => { | ||
copyAction.push(fs.copy(src, `${dest}${name}.js`)) | ||
}) | ||
return copyAction | ||
}).then(copyAction => Promise.all(copyAction).then(() => { | ||
const replaceAction = [] | ||
const type = 'model' | ||
const regex = /serviceName/g | ||
copy(names, type, regex).then(() => { | ||
console.log('\n') | ||
names.forEach(name => { | ||
replaceAction.push(replace({ | ||
files: `${dest}${name}.js`, | ||
from: /model_name/g, | ||
to: name | ||
})) | ||
}) | ||
return replaceAction | ||
}).catch(err => new Error(err)) | ||
.then(replaceAction => Promise.all(replaceAction).then(() => { | ||
})).catch(err => new Error(err))) | ||
.catch(err => { | ||
if (err instanceof Error) throw err | ||
else throw new Error(err) | ||
console.info(`New ${type} has been created as src/model/${name}.js`) | ||
}) | ||
console.log('\n') | ||
}).catch(err => { | ||
if (err instanceof Error) throw err | ||
else throw new Error(err) | ||
}) | ||
} |
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 copy = require('../../../helper/copy') | ||
|
||
module.exports = (names, options) => { | ||
const type = 'publisher' | ||
const regex = /serviceName/g | ||
copy(names, type, regex).then(() => { | ||
console.log('\n') | ||
names.forEach(name => { | ||
console.info(`New ${type} has been created as src/app/${name}.${type}.js`) | ||
}) | ||
console.log('\n') | ||
}).catch(err => { | ||
if (err instanceof Error) throw err | ||
else throw new Error(err) | ||
}) | ||
} |
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 copy = require('../../../helper/copy') | ||
|
||
module.exports = (names, options) => { | ||
const type = 'requester' | ||
const regex = /serviceName/g | ||
copy(names, type, regex).then(() => { | ||
console.log('\n') | ||
names.forEach(name => { | ||
console.info(`New ${type} has been created as src/app/${name}.${type}.js`) | ||
}) | ||
console.log('\n') | ||
}).catch(err => { | ||
if (err instanceof Error) throw err | ||
else throw new Error(err) | ||
}) | ||
} |
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 copy = require('../../../helper/copy') | ||
|
||
module.exports = (names, options) => { | ||
const type = 'responder' | ||
const regex = /serviceName/g | ||
copy(names, type, regex).then(() => { | ||
console.log('\n') | ||
names.forEach(name => { | ||
console.info(`New ${type} has been created as src/app/${name}.${type}.js`) | ||
}) | ||
console.log('\n') | ||
}).catch(err => { | ||
if (err instanceof Error) throw err | ||
else throw new Error(err) | ||
}) | ||
} |
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 copy = require('../../../helper/copy') | ||
|
||
module.exports = (names, options) => { | ||
const type = 'subscriber' | ||
const regex = /serviceName/g | ||
copy(names, type, regex).then(() => { | ||
console.log('\n') | ||
names.forEach(name => { | ||
console.info(`New ${type} has been created as src/app/${name}.${type}.js`) | ||
}) | ||
console.log('\n') | ||
}).catch(err => { | ||
if (err instanceof Error) throw err | ||
else throw new Error(err) | ||
}) | ||
} |