src/indexOld.js
function addVersion(machineName) {
        return co(function*() {
            debug("Adding a new version to the '" + machineName + "' machine");
            let manifest = getManifest();

            if (!manifest.machines[machineName]) {
                throw new Error("Machine does not exists");
            }

            let versions = manifest.machines[machineName].versions;
            let versionKeys = Object.keys(versions);
            let lastVersionKey = versionKeys[versionKeys.length - 1];
            let lastVersion = versions[lastVersionKey];
            let lastVersionInfoFile = lastVersion.route + "/info.json";
            let lastVersionInfo = jsonfile.readFileSync(repositoryPath + "/" + lastVersionInfoFile);
            let lastVersionModelFile = lastVersion.route + '/model.scxml';

            if(!lastVersionInfo.isSealed) {
                throw new Error("The last versions is not sealed yet");
            }

            let newVersionKey = "version" + (versionKeys.length + 1);
            let versionDirPath = manifest.machines[machineName].route + "/versions/" + newVersionKey;
            manifest.machines[machineName].versions[newVersionKey] = {
                "route": versionDirPath,
                "instances": {}
            };

            let versionInstancesDirPath = versionDirPath + "/instances";
            let modelFile = versionDirPath + '/model.scxml';
            let infoFile = versionDirPath + "/info.json";

            debug("Creating the directories");
            fs.mkdirSync(repositoryPath + "/" + versionDirPath);
            fs.mkdirSync(repositoryPath + "/" + versionInstancesDirPath);

            debug("Copying the previous version's model.scxml");
            fs.copySync(repositoryPath + "/" + lastVersionModelFile, repositoryPath + "/" + modelFile);

            debug("Creating the version info.json file");
            let infoVersion = { "isSealed": false };
            jsonfile.writeFileSync(repositoryPath + "/" + infoFile, infoVersion);

            debug("Setting the manifest");
            setManifest(manifest);
            yield _commit(null, ["manifest.json",  modelFile, infoFile],
                "Created the "+newVersionKey+" for the '" + machineName + "' machine");

            return newVersionKey;

        });

    }
function addVersion(machineName) {
        return co(function*() {
            debug("Adding a new version to the '" + machineName + "' machine");
            let manifest = getManifest();

            if (!manifest.machines[machineName]) {
                throw new Error("Machine does not exists");
            }

            let versions = manifest.machines[machineName].versions;
            let versionKeys = Object.keys(versions);
            let lastVersionKey = versionKeys[versionKeys.length - 1];
            let lastVersion = versions[lastVersionKey];
            let lastVersionInfoFile = lastVersion.route + "/info.json";
            let lastVersionInfo = jsonfile.readFileSync(repositoryPath + "/" + lastVersionInfoFile);
            let lastVersionModelFile = lastVersion.route + '/model.scxml';

            if(!lastVersionInfo.isSealed) {
                throw new Error("The last versions is not sealed yet");
            }

            let newVersionKey = "version" + (versionKeys.length + 1);
            let versionDirPath = manifest.machines[machineName].route + "/versions/" + newVersionKey;
            manifest.machines[machineName].versions[newVersionKey] = {
                "route": versionDirPath,
                "instances": {}
            };

            let versionInstancesDirPath = versionDirPath + "/instances";
            let modelFile = versionDirPath + '/model.scxml';
            let infoFile = versionDirPath + "/info.json";

            debug("Creating the directories");
            fs.mkdirSync(repositoryPath + "/" + versionDirPath);
            fs.mkdirSync(repositoryPath + "/" + versionInstancesDirPath);

            debug("Copying the previous version's model.scxml");
            fs.copySync(repositoryPath + "/" + lastVersionModelFile, repositoryPath + "/" + modelFile);

            debug("Creating the version info.json file");
            let infoVersion = { "isSealed": false };
            jsonfile.writeFileSync(repositoryPath + "/" + infoFile, infoVersion);

            debug("Setting the manifest");
            setManifest(manifest);
            yield _commit(null, ["manifest.json",  modelFile, infoFile],
                "Created the "+newVersionKey+" for the '" + machineName + "' machine");

            return newVersionKey;

        });

    }
function addVersion ( machineName ) { return co ( function * ( ) { debug ( "Adding a new version to the '" + machineName + "' machine" ) ; let manifest = getManifest ( ) ; if ( ! manifest . machines [ machineName ] ) { throw new Error ( "Machine does not exists" ) ; } let versions = manifest . machines [ machineName ] . versions ; let versionKeys = Object . keys ( versions ) ; let lastVersionKey = versionKeys [ versionKeys . length - 1 ] ; let lastVersion = versions [ lastVersionKey ] ; let lastVersionInfoFile = lastVersion . route + "/info.json" ; let lastVersionInfo = jsonfile . readFileSync ( repositoryPath + "/" + lastVersionInfoFile ) ; let lastVersionModelFile = lastVersion . route + '/model.scxml' ; if ( ! lastVersionInfo . isSealed ) { throw new Error ( "The last versions is not sealed yet" ) ; } let newVersionKey = "version" + ( versionKeys . length + 1 ) ; let versionDirPath = manifest . machines [ machineName ] . route + "/versions/" + newVersionKey ; manifest . machines [ machineName ] . versions [ newVersionKey ] = { "route" : versionDirPath , "instances" : { } } ; let versionInstancesDirPath = versionDirPath + "/instances" ; let modelFile = versionDirPath + '/model.scxml' ; let infoFile = versionDirPath + "/info.json" ; debug ( "Creating the directories" ) ; fs . mkdirSync ( repositoryPath + "/" + versionDirPath ) ; fs . mkdirSync ( repositoryPath + "/" + versionInstancesDirPath ) ; debug ( "Copying the previous version's model.scxml" ) ; fs . copySync ( repositoryPath + "/" + lastVersionModelFile , repositoryPath + "/" + modelFile ) ; debug ( "Creating the version info.json file" ) ; let infoVersion = { "isSealed" : false } ; jsonfile . writeFileSync ( repositoryPath + "/" + infoFile , infoVersion ) ; debug ( "Setting the manifest" ) ; setManifest ( manifest ) ; yield _commit ( null , [ "manifest.json" , modelFile , infoFile ] , "Created the " + newVersionKey + " for the '" + machineName + "' machine" ) ; return newVersionKey ; } ) ; }
Add a new version to a machine
@method addVersion
@param {String} machineName The name of the machine
@returns {Promise} The version key
Add a new version to a machine