function main()

in packages/actions/deploy.js [13:80]


function main(params) {
  const activationId = process.env.__OW_ACTIVATION_ID;
  return new Promise((resolve, reject) => {
    // Grab optional envData and manifestPath params for wskdeploy
    let {
      envData,
      manifestPath,
      gitUrl
    } = params;

    // confirm gitUrl was provided as a parameter
    if (!gitUrl) {
      reject(new Error('Please enter the GitHub repo url in params'));
    }

    // if no manifestPath was provided, use current directory
    if (!manifestPath) {
      manifestPath = '.';
    }
    // Grab wsp api host and auth from params, or process.env
    const { wskApiHost, wskAuth } = getWskApiAuth(params);

    // Extract the name of the repo for the tmp directory
    const tmpUrl = gitUrl.replace('https://', '');
    const repoSplit = tmpUrl.split('/');
    const repoOrg = repoSplit[1];
    const repoName = repoSplit[2];
    const localDirName = `${__dirname}/../tmp/${repoOrg}/${repoName}`;
    const templatesDirName = `${__dirname}/preInstalled/${repoOrg}/${repoName}`;

    if (fs.existsSync(templatesDirName)) {
      resolve({
        repoDir: templatesDirName,
        usingTemp: false,
        manifestPath,
        manifestFileName: 'manifest.yaml',
        wskAuth,
        wskApiHost,
        envData,
      });
    } else {
      return git().clone(gitUrl, localDirName, ['--depth', '1'], (err) => {
        if (err) {
          reject(new Error('There was a problem cloning from github.  Does that github repo exist?  Does it begin with http?'));
        }
        resolve({
          repoDir: localDirName,
          usingTemp: true,
          manifestPath,
          manifestFileName: 'manifest.yaml',
          wskAuth,
          wskApiHost,
          envData,
        });
      });
    }
  })
    .then(result => common.main(result))
    .then(success =>
      new Promise((resolve, reject) => {
        resolve({
          status: success,
          activationId,
          success: true,
        });
      }))
    .catch(err => ({ error: err.message, activationId }));
}