-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setup script * Change to array flags * Better approach to know the files affected * Replaceflag method refactor * Fix to change all occurrences not only the first one * Setup script split into different files * Custom cognito iam role name * Refactor
- Loading branch information
1 parent
de58397
commit 094edd2
Showing
7 changed files
with
183 additions
and
68 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 @@ | ||
const flags = [/myapp/g, /MyApp/g] | ||
const longNameFlags = [/My App/g] | ||
|
||
/* DIR PATHS */ | ||
const UIPath = 'packages/ui/' | ||
const APIPath = 'packages/api/' | ||
|
||
const packageJson = 'package.json' | ||
const yamlFile = 'serverless.yaml' | ||
const manifest = 'public/manifest.json' | ||
const index = 'public/index.html' | ||
|
||
module.exports = { | ||
flags, | ||
longNameFlags, | ||
UIPath, | ||
APIPath, | ||
packageJson, | ||
yamlFile, | ||
manifest, | ||
index, | ||
} |
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,17 @@ | ||
const npm = require('npm') | ||
const constants = require('./constants') | ||
|
||
const installUIDependencies = () => { | ||
npm.load(() => npm.commands.install(constants.UIPath, [])) | ||
} | ||
|
||
const installAPIDependencies = () => { | ||
npm.load(() => npm.commands.install(constants.APIPath, [])) | ||
} | ||
|
||
const installDependencies = async () => { | ||
installUIDependencies() | ||
installAPIDependencies() | ||
} | ||
|
||
module.exports = installDependencies |
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,47 @@ | ||
const replace = require('replace-in-file') | ||
const constants = require('./constants') | ||
|
||
const getUndescoredString = (string) => string.split(' ').join('_') | ||
const getLowerCaseString = (string) => string.toLowerCase() | ||
const getLowerCasedUnderscoredString = (string) => getUndescoredString(getLowerCaseString(string)) | ||
|
||
const replaceShortFlags = (shortName) => replace.sync({ | ||
files: [ | ||
constants.packageJson, | ||
`${constants.UIPath}${constants.packageJson}`, | ||
`${constants.APIPath}${constants.packageJson}`, | ||
`${constants.UIPath}${constants.manifest}`, | ||
constants.yamlFile, | ||
], | ||
from: constants.flags, | ||
to: getLowerCasedUnderscoredString(shortName), | ||
}) | ||
|
||
const replaceLongFlags = (appName) => replace.sync({ | ||
files: [ | ||
`${constants.UIPath}${constants.manifest}`, | ||
`${constants.UIPath}${constants.index}`, | ||
], | ||
from: constants.longNameFlags, | ||
to: appName, | ||
}) | ||
|
||
const replaceFlag = (appName, shortName) => { | ||
const changeShortName = replaceShortFlags(shortName) | ||
const changeAppName = replaceLongFlags(appName) | ||
|
||
const filesChanged = [...changeShortName, ...changeAppName.filter((change) => { | ||
const shortNameFile = changeShortName.find((ch) => ch.file === change.file) | ||
/* conditional to get unique files */ | ||
if (shortNameFile) { | ||
return change.hasChanged !== shortNameFile.hasChanged && change.hasChanged | ||
} | ||
|
||
return change | ||
})] | ||
|
||
const filesCount = filesChanged.filter((r) => r.hasChanged).length | ||
console.info(`${filesCount} files changed!`) | ||
} | ||
|
||
module.exports = replaceFlag |
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,12 @@ | ||
const replaceFlags = require('./replaceFlags') | ||
const installDependencies = require('./installDependencies') | ||
|
||
const main = () => { | ||
const appName = process.env.npm_config_appName | ||
const shortName = process.env.npm_config_shortName || appName | ||
|
||
replaceFlags(appName, shortName) | ||
installDependencies() | ||
} | ||
|
||
main() |
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