How to use the shelljs.cd function in shelljs

To help you get started, we’ve selected a few shelljs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactjs / reactjs.org-translation / scripts / create.js View on Github external
function pushOriginalContents() {
  console.log(`${newRepoName} Setting up duplicate repo...`);
  shell.cd(this.path);
  shell.exec(`git clone ${originalUrl} ${newRepoName}`);
  shell.cd(newRepoName);
  // Set the remote to the newly created repo
  shell.exec(`git remote set-url origin ${newRepoUrl}`);
  shell.exec(`git push -u origin ${defaultBranch}`);
  console.log(`${newRepoName} Finished copying contents`);
}
github tensorflow / tfjs / scripts / diff.js View on Github external
const res = shell.exec(`git checkout ${commitSha}`, {silent: true});
const isPullRequestFromFork = res.code !== 0;

// Only checkout the merge base if the pull requests comes from a
// tensorflow/tfjs branch. Otherwise clone master and diff against master.
if (!isPullRequestFromFork) {
  console.log('PR is coming from tensorflow/tfjs. Finding the merge base...');
  exec(`git checkout ${branchName}`);
  const mergeBase = exec(`git merge-base master ${branchName}`).stdout.trim();
  exec(`git fetch origin ${mergeBase}`);
  exec(`git checkout ${mergeBase}`);
  console.log('mergeBase: ', mergeBase);
} else {
  console.log('PR is coming from a fork. Diffing against master.');
}
shell.cd('..');
console.log();  // Break up the console for readability.

let triggerAllBuilds = false;
let whitelistDiffOutput = [];
filesWhitelistToTriggerBuild.forEach(fileToTriggerBuild => {
  const diffOutput = diff(fileToTriggerBuild);
  if (diffOutput !== '') {
    console.log(fileToTriggerBuild, 'has changed. Triggering all builds.');
    triggerAllBuilds = true;
    whitelistDiffOutput.push(diffOutput);
  }
});

console.log();  // Break up the console for readability.

let triggeredBuilds = [];
github reactjs / reactjs.org-translation / lib / repository.js View on Github external
setup() {
    shell.cd(this.path);
    // TODO this will fuck things up if the repo was created but something went wrong
    // (i.e. it's not idempotent)
    if (shell.cd(this.remote.origin.name).code !== 0) {
      if (
        Git.exec(`clone ${this.remote.origin.url} ${this.remote.origin.name}`)
          .code !== 0
      ) {
        console.log(`Error setting up ${this.remote.origin.name}`);
        return;
      }
      shell.cd(this.remote.origin.name);
      Git.exec(
        `remote add ${this.remote.origin.name} ${this.remote.origin.url}`,
      );
      Git.exec(`remote add ${this.remote.head.name} ${this.remote.head.url}`);
      Git.exec(`config user.name "${this.user.name}"`);
github IBM-Blockchain / blockchain-vscode-extension / packages / blockchain-extension / extension / webview / SampleView.ts View on Github external
outputAdapter.log(LogType.ERROR, `The location of the cloned repository on the disk is unknown. Try re-cloning the sample repository.`);
            return;
        }
        const baseDirectory: string = repositoryData.path;

        // Check if directory exists
        const directoryExists: boolean = await fs.pathExists(baseDirectory);

        if (!directoryExists) {
            // If the directory doesn't exist anymore, the user needs to re-clone the repository
            await repositoryRegistry.delete(this.repoName);
            outputAdapter.log(LogType.ERROR, `The location of the file(s) you're trying to open is unknown. The sample repository has either been deleted or moved. Try re-cloning the sample repository.`);
            return;
        } else {
            // If the directory exists, we need to change into the directory
            shell.cd(baseDirectory);
        }

        // Create the command
        const command: string = `git checkout -b ${branch} origin/${branch}`;

        // Checkout the correct branch

        let fastFail: boolean = false; // Throw the error if not attempting to recover

        try {
            await CommandUtil.sendCommand(command);
        } catch (firstError) {
            try {
                if (firstError.message.includes('already exists')) {
                    // If the local branch has already been created, we just need to check it out
                    const checkoutCommand: string = `git checkout ${branch}`;
github adobe / helix-cli / src / builder / ModuleHelper.js View on Github external
}
      let cmd = 'install';
      if (await fse.pathExists(path.resolve(this._buildDir, 'package-lock.json'))) {
        cmd = 'ci';
      }

      const moduleDescriptor = descriptor || name;

      this.log.info(chalk`Running {grey npm ${cmd} ${moduleDescriptor}} in {grey ${path.relative(this.directory, this._buildDir)}} ...`);
      // todo: maye use npm API instead, so that we can show a nice progress bar.
      // todo: since stderr is not a TTY when executed with shelljs, we don't see it.
      await execAsync(`npm ${cmd} --only=prod --prefer-offline --ignore-scripts --no-bin-links --no-audit --save-exact --loglevel ${loglevel} --no-fund --progress true ${moduleDescriptor}`);
    } catch (e) {
      throw Error(`Unable to install ${name}: ${e}`);
    } finally {
      shell.cd(cwd);
    }
  }
github aui / font-spider / src / optimizer.js View on Github external
// Windows 对中文编码支持有问题
    // 使用临时文件来解决此问题
    var charsfile = dest + '.txt.__temp';
    fs.writeFileSync(charsfile, chars, 'utf8');

    // Features to include.
    // - Use "none" to include no features.
    // - Leave array empty to include all features.
    // See list of all features:
    // http://en.wikipedia.org/wiki/OpenType_feature_tag_list#OpenType_typographic_features
    var includeFeatures = ['kern'];


    // Save old path so we can cwd back into it
    var oldCwd = path.resolve(".");
    shell.cd(path.join(__dirname, "./font-optimizer/"));

    // build execution command
    var cmd = [];
    cmd.push("perl -X ./subset.pl"); // Main executable
    // Included characters
    cmd.push(util.format('--charsfile=%s', JSON.stringify(charsfile)));
    if (includeFeatures.length !== 0) {
        // Included font features
        cmd.push("--include=" + includeFeatures.join(","));
    }
    cmd.push(JSON.stringify(src));
    cmd.push(JSON.stringify(temp));
    cmd = cmd.join(" ");
    
    var result = shell.exec(cmd, {silent: true});
github antwarjs / antwar / packages / antwar-cli / src / lib / init.js View on Github external
return download.run(function (err) {
      if (err) {
        return reject(err);
      }

      console.info('Downloaded boilerplate');
      console.info('Installing dependencies');

      shell.cd(directory);
      shell.exec('npm install');

      return resolve();
    });
  });
