Ejemplo n.º 1
0
function compileShader(exporter, platform, project, shader, to, temp, compiler, kfx) {
	let name = shader.name;
	if (name.endsWith('.inc')) return;
	switch (platform) {
		case Platform.Node: {
			Files.copy(shader.files[0], to.resolve(name + '.glsl'), true);
			addShader(project, name, '.glsl');
			exporter.addShader(name + '.glsl');
			break;
		}
		case Platform.Flash: {
			compileShader2(compiler, 'agal', shader.files[0], to.resolve(name + '.agal'), temp, platform, kfx);
			addShader(project, name, '.agal');
			exporter.addShader(name + '.agal');
			break;
		}
		case Platform.HTML5:
		case Platform.HTML5 + '-native':
		case Platform.DebugHTML5:
		case Platform.HTML5Worker:
		case Platform.Android:
		case Platform.Android + '-native':
		case Platform.Tizen:
		case Platform.iOS: {
			if (Options.graphicsApi === GraphicsApi.Metal) {
				if (!Files.isDirectory(to.resolve(Paths.get('..', 'ios-build', 'Sources')))) {
					Files.createDirectories(to.resolve(Paths.get('..', 'ios-build', 'Sources')));
				}
				var funcname = name;
				funcname = funcname.replaceAll('-', '_');
				funcname = funcname.replaceAll('.', '_');
				funcname += '_main';
				fs.writeFileSync(to.resolve(name + ".metal").toString(), funcname, { encoding: 'utf8' });
				compileShader2(compiler, "metal", shader.files[0], to.resolve(Paths.get('..', 'ios-build', 'Sources', name + ".metal")), temp, platform, kfx);
				addShader(project, name, ".metal");
			}
			else {
				var shaderpath = to.resolve(name + '.essl');
				compileShader2(compiler, "essl", shader.files[0], shaderpath, temp, platform, kfx);
				addShader(project, name, ".essl");
			}
			break;
		}
		case Platform.Windows: {
			if (Options.graphicsApi == GraphicsApi.OpenGL || Options.graphicsApi == GraphicsApi.OpenGL2) {
				compileShader2(compiler, "glsl", shader.files[0], to.resolve(name + ".glsl"), temp, platform, kfx);
				addShader(project, name, ".glsl");
			}
			else if (Options.graphicsApi === GraphicsApi.Direct3D11 || Options.graphicsApi === GraphicsApi.Direct3D12) {
				compileShader2(compiler, "d3d11", shader.files[0], to.resolve(name + ".d3d11"), temp, platform, kfx);
				addShader(project, name, ".d3d11");
			}
			else {
				compileShader2(compiler, "d3d9", shader.files[0], to.resolve(name + ".d3d9"), temp, platform, kfx);
				addShader(project, name, ".d3d9");
			}
			break;
		}
		case Platform.WindowsApp: {
			compileShader2(compiler, "d3d11", shader.files[0], to.resolve(name + ".d3d11"), temp, platform, kfx);
			addShader(project, name, ".d3d11");
			break;
		}
		case Platform.Xbox360:
		case Platform.PlayStation3: {
			compileShader2(compiler, "d3d9", shader.files[0], to.resolve(name + ".d3d9"), temp, platform, kfx);
			addShader(project, name, ".d3d9");
			break;
		}
		case Platform.Linux:
		case Platform.OSX: {
			compileShader2(compiler, "glsl", shader.files[0], to.resolve(name + ".glsl"), temp, platform, kfx);
			addShader(project, name, ".glsl");
			break;
		}
		case Platform.Unity: {
			compileShader2(compiler, "d3d9", shader.files[0], to.resolve(name + ".hlsl"), temp, platform, kfx);
			addShader(project, name, ".hlsl");
			break;
		}
		case Platform.WPF:
		case Platform.XNA:
		case Platform.Java:
		case Platform.PlayStationMobile:
			break;
		default: {
			var customCompiler = compiler;
			if (fs.existsSync(pathlib.join(from.toString(), 'Backends'))) {
				var libdirs = fs.readdirSync(pathlib.join(from.toString(), 'Backends'));
				for (var ld in libdirs) {
					var libdir = pathlib.join(from.toString(), 'Backends', libdirs[ld]);
					if (fs.statSync(libdir).isDirectory()) {
						var exe = pathlib.join(libdir, 'krafix', 'krafix-' + platform + '.exe');
						if (fs.existsSync(exe)) {
							customCompiler = exe;
						}
					}
				}
			}
			compileShader2(customCompiler, platform, shader.files[0], to.resolve(name + '.' + platform), temp, platform, kfx);
			addShader(project, name, '.' + platform);
			break;
		}
	}
}
Ejemplo n.º 2
0
var fs = require('fs-extra')
var debug = require('debug')('dactic')

