--- /dev/null
+var fs = require('fs');
+var util = require('util');
+var gulp = require('gulp');
+var xsd2json = require('xsd2json2').xsd2json;
+var mkdirp = require('mkdirp');
+var del = require('del');
+
+gulp.task('clean', function() {
+ del.sync(['./affectation.json',
+ './affectation-noAdditionalProperties.json',
+
+ './engagement.json',
+ './engagement-noAdditionalProperties.json',
+
+ './liquidation.json',
+ './liquidation-noAdditionalProperties.json',
+
+ './ng-schemas.js']);
+});
+
+// Generate the JSON schemas from the XSD definitions
+gulp.task('xsd2json', function(callback) {
+
+ // bug fix of xsd2json with complexType
+ var bugFix = function(o) {
+ for (var i in o) {
+ if (typeof o[i] === 'object') {
+ if (o[i].properties && o[i].properties.type === 'string') {
+ console.log('delete invalid type property for ' + i);
+ delete o[i].properties.type;
+ }
+ // recursive bugFix
+ bugFix(o[i]);
+ }
+ }
+ return o;
+ };
+
+ xsd2json('./publique/affectation.xsd', function(err, jsonSchema) {
+ if (err) return callback(err);
+ // Root element of schema should have type Visite
+ jsonSchema.$ref = '#/definitions/sformatspivotsadullactnetfinancepubliquev1:AffectationType';
+ jsonSchema = bugFix(jsonSchema);
+ fs.writeFile('./affectation.json', JSON.stringify(jsonSchema, null, 2), function(err){
+ xsd2json('./publique/liquidation.xsd', function(err, jsonSchema) {
+ if (err) return callback(err);
+ // Root element of schema should have type Visite
+ jsonSchema.$ref = '#/definitions/sformatspivotsadullactnetfinancepubliquev1:LiquidationType';
+ jsonSchema = bugFix(jsonSchema);
+ fs.writeFile('./liquidation.json', JSON.stringify(jsonSchema, null, 2), function(err){
+ xsd2json('./publique/engagement.xsd', function(err, jsonSchema) {
+ if (err) return callback(err);
+ // Root element of schema should have type Visite
+ jsonSchema.$ref = '#/definitions/sformatspivotsadullactnetfinancepubliquev1:EngagementType';
+ jsonSchema = bugFix(jsonSchema);
+ fs.writeFile('./engagement.json', JSON.stringify(jsonSchema, null, 2), callback);
+ });
+ });
+ });
+ });
+ });
+});
+
+var recursiveNoAddProp = function(o) {
+ for (var i in o) {
+ if (typeof o[i] === 'object') {
+ if (o[i].properties) {
+ o[i].patternProperties = { };
+ o[i].patternProperties["^_\\w+$"] = { "type": ["object", "string", "number", "array", "null", "boolean"]};
+ o[i].additionalProperties = false;
+ }
+ recursiveNoAddProp(o[i]);
+ }
+ }
+};
+
+gulp.task('noAddProp', function() {
+ var schema = JSON.parse(fs.readFileSync('./affectation.json', 'utf8'));
+ recursiveNoAddProp(schema);
+ fs.writeFileSync('./affectation-noAdditionalProperties.json', JSON.stringify(schema, null, 2));
+
+ schema = JSON.parse(fs.readFileSync('./liquidation.json', 'utf8'));
+ recursiveNoAddProp(schema);
+ fs.writeFileSync('./liquidation-noAdditionalProperties.json', JSON.stringify(schema, null, 2));
+
+ schema = JSON.parse(fs.readFileSync('./engagement.json', 'utf8'));
+ recursiveNoAddProp(schema);
+ fs.writeFileSync('./engagement-noAdditionalProperties.json', JSON.stringify(schema, null, 2));
+});
+
+// Generate an angular module with a constant that holds the JSON schema
+gulp.task('ngConstant', function(callback) {
+ var angularModule = util.format(
+ 'angular.module("connecteur-finance.contract", [])\n.constant("CONNECTEUR_FINANCE_SCHEMA", %s);',
+ fs.readFileSync('./engagement.json', 'utf8')
+ );
+ fs.writeFile('./ng-schemas.js', angularModule, callback);
+});
\ No newline at end of file