github microsoft / azure-pipelines-tasks / make-util.js View on Github external
var cd = function (dir) {
    var cwd = process.cwd();
    if (cwd != dir) {
        console.log('');
        console.log(`> cd ${path.relative(cwd, dir)}`);
        shell.cd(dir);
        shellAssert();
    }
}
exports.cd = cd;
github icfnext / iron / lib / solutions / projectSetUp.js View on Github external
if( answers.gulp_es6 === true ){
                            fs.writeFileSync( 'gulpfile.babel.js', templates.gulp['gulp-es6'].value );
                        } else {
                            fs.writeFileSync( 'gulpfile.js', templates.gulp['gulp'].value );
                        }

                        templateRenderer( 'build-tasks/browserify.js', templates.gulp['browserify'].value, {} );
                        templateRenderer( 'build-tasks/sass.js', templates.gulp['sass'].value, {} );
                        templateRenderer( 'build-tasks/watch-browserify.js', templates.gulp['watchBrowserify'].value, {} );
                        templateRenderer( 'build-tasks/watch-sass.js', templates.gulp['watchSass'].value, {} );
                        templateRenderer( 'build-tasks/move-to-cq.js', templates.gulp['moveToCQ'].value, {} );

                    }

                    shell.cd( cwd );

                    exit();

                } )
github simplyspoke / node-harvest / tools / gh-pages-publish.ts View on Github external
let pkg = readJsonSync("package.json");
if (typeof pkg.repository === "object") {
  if (!pkg.repository.hasOwnProperty("url")) {
    throw new Error("URL does not exist in repository section")
  }
  repoUrl = pkg.repository.url
} else {
  repoUrl = pkg.repository
}

let parsedUrl = url.parse(repoUrl)
let repository = (parsedUrl.host || "") + (parsedUrl.path || "")
let ghToken = process.env.GH_TOKEN

echo("Deploying docs!!!")
cd("docs")
touch(".nojekyll")
exec("git init")
exec("git add .")
exec('git config user.name "Tristan Fitzgerald"')
exec('git config user.email "tristan@simplyspoke.com"')
exec('git commit -m "docs(docs): update gh-pages"')
exec(
  `git push --force --quiet "https://${ghToken}@${repository}" master:gh-pages`
)
echo("Docs deployed!!")