writing()

in generators/guestbinary/index.js [90:188]


    writing() {

            var appPackagePath = this.isAddNewService ? this.projName : path.join(this.projName, this.projName);
            var servicePkgName = this.props.serviceName + 'Pkg';
            var serviceTypeName = this.props.serviceName + 'Type';
            var serviceName = this.props.serviceName;
            var appTypeName = this.projName + 'Type';
            var instanceCount = this.props.instanceCount;

                if (this.isAddNewService) {
                var fs = require('fs');
                var xml2js = require('xml2js');
                var parser = new xml2js.Parser();

                fs.readFile(path.join(appPackagePath, 'ApplicationManifest.xml'), function(err, data) {
                    parser.parseString(data, function (err, result) {
                        if (err) {
                            return console.log(err);
                        }
                        result['ApplicationManifest']['ServiceManifestImport'][result['ApplicationManifest']['ServiceManifestImport'].length] =
                            {"ServiceManifestRef":[{"$":{"ServiceManifestName":servicePkgName, "ServiceManifestVersion":"1.0.0"}}]}
                        result['ApplicationManifest']['DefaultServices'][0]['Service'][result['ApplicationManifest']['DefaultServices'][0]['Service'].length] =
                            {"$":{"Name":serviceName},"StatelessService":[{"$":{"ServiceTypeName":serviceTypeName,"InstanceCount":instanceCount},"SingletonPartition":[""]}]};
                        var builder = new xml2js.Builder();
                        var xml = builder.buildObject(result);
                        fs.writeFile(path.join(appPackagePath, 'ApplicationManifest.xml'), xml, function(err) {
                            if(err) {
                                return console.log(err);
                            }
                        });
                    });
                });

            } else { 
                this.fs.copyTpl(  this.templatePath('ApplicationManifest.xml'),
                    this.destinationPath(path.join(appPackagePath, '/ApplicationManifest.xml')),
                    {
                        appTypeName: appTypeName,
                        serviceName: serviceName,
                        serviceTypeName: serviceTypeName,
                        servicePkgName: servicePkgName,
                        instanceCount: instanceCount
                    }
                ); 
            }
            var servicePkg = this.props.serviceName + 'Pkg';
            var serviceTypeName = this.props.serviceName + 'Type';
            var appTypeName = this.projName + 'Type';
            var pkgDir = this.isAddNewService == false ? path.join(this.projName, this.projName) : this.projName;
            var is_Windows = (process.platform == 'win32');
            var sdkScriptExtension;
            if (is_Windows)
            {
                sdkScriptExtension = '.ps1';
            }
            else {
                sdkScriptExtension = '.sh';
            }

            this.fs.copyTpl(  this.templatePath('Service/ServiceManifest.xml'),
                this.destinationPath(path.join(pkgDir, servicePkg, '/ServiceManifest.xml')),
                {
                    serviceTypeName: serviceTypeName,
                    servicePkgName: servicePkg,
                    guestBinaryRelativePath: this.props.guestBinaryRelativePath,
                    guestBinaryParameters: this.props.guestBinaryParameters             
                }
            ); 

            this.fs.copyTpl(  this.templatePath('Service/Settings.xml'),
                this.destinationPath(path.join(pkgDir, servicePkg , '/config/Settings.xml')));

            this.fs.copy(this.props.guestBinarySourceFolder + '/**/*' ,
                this.destinationPath(path.join(pkgDir, servicePkg , '/code/')),
                { globOptions: { dot: true } }
            );
            if (!this.isAddNewService) {
                this.fs.copyTpl(
                    this.templatePath('deploy/install'+sdkScriptExtension),
                    this.destinationPath(path.join(this.projName, 'install'+sdkScriptExtension)),
                    {
                        appPackage: this.projName,
                        appName: this.projName,
                        appTypeName: appTypeName
                    } 
                );

                this.fs.copyTpl(
                    this.templatePath('deploy/uninstall'+sdkScriptExtension),
                    this.destinationPath(path.join(this.projName, 'uninstall'+sdkScriptExtension)),
                    {
                        appPackage: this.projName,
                        appName: this.projName,
                        appTypeName: appTypeName
                    }
                );
            }

    } // writing()