Returns a Promise Gets platform details from a directory
556684
function getPlatformDetailsFromDir(dir, platformIfKnown){
    var libDir = path.resolve(dir);
    var platform;
    var version;

    try {
        var pkg = require(path.join(libDir, 'package'));
        platform = platformFromName(pkg.name);
        version = pkg.version;
    } catch(e) {
        // Older platforms didn't have package.json.
        platform = platformIfKnown || platformFromName(path.basename(dir));
        var verFile = fs.existsSync(path.join(libDir, 'VERSION')) ? path.join(libDir, 'VERSION') :
                      fs.existsSync(path.join(libDir, 'CordovaLib', 'VERSION')) ? path.join(libDir, 'CordovaLib', 'VERSION') : null;
        if (verFile) {
            version = fs.readFileSync(verFile, 'UTF-8').trim();
        }
    }

    // if (!version || !platform || !platforms[platform]) {
    //     return Q.reject(new CordovaError('The provided path does not seem to contain a ' +
    //         'Cordova platform: ' + libDir));
    // }

    return Q({
        libDir: libDir,
        platform: platform || platformIfKnown,
        version: version || '0.0.1'
    });
}
62141
function search(platform) {
  return new Promise((resolve, reject) => {
    if (!platform || platform === '') reject(new Error('platform cannot be blank'));
    const options = {
      method: 'GET',
      hostname: 'www.exploitalert.com',
      path: `/api/search-exploit?name=${platform}`,
    };

    const req = http.request(options, (res) => {
      const chunks = [];

      res.on('data', (chunk) => {
        chunks.push(chunk);
      });

      res.on('end', () => {
        const body = Buffer.concat(chunks);
        resolve(JSON.parse(body));
      });
    });

    req.on('error', err => reject(err));
    req.end();
  });
}
1060892
function dirExist(dirName) {
  return new Promise((resolve, reject) => {
    fs.stat(dirName, (err, stats) => {
      if (err === null && stats.isDirectory()) {
        resolve(dirName);
      } else {
        resolve(false);
      }
    });
  });
}
737288
function PlatformInfo(PlatformCtor, platformId) {

    this._Ctor = PlatformCtor;
    this._platformId = platformId;

    // Prefix all platform-specific args with the platform name
    var argSpec = PlatformCtor.getArgs ? PlatformCtor.getArgs() : {};
    this._argSpec = {};
    for (var cmd in argSpec) {
        var cmdArgSpec = argSpec[cmd];
        var platformCmdArgSpec = {};
        for (var key in cmdArgSpec) {
            platformCmdArgSpec["--" + platformId + "-" + key] = cmdArgSpec[key];
        }
        this._argSpec[cmd] = platformCmdArgSpec;
    }

    // Look for platforms env vars
    this._envSpec = PlatformCtor.getEnv ? PlatformCtor.getEnv() : {};
}
773005
function getPlatformExtension(file, platforms = SUPPORTED_PLATFORM_EXTS) {
  const last = file.lastIndexOf('.');
  const secondToLast = file.lastIndexOf('.', last - 1);
  if (secondToLast === -1) {
    return null;
  }
  const platform = file.substring(secondToLast + 1, last);
  return platforms.has(platform) ? platform : null;
}
413366
function (packageid) {
    return this.get('/packagedetails', {
      'cc': this.options.country,
      'l': this.options.language,
      'packageids': packageid
    }).then(function (body) {
      var data = body[packageid].data;
      return Promise.resolve(data);
    });
  }
368199
function rimrafPromise(dir) {
  return new Promise((resolve, reject) => {
    rimraf(dir, err => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}
329563
function getPlatVersionsFromFileSystem(projectRoot){
    var platforms_on_fs = cordova_util.listPlatforms(projectRoot);
    var platformVersions = platforms_on_fs.map(function(platform){
        var script = path.join(projectRoot, 'platforms', platform, 'cordova', 'version');
        return Q.ninvoke(child_process, 'exec', script, {}).then(function(result){
            var version = result[0];

            // clean the version we get back from the script
            // This is necessary because the version script uses console.log to pass back
            // the version. Using console.log ends up adding additional line breaks/newlines to the value returned.
            // ToDO: version scripts should be refactored to not use console.log()
            var versionCleaned = version.replace(/\r?\n|\r/g, '');
            return {platform: platform, version: versionCleaned};
        });
    });

    return Q.all(platformVersions);
}
761684
function getVersions(projectRoot) {
    var platformsDir = path.join(projectRoot, 'platforms');
    var platformsJsonFile = path.join(platformsDir, 'platforms.json');

    // If the platforms.json file doesn't exist, retrieve versions from platforms installed on the filesystem...
    // ...Note that in this case, we won't be able to know what source(folder, git-url) the platform came from, we'll just use versions
    return getPlatVersionsFromFile(platformsJsonFile).fail(function(){
        return getPlatVersionsFromFileSystem(projectRoot);
    });
}
218683
function() {
                var def = _promise.deferred();

                _fs.exists(_folderPath, function(exists) {
                    if (exists) {
                        def.resolve();
                    } else {
                        _fs.mkdir(_folderPath, function(err) {
                            if (!err) {
                                def.resolve();
                            } else {
                                def.reject();
                            }
                        });
                    }
                });

                return def.promise();
            }
896460
function mkdirs(dir) {
  return new Promise((resolve, reject) => {
    FS.ensureDir(dir, err => {
      err ? reject(err) : resolve(dir);
    })
  });
}
960021
function getInstalledPlatformVersion(projectPath, platform) {
    var platformJsonPath = path.join(projectPath, 'platforms', 'platforms.json')
    if (fileExistsSync(platformJsonPath)) {
        var platformsJson = require(path.join(projectPath, 'platforms', 'platforms.json'));
        return Q(platformsJson[platform]);
    } else {
        return exec(path.join(projectPath, 'platforms', platform, 'cordova', 'version')).then(function (result) {
            return result[0].replace(/\r?\n|\r/g, '');
        });
    }
}
528698
async function getTemplateFile(templateDir, stackName) {
  const f = await Promise.any(
    _.map(['.yml', '.yaml', '.json', ''], async(ext) =>
      await utils.fileExists(`${path.join(templateDir, stackName)}${ext}`)));
  if (f) {
    return f;
  }
  throw new Error(`Stack template "${stackName}" not found!`);
}
521571
async function viaContentsApi(identifier, dir, token) {
	const files = [];
	const requests = [];
	const {repo, ref} = parseIdentifier(identifier);
	const contents = await api(`${repo}/contents/${dir}?ref=${ref}`, token);
	for (const item of contents) {
		if (item.type === 'file') {
			files.push(item.path);
		} else if (item.type === 'dir') {
			requests.push(viaContentsApi(repo, item.path, token));
		}
	}
	return files.concat(...await Promise.all(requests));
}
1142834
function osInfo(callback) {

  return new Promise((resolve) => {
    process.nextTick(() => {
      let result = {

        platform: (_platform === 'Windows_NT' ? 'Windows' : _platform),
        distro: 'unknown',
        release: 'unknown',
        codename: '',
        kernel: os.release(),
        arch: os.arch(),
        hostname: os.hostname(),
        codepage: '',
        logofile: '',
        serial: '',
        build: ''
      };

      if (_linux) {

        exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', function (error, stdout) {
          //if (!error) {
          /**
           * @namespace
           * @property {string}  DISTRIB_ID
           * @property {string}  NAME
           * @property {string}  DISTRIB_RELEASE
           * @property {string}  VERSION_ID
           * @property {string}  DISTRIB_CODENAME
           */
          let release = {};
          let lines = stdout.toString().split('\n');
          lines.forEach(function (line) {
            if (line.indexOf('=') !== -1) {
              release[line.split('=')[0].trim().toUpperCase()] = line.split('=')[1].trim();
            }
          });
          let releaseVersion = (release.VERSION || '').replace(/"/g, '');
          let codename = (release.DISTRIB_CODENAME || release.VERSION_CODENAME || '').replace(/"/g, '');
          if (releaseVersion.indexOf('(') >= 0) {
            codename = releaseVersion.split('(')[1].replace(/[()]/g, '').trim();
            releaseVersion = releaseVersion.split('(')[0].trim();
          }
          result.distro = (release.DISTRIB_ID || release.NAME || 'unknown').replace(/"/g, '');
          result.logofile = getLogoFile(result.distro);
          result.release = (releaseVersion || release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
          result.codename = codename;
          result.codepage = util.getCodepage();
          result.build = (release.BUILD_ID || '').replace(/"/g, '').trim();
          uuid().then(data => {
            result.serial = data.os;
            if (callback) {
              callback(result);
            }
            resolve(result);
          });
          //}
        });
      }
      if (_freebsd || _openbsd) {

        exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid', function (error, stdout) {
          if (!error) {
            let lines = stdout.toString().split('\n');
            result.distro = util.getValue(lines, 'kern.ostype');
            result.logofile = getLogoFile(result.distro);
            result.release = util.getValue(lines, 'kern.osrelease').split('-')[0];
            result.serial = util.getValue(lines, 'kern.uuid');
            result.codename = '';
            result.codepage = util.getCodepage();
          }
          if (callback) {
            callback(result);
          }
          resolve(result);
        });
      }
      if (_darwin) {
        exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', function (error, stdout) {
          let lines = stdout.toString().split('\n');
          result.serial = util.getValue(lines, 'kern.uuid');
          result.distro = util.getValue(lines, 'ProductName');
          result.release = util.getValue(lines, 'ProductVersion');
          result.build = util.getValue(lines, 'BuildVersion');
          result.logofile = getLogoFile(result.distro);
          result.codename = 'macOS';
          result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
          result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
          result.codename = (result.release.indexOf('10.4') > -1 ? 'Mac OS X Tiger' : result.codename);
          result.codename = (result.release.indexOf('10.5') > -1 ? 'Mac OS X Leopard' : result.codename);
          result.codename = (result.release.indexOf('10.6') > -1 ? 'Mac OS X Snow Leopard' : result.codename);
          result.codename = (result.release.indexOf('10.7') > -1 ? 'Mac OS X Lion' : result.codename);
          result.codename = (result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename);
          result.codename = (result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename);
          result.codename = (result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename);
          result.codename = (result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename);
          result.codename = (result.release.indexOf('10.12') > -1 ? 'macOS Sierra' : result.codename);
          result.codename = (result.release.indexOf('10.13') > -1 ? 'macOS High Sierra' : result.codename);
          result.codename = (result.release.indexOf('10.14') > -1 ? 'macOS Mojave' : result.codename);

          result.codepage = util.getCodepage();
          if (callback) {
            callback(result);
          }
          resolve(result);
        });
      }
      if (_sunos) {
        result.release = result.kernel;
        exec('uname -o', function (error, stdout) {
          let lines = stdout.toString().split('\n');
          result.distro = lines[0];
          result.logofile = getLogoFile(result.distro);
          if (callback) { callback(result); }
          resolve(result);
        });
      }
      if (_windows) {
        result.logofile = getLogoFile();
        result.release = result.kernel;
        try {
          util.wmic('os get /value').then((stdout, error) => {
            let lines = stdout.toString().split('\r\n');
            result.distro = util.getValue(lines, 'Caption', '=').trim();
            result.serial = util.getValue(lines, 'SerialNumber', '=').trim();
            result.build = util.getValue(lines, 'BuildNumber', '=').trim();
            result.codepage = util.getCodepage();
            if (callback) {
              callback(result);
            }
            resolve(result);
          });
        } catch (e) {
          if (callback) { callback(result); }
          resolve(result);
        }
      }
    });
  });
}
1311050
async function getFiles(dir) {
  const subdirs = await readdir(dir);
  const files = await Promise.all(
    subdirs.map(async subdir => {
      const res = resolve(dir, subdir);
      return (await stat(res)).isDirectory() ? getFiles(res) : res;
    }),
  );
  return files.reduce((a, f) => a.concat(f), []);
}
841258
function() {
        return new Promise(function(resolve, reject) {
            exec("find . ! -name '" + __filename.split('/').pop() + "' -iname '*\.js' | xargs grep 'CRUD.Entity.call(this);' -isl", {
                timeout: 3000,
                cwd: process.cwd()
            }, function(err, stdout, stdin) {
                var results = stdout.trim().split('\n');
                var entities = {};

                // iterate all found js files and search for CRUD.define calls
                results.map(function(filename) {
                    if (filename.trim() == '') return;
                    var code = fs.readFileSync(filename) + '';
                    var ast = UglifyJS.parse(code);
                    ast.walk(new UglifyJS.TreeWalker(function(node) {
                        if (node instanceof UglifyJS.AST_Call && node.start.value == 'CRUD' && node.expression.property == 'define') {
                            entities[node.args[0].start.value] = filename;
                        }
                    }));
                });

                resolve(entities);
            });
        });
    }