[]( https://g.codefresh.io/repositories/codefresh-io/cf-com
npm install cf-compose-model
Codefresh introducing CF-Compose-Model, our model for all compositions.
Using our compose model you can:
* Verify that your composition is valid on Codefresh.io
* Convert Composition from one type to another
node example.js to run the basic examples we provided``javascript
'use strict';
const Promise = require('bluebird');
const path = require('path');
const CM = require('cf-compose-model');
const ComposeModel = CM.ComposeModel;
const path = './lib/model/tests/ComposeV1/ex1.yaml';
console.log(\n#############################\nExample load yaml from location ${locapathtion}\n#############################);
let location = path.resolve(__dirname, path);
return ComposeModel.load(location)
.then(compose => {
return compose.getWarnings();
})
.then((warnings) => {
console.log('\n===\nWarnings\n===');
return Promise.map(warnings, (warning) => {
console.log(warning.format());
});
})
.then(() => {
return cm.translate().toYaml();
})
.then((translated) => {
console.log('\n===\nOutput\n===');
console.log(translated);
});
``
OR
* clone this repo and npm isntall, yarn also supportedApi reference
Test
*
npm run unit_test
* npm run e2e_test using the flow.yaml
Road-map:
- [X] Support Compose V1
- [X] Support Compose V2
- [X] Support Compose V3
- [ ] CLI tool - started!
- [ ] ES5 moduleDocumantation
$3
ComposeModel holds inside 3 basic objects - each one of the objects holds in instances of CFNode class:
* services
* networks
* volumesMore objects that ComposeModel holds:
* originalYaml - the yaml file ComposeModel parsed. Optional
* parser - the original parser class that used to parse the yaml. Optional
* defaultTranslator - the translator that will be used if no other translator will be passed in
translate method. The defaultTranslator exist only if the ComposeModel parsed some yaml and a translator exist for it.
* policy - set of instructions that tell ComposeModel what are to possible warnings may each CFNode and CFLeaf have. The default value is the policy of the shared plan.
Methods of ComposeModel:
* static:
* parse(yaml) - Parse an yaml, search for a parser for the yaml file, parse it and return ComposeModel instance. Throw an error parser not found' if there is no parser.parse does.lib/model/policies.onlyAutoFix flag is set then only warnings with this flag will be fixed.