-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #482 from JoinColony/feature/extensions-versions
Introduce Extension Versioning
- Loading branch information
Showing
92 changed files
with
83,212 additions
and
6,736 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* - Get clients and versions | ||
* - Check if they exist | ||
* - Generate client for version | ||
*/ | ||
import { resolve as resolvePath } from 'path'; | ||
import { existsSync, mkdirSync, writeFileSync } from 'fs'; | ||
|
||
import { Extension } from '../src/clients/Extensions/colonyContractExtensions'; | ||
import { | ||
CurrentCoinMachineVersion, | ||
CurrentOneTxPaymentVersion, | ||
CurrentVotingReputationVersion, | ||
} from '../src/versions'; | ||
import getClientTemplate from './client-templates/extension-client-generator'; | ||
import getClientAddonTemplate from './client-templates/extension-client-addons-generator'; | ||
|
||
const extensionContracts = [ | ||
Extension.OneTxPayment, | ||
Extension.CoinMachine, | ||
Extension.VotingReputation, | ||
]; | ||
|
||
const currentExtensionsVersions = { | ||
[Extension.OneTxPayment]: CurrentOneTxPaymentVersion, | ||
[Extension.CoinMachine]: CurrentCoinMachineVersion, | ||
[Extension.VotingReputation]: CurrentVotingReputationVersion, | ||
}; | ||
|
||
const getExtensionVersionedPath = ( | ||
extensionName: Extension, | ||
extensionVersion: number, | ||
): string => | ||
resolvePath( | ||
__dirname, | ||
'../src/clients/Extensions', | ||
extensionName, | ||
String(extensionVersion), | ||
); | ||
|
||
const checkClientVersionExistance = ( | ||
extensionName: Extension, | ||
extensionVersion: number, | ||
): boolean => { | ||
const extensionPath = getExtensionVersionedPath( | ||
extensionName, | ||
extensionVersion, | ||
); | ||
return existsSync(`${extensionPath}/${extensionName}Client.ts`); | ||
}; | ||
|
||
const generateExtensionClient = async ( | ||
extensionName: Extension, | ||
extensionVersion: number, | ||
): Promise<void> => { | ||
const extensionPath = getExtensionVersionedPath( | ||
extensionName, | ||
extensionVersion, | ||
); | ||
const client = getClientTemplate(extensionName, extensionVersion); | ||
const addons = getClientAddonTemplate(extensionName, extensionVersion); | ||
|
||
mkdirSync(extensionPath, { recursive: true }); | ||
|
||
writeFileSync(`${extensionPath}/${extensionName}Client.ts`, client, { | ||
encoding: 'utf8', | ||
}); | ||
writeFileSync(`${extensionPath}/${extensionName}ClientAddons.ts`, addons, { | ||
encoding: 'utf8', | ||
}); | ||
}; | ||
|
||
const orchestrateBuild = async (): Promise<void> => { | ||
await Promise.all( | ||
extensionContracts.map(async (extensionContract) => { | ||
const extensionVersion = currentExtensionsVersions[extensionContract]; | ||
const clientExists = checkClientVersionExistance( | ||
extensionContract, | ||
extensionVersion, | ||
); | ||
|
||
if (!clientExists) { | ||
await generateExtensionClient(extensionContract, extensionVersion); | ||
} | ||
}), | ||
); | ||
}; | ||
|
||
orchestrateBuild(); |
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
Oops, something went wrong.