-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
960d79a
commit a379782
Showing
5 changed files
with
128 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ActionConfig, NodePlopAPI } from 'plop' | ||
import globby from 'globby' | ||
import fse from 'fs-extra' | ||
import replaceInFiles from 'replace-in-files' | ||
|
||
export const copyFiles = async (answers: object, config: ActionConfig, plop: NodePlopAPI) => { | ||
const configData = config.data as any | ||
|
||
const allFiles = await globby([configData.source], { | ||
gitignore: true, | ||
dot: true | ||
}) | ||
for (let fileName of allFiles) { | ||
const destFileName = fileName.replace(configData.source, configData.dest) | ||
console.log(`- ${destFileName}`) | ||
await fse.copy(fileName, destFileName) | ||
} | ||
|
||
for (let key in configData.replaceInFiles) { | ||
await replaceInFiles({ | ||
files: [`${configData.dest}/**/*`, `${configData.dest}/*`], | ||
from: new RegExp(key, 'g'), | ||
to: configData.replaceInFiles[key] | ||
}) | ||
} | ||
|
||
return await Promise.resolve('success') | ||
} |
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,50 @@ | ||
import { NodePlopAPI } from 'plop' | ||
|
||
export const appGenerator = (plop: NodePlopAPI) => { | ||
const prompts = [ | ||
{ | ||
type: 'input', | ||
name: 'appName', | ||
message: 'App name' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'description', | ||
message: 'App description' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'port', | ||
message: 'Port for dev mode (ex: 3045, Check available ports)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'appPath', | ||
message: 'App path (ex: /my-app)' | ||
} | ||
] | ||
const actions = ({ appName, description, port, appPath }) => { | ||
return [ | ||
{ | ||
type: 'copy-files', | ||
data: { | ||
source: 'packages/app/template', | ||
dest: `packages/app/${appName}`, | ||
replaceInFiles: { | ||
'@outsrc/template': `@outsrc/${appName}`, | ||
'3010': port, | ||
'Frontend App Template': description, | ||
'/template': appPath, | ||
template: appName | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
return { | ||
description: 'App Generator', | ||
prompts, | ||
actions | ||
} | ||
} |
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,37 @@ | ||
import { NodePlopAPI } from 'plop' | ||
|
||
export const libGenerator = (plop: NodePlopAPI) => { | ||
const prompts = [ | ||
{ | ||
type: 'input', | ||
name: 'libName', | ||
message: 'Library name' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'description', | ||
message: 'Library description' | ||
} | ||
] | ||
const actions = ({ libName, description }) => { | ||
return [ | ||
{ | ||
type: 'copy-files', | ||
data: { | ||
source: 'packages/shared/functions', | ||
dest: `packages/shared/${libName}`, | ||
replaceInFiles: { | ||
'@outsrc/functions': `@outsrc/${libName}`, | ||
'Templated shared functions': description | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
return { | ||
description: 'Shared Module Generator', | ||
prompts, | ||
actions | ||
} | ||
} |
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,11 @@ | ||
import { appGenerator } from './app-generator' | ||
import { libGenerator } from './lib-generator' | ||
import { NodePlopAPI } from 'plop' | ||
import { copyFiles } from './actions' | ||
|
||
module.exports = function (plop: NodePlopAPI) { | ||
plop.setActionType('copy-files', copyFiles) | ||
|
||
plop.setGenerator('app', appGenerator(plop)) | ||
plop.setGenerator('lib', libGenerator(plop)) | ||
} |
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