-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 = { | ||
add: { test: 'test' }, | ||
}; |
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,7 @@ | ||
export class ConfigDto { | ||
remove: string[]; | ||
replace: Record<string, any>[]; | ||
add: Record<string, any>[]; | ||
replaceText: { text: string; replace: string }[]; | ||
customOperation: ((record: Record<string, any>) => Record<string, any>)[]; | ||
} |
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 * from './config.dto'; |
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,26 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { ConfigDto } from '../dto'; | ||
|
||
export const getConfigFromJSFile = (): ConfigDto | null => { | ||
const filePath = path.join(global._projectDir, 'repackify.js'); | ||
if (fs.existsSync(filePath)) { | ||
return require(filePath); | ||
} | ||
return null; | ||
}; | ||
|
||
export const getConfigFromRecord = ( | ||
record: Record<string, any>, | ||
): ConfigDto | null => { | ||
if (Object.keys(record).includes('repackify')) { | ||
return record['repackify']; | ||
} | ||
return null; | ||
}; | ||
|
||
export const getConfig = (record: Record<string, any>): ConfigDto | null => { | ||
const jsConfig = getConfigFromJSFile(); | ||
const packageJsonConfig = getConfigFromRecord(record); | ||
return { ...packageJsonConfig, ...jsConfig }; | ||
}; |
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 * from './get-config-object'; |
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,52 @@ | ||
import { filterPackageJson } from '../common/package-utils'; | ||
|
||
export const add = ( | ||
packProps: Record<string, any>, | ||
props: Record<string, any>, | ||
): Record<string, any> => { | ||
for (const key in props) { | ||
if (!(key in packProps)) { | ||
packProps[key] = props[key]; | ||
} | ||
} | ||
return filterPackageJson(packProps); | ||
}; | ||
|
||
export const remove = ( | ||
packProps: Record<string, any>, | ||
prop: string, | ||
): Record<string, any> => { | ||
if (prop in packProps) { | ||
delete packProps[prop]; | ||
} | ||
return packProps; | ||
}; | ||
|
||
export const replace = ( | ||
packProps: Record<string, any>, | ||
props: Record<string, any>, | ||
): Record<string, any> => { | ||
for (const key in props) { | ||
if (key in packProps) { | ||
packProps[key] = props[key]; | ||
} | ||
} | ||
return packProps; | ||
}; | ||
|
||
export const replaceText = ( | ||
packProps: Record<string, any>, | ||
text: string, | ||
replace: string, | ||
): Record<string, any> => { | ||
let resultString = JSON.stringify(packProps); | ||
resultString = resultString.replaceAll(text, replace); | ||
return JSON.parse(resultString); | ||
}; | ||
|
||
export const customOperation = ( | ||
packProps: Record<string, any>, | ||
operation: (packProps: Record<string, any>) => Record<string, any>, | ||
): Record<string, any> => { | ||
return operation(packProps); | ||
}; |
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,40 @@ | ||
import { ConfigDto } from '../common/dto'; | ||
import * as operations from './operations'; | ||
import { filterPackageJson } from '../common/package-utils'; | ||
|
||
export const operationsRunner = ( | ||
packProps: Record<string, any>, | ||
config: ConfigDto, | ||
): Record<string, any> => { | ||
if (config.add) { | ||
config.add.forEach((prop) => { | ||
packProps = operations.add(packProps, prop); | ||
}); | ||
} | ||
|
||
if (config.remove) { | ||
config.remove.forEach((prop) => { | ||
packProps = operations.remove(packProps, prop); | ||
}); | ||
} | ||
|
||
if (config.replace) { | ||
config.replace.forEach((prop) => { | ||
packProps = operations.replace(packProps, prop); | ||
}); | ||
} | ||
|
||
if (config.replaceText) { | ||
config.replaceText.forEach((prop) => { | ||
packProps = operations.replaceText(packProps, prop.text, prop.replace); | ||
}); | ||
} | ||
|
||
if (config.customOperation) { | ||
config.customOperation.forEach((customOperation) => { | ||
packProps = operations.customOperation(packProps, customOperation); | ||
}); | ||
} | ||
|
||
return filterPackageJson(packProps); | ||
}; |
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