var models = {}

fs.readdirSync(__dirname).filter(function (filename) { return filename.match('.js$') && (filename !== 'index.js') && (filename !== 'base.js') }).forEach(function (filename) {
  var name = filename.replace('.js', '')
  debug('Loading Models' + './' + name + ' from ' + filename)
  models[name] = require('./' + name)
})

module.exports = models
Ejemplo n.º 3
0
var searchInFolder = function (defer, path, web) {
	var coverFolder = '';
	var splitted = path.split('/');

	for (var k = 1; k < splitted.length; k++) {
		coverFolder = coverFolder + '/' + splitted[k];
	}

	if (fs.existsSync(coverFolder)) {
		logger.info("Searching in folder " + coverFolder);
		var stats = fs.statSync(coverFolder);

		if (stats.isFile()) {
			var fileSizeInBytes = stats["size"];
			if (fileSizeInBytes > 0) {
				defer.resolve(coverFolder);
				return defer.promise;
			}
			else {
				defer.reject(new Error('Filesize is zero'));
				return defer.promise;
			}
		}

		/**
		 * Trying to read albumart from file
		 */

		var covers = ['coverart.jpg', 'albumart.jpg', 'coverart.png', 'albumart.png',
			'cover.JPG' , 'Cover.JPG' , 'folder.JPG','Folder.JPG',
			'cover.PNG' , 'Cover.PNG' , 'folder.PNG','Folder.PNG',
			'cover.jpg', 'Cover.jpg', 'folder.jpg', 'Folder.jpg',
			'cover.png', 'Cover.png', 'folder.png', 'Folder.png'];
		splitted = path.split('/');


		for (var i in covers) {
			var coverFile = coverFolder + '/' + covers[i];
			//console.log("Searching for cover " + coverFile);
			if (fs.existsSync(coverFile)) {
                var cacheFile=mountAlbumartFolder+'/'+coverFolder+'/extralarge.jpeg';
                logger.info('Copying file to cache ['+cacheFile+']');
                fs.ensureFileSync(cacheFile);
                fs.copySync(coverFile,cacheFile);
				defer.resolve(cacheFile);
				return defer.promise;
			}
		}

		var files = fs.readdirSync(coverFolder);
		for (var j in files) {
			var fileName = S(files[j]);

			//console.log(fileName.s);
			if (fileName.endsWith('.png') || fileName.endsWith('.jpg') || fileName.endsWith('.JPG') || fileName.endsWith('.PNG')|| fileName.endsWith('.jpeg') || fileName.endsWith('.JPEG')) {
				defer.resolve(coverFolder + '/' + fileName.s);
				return defer.promise;
			}

		}
	} else {
		logger.info('Folder ' + coverFolder + ' does not exist');
	}
	searchOnline(defer, web);

};
Ejemplo n.º 4
0
  var handleDockerVersionTagAndPushToDockerImageRepo = function (versionTag) {
    var dockerConfig = baasilConfig.docker;
    var authParts = (new Buffer(dockerConfig.auth, 'base64')).toString('utf8').split(':');
    var username = authParts[0];
    var password = authParts[1];
    var dockerLoginCommand = `docker login -u ${username} -p ${password}`;

    var fullVersionTag;
    if (versionTag) {
      fullVersionTag = `:${versionTag}`;
    } else {
      fullVersionTag = parseVersionTag(dockerConfig.imageName);
    }
    dockerConfig.imageName = setImageVersionTag(dockerConfig.imageName, fullVersionTag);
    try {
      fs.writeFileSync(baasilConfigFilePath, JSON.stringify(baasilConfig, null, 2));

      execSync(`docker build -t ${dockerConfig.imageName} .`, {stdio: 'inherit'});
      execSync(`${dockerLoginCommand}; docker push ${dockerConfig.imageName}`, {stdio: 'inherit'});

      var kubernetesDirPath = appPath + '/kubernetes';

      var kubeConfSocketCluster = getSocketClusterDeploymentDefPath(kubernetesDirPath);
      var kubeConfContentSocketCluster = fs.readFileSync(kubeConfSocketCluster, {encoding: 'utf8'});

      var deploymentConfSocketCluster = YAML.parse(kubeConfContentSocketCluster);
      var configSocketCluster = baasilConfig.socketCluster || {};

      var containersSocketCluster = deploymentConfSocketCluster.spec.template.spec.containers;
      containersSocketCluster.forEach((value, index) => {
        if (value) {
          if (value.name == 'app-src-container') {
            containersSocketCluster[index].image = dockerConfig.imageName;
          } else if (value.name == 'socketcluster') {
            if (!containersSocketCluster[index].env) {
              containersSocketCluster[index].env = [];
            }
            containersSocketCluster[index].env = containersSocketCluster[index].env.filter((envObject) => {
              return envObject.name != 'SOCKETCLUSTER_WORKERS' && envObject.name != 'SOCKETCLUSTER_BROKERS';
            });
            containersSocketCluster[index].env.push({
              name: 'SOCKETCLUSTER_WORKERS',
              value: String(configSocketCluster.workers || defaultWorkerCount)
            });
            containersSocketCluster[index].env.push({
              name: 'SOCKETCLUSTER_BROKERS',
              value: String(configSocketCluster.brokers || defaultBrokerCount)
            });
          }
        }
      });

      var formattedYAMLStringSocketCluster = sanitizeYAML(YAML.stringify(deploymentConfSocketCluster, Infinity, 2));
      fs.writeFileSync(kubeConfSocketCluster, formattedYAMLStringSocketCluster);

      var kubeConfSCCBroker = getSCCBrokerDeploymentDefPath(kubernetesDirPath);
      var kubeConfContentSCCBroker = fs.readFileSync(kubeConfSCCBroker, {encoding: 'utf8'});

      var deploymentConfSCCBroker = YAML.parse(kubeConfContentSCCBroker);
      var configSCCBroker = baasilConfig.sccBroker || {};

      var containersSCCBroker = deploymentConfSCCBroker.spec.template.spec.containers;

      containersSCCBroker.forEach((value, index) => {
        if (value) {
          if (value.name == 'scc-broker') {
            if (!containersSCCBroker[index].env) {
              containersSCCBroker[index].env = [];
            }
            containersSCCBroker[index].env = containersSCCBroker[index].env.filter((envObject) => {
              return envObject.name != 'SOCKETCLUSTER_WORKERS' && envObject.name != 'SOCKETCLUSTER_BROKERS';
            });
            containersSCCBroker[index].env.push({
              name: 'SOCKETCLUSTER_WORKERS',
              value: String(configSCCBroker.workers || defaultWorkerCount)
            });
            containersSCCBroker[index].env.push({
              name: 'SOCKETCLUSTER_BROKERS',
              value: String(configSCCBroker.brokers || defaultBrokerCount)
            });
          }
        }
      });

      var formattedYAMLStringSCCBroker = sanitizeYAML(YAML.stringify(deploymentConfSCCBroker, Infinity, 2));
      fs.writeFileSync(kubeConfSCCBroker, formattedYAMLStringSCCBroker);

      var ingressKubeFileName = 'scc-ingress.yaml';
      var socketClusterDeploymentFileName = 'socketcluster-deployment.yaml';

      var deploySuccess = () => {
        successMessage(`The '${appName}' app was deployed successfully - You should be able to access it online ` +
        `once it has finished booting up. Check your Rancher control panel from http://baasil.io to track the boot progress and to find out which IP address(es) have been exposed to the internet.`);
        process.exit();
      };

      if (isUpdate) {
        try {
          execSync(`kubectl replace -f ${kubernetesDirPath}/${socketClusterDeploymentFileName}`, {stdio: 'inherit'});
        } catch (err) {}

        deploySuccess();
      } else {
        var kubeFiles = fs.readdirSync(kubernetesDirPath);
        var serviceAndDeploymentKubeFiles = kubeFiles.filter((configFilePath) => {
          return configFilePath != ingressKubeFileName;
        });
        var deploymentRegex = /\-deployment\.yaml/;
        var scalableDeploymentsKubeFiles = kubeFiles.filter((configFilePath) => {
          return deploymentRegex.test(configFilePath) && configFilePath != 'scc-state-deployment.yaml';
        });
        serviceAndDeploymentKubeFiles.forEach((configFilePath) => {
          var absolutePath = path.resolve(kubernetesDirPath, configFilePath);
          execSync(`kubectl create -f ${absolutePath}`, {stdio: 'inherit'});
        });

        if (doAutoScale) {
          scalableDeploymentsKubeFiles.forEach((configFilePath) => {
            var absolutePath = path.resolve(kubernetesDirPath, configFilePath);
            var hpaName = configFilePath.replace(deploymentYAMLRegex, '');
            try {
              execSync(`kubectl delete hpa ${hpaName}`, {stdio: 'ignore'});
            } catch (e) {}

            execSync(`kubectl autoscale -f ${absolutePath} --cpu-percent=${targetCPUUtilization} --max=${maxPodsPerService} --min=1`, {stdio: 'inherit'});
          });
        }

        // Wait a few seconds before deploying ingress (due to a bug in Rancher).
        setTimeout(() => {
          try {
            execSync(`kubectl create -f ${kubernetesDirPath}/${ingressKubeFileName}`, {stdio: 'inherit'});
            deploySuccess();
          } catch (err) {
            failedToDeploy(err);
          }
        }, 7000);
      }
    } catch (err) {
      failedToDeploy(err);
    }
  };
Ejemplo n.º 5
0
    };

    var handleUsername = function (username) {
      dockerUsername = username;
      promptInput('Enter your DockerHub password:', handlePassword, true);
    };
    promptInput('Enter your DockerHub username:', handleUsername);
  }
} else if (command == 'undeploy') {
  var appPath = arg1 || '.';

  var pkg = parsePackageFile(appPath);
  var appName = pkg.name;

  var kubernetesDirPath = appPath + '/kubernetes';
  var kubeFiles = fs.readdirSync(kubernetesDirPath);
  kubeFiles.forEach((configFilePath) => {
    var absolutePath = path.resolve(kubernetesDirPath, configFilePath);
    try {
      execSync(`kubectl delete -f ${absolutePath}`, {stdio: 'inherit'});
    } catch (err) {}
  });

  var deploymentRegex = /\-deployment\.yaml/;
  var scalableDeploymentsKubeFiles = kubeFiles.filter((configFilePath) => {
    return deploymentRegex.test(configFilePath) && configFilePath != 'scc-state-deployment.yaml';
  });
  scalableDeploymentsKubeFiles.forEach((configFilePath) => {
    var hpaName = configFilePath.replace(deploymentYAMLRegex, '');
    execSync(`kubectl delete hpa ${hpaName}`, {stdio: 'inherit'});
  });
Ejemplo n.º 6
0
    `${chalk.green('NOBUILD')} Module build terminated, not a cron job or a custom build!`
  );
  process.exit(0);
}
// Set variables for paths
const SNIPPETS_PATH = './snippets';
const TEMP_PATH = './temp';
const IMPORTS = './imports.js';
// Regex for selecting code blocks
const codeRE = /```\s*js([\s\S]*?)```/;
// Start the timer of the script
console.time('Packager');
// Load tag data from the database and snippets from their folder
try {
  const tagDatabase = fs.readFileSync('tag_database', 'utf8');
  const snippets = fs.readdirSync(SNIPPETS_PATH);
  // Create `temp` folder if it doesn't already exist.
  if (!fs.existsSync(TEMP_PATH)) {
    fs.mkdirSync(TEMP_PATH);
  }
  // Write `imports.js`
  fs.writeFileSync(IMPORTS, '');
  let exportStr = 'export default {';
  // Read all snippets and store them appropriately
  for (const snippet of snippets) {
    const snippetData = fs.readFileSync(path.join(SNIPPETS_PATH, snippet), 'utf8');
    const snippetName = snippet.replace('.md', '');
    // Check if a snippet is Node-only
    const isNodeSnippet = tagDatabase
      .slice(tagDatabase.indexOf(snippetName) + snippetName.length + 1)
      .split('\n')[0]