UNPKG

generator-hap

Version:

generator hap for install and update hap scaffold

122 lines (101 loc) 3.46 kB
var fs = require('fs'), path = require('path'), yeoman = require('yeoman-generator'), util = require("./util"), config = require("./config"); module.exports = yeoman.Base.extend({ constructor: function() { yeoman.Base.apply(this, arguments); this.option("update", { desc: "Update scaffold", type: Boolean, defaults: false }); this.option("archive", { desc: "The archive url", type: String, defaults: "" }); this.option("username", { desc: "The git username", type: String, defaults: config.github.username }); this.option("repository", { desc: "The git repository name", type: String, defaults: config.github.repository }); this.option("branch", { desc: "The git branch name", type: String, defaults: config.github.branch }); this.option("skip-local-cache", { desc: "Skips the local cache", type: Boolean, defaults: true }); this.option("skip-npm-install", { desc: "Skips the installation of npm", type: Boolean, defaults: false }); this.option("skip-bower-install", { desc: "Skips the installation of bower", type: Boolean, defaults: false }); this.argument('appname', { type: String, required: false, defaults: "" }); }, initializing: function() { util.log("Welcome to use hap.") }, writing: function() { var self = this, done = this.async(), archive = this.options["archive"], skipLocalCache = this.options["skip-local-cache"], username = this.options["username"], repository = this.options["repository"], branch = this.options["branch"], target = path.join(config.targetPath, this.appname); function callback(err, remote){ var source; if (!err) { util.log("The branch has been download to " + remote.cachePath); util.log("Copy files to " + path.join(process.cwd(), target)); //copy assets and .* file source = [path.join(remote.cachePath, "**"), path.join(remote.cachePath, ".*")]; self.fs.copy(source, target); } else { util.log(err); process.exit(1); } done(); } util.log("Downloading the files."); //if archive is not empty if(archive){ this.remote(archive, callback, skipLocalCache); }else{ this.remote(username, repository, branch, callback, skipLocalCache); } }, install: function() { var update = this.options["update"], skipNpmInstall = this.options["skip-npm-install"], skipBowerInstall = this.options["skip-bower-install"]; !update && this.installDependencies({ bower: skipBowerInstall ? false : true, npm: skipNpmInstall ? false : true, callback: function(err) { util.log("The installation of dependencies has been download."); } }); } });