References Compiler
Compiler for YAML, JSON and INI files using path references
Install
# npm # global $ npm install -g refs-compiler # dev dependency $ npm install refs-compiler --save-dev # Yarn # global $ yarn global add refs-compiler # dev dependency $ yarn add refs-compiler -D
Example: YAML
Template(s)
AWSTemplateFormatVersion: '2010-09-09' Resources: - $ref: ./relative/path/to/file.yaml
RolePolicies: $ref: ./resources/role-policies.yaml
Type: 'AWS::IAM::Policy'Properties: PolicyName: custom-role Roles: - custom-role PolicyDocument: Version: '2012-10-17' Statement: - Sid: PassRole Effect: Allow Resource: - 'Fn::Join': - "" - - 'arn:aws:iam::' - Ref: 'AWS::AccountId' - ':role/*' Action: - 'iam:PassRole'
Code
// CommonJSconst path = ;const default: compiler = ;// ES6;; const inputTemplate = path;const outputFile = path; try ; catch e console; console;
CLI
$ refs-compiler -o ./build/output.yaml ./templates/template.yaml
Output
AWSTemplateFormatVersion: '2010-09-09'Resources: - RolePolicies: Type: 'AWS::IAM::Policy' Properties: PolicyName: custom-role Roles: - custom-role PolicyDocument: Version: '2012-10-17' Statement: - Sid: PassRole Effect: Allow Resource: - 'Fn::Join': - '' - - 'arn:aws:iam::' - Ref: 'AWS::AccountId' - ':role/*' Action: - 'iam:PassRole'
Acknowledgement
The base code was borrowed from doublenot/refs and then refactored / rewritten to support NodeJS 8+ using native Promises + async/await