How to use the pwd function from shelljs

Find comprehensive JavaScript shelljs.pwd code examples handpicked from public code repositorys.

shelljs.pwd is a method that returns the current working directory as a string.

25
26
27
28
29
30
31
32
33
34
const extVersion = utils.getExtVersion();
const extName = utils.getExtName();
const extString = `${extName}_${extVersion}`;

shell.config.silent = true;
let pwd = shell.pwd();
const rootDir = pwd.match(/[^\\|\/]*$/)[0];
shell.config.silent = false;

// beginning the prompts
fork icon4
star icon4
watch icon0

171
172
173
174
175
176
177
178
179

// Generate native files for Android
generateAndroidArtifacts(releaseVersion);

// Setting up generating native iOS (will be done later)
const repoRoot = pwd();
const reactNativePackagePath = `${repoRoot}/packages/react-native`;
const jsiFolder = `${reactNativePackagePath}/ReactCommon/jsi`;
const hermesCoreSourceFolder = `${reactNativePackagePath}/sdks/hermes`;
fork icon2
star icon0
watch icon0

How does shelljs.pwd work?

The shelljs.pwd() method returns the current working directory (cwd) of the shell process as a string, and it works by invoking the process.cwd() method to obtain the current working directory.

12
13
14
15
16
17
18
19
20
21
22
23


Object.freeze(TestType);


function exec(command) {
  return new Promise(function(resolve, reject) {
    log.debug("Command directory:", shell.pwd().toString());
    log.debug("Command to execute:", command);
    shell.exec(command, config, function(code, stdout, stderr) {
      if (code) {
        reject(new CICDError(code, stderr));
fork icon1
star icon0
watch icon6

+ 8 other calls in file

248
249
250
251
252
253
254
255
256
257
258
 * the remote. This assumes that the repository has already been modified somehow (e.g. by adding a blogpost).
 * @param {string} [tag] The string to tag the commit with
 * @returns {void}
 */
function commitSiteToGit(tag) {
    const currentDir = pwd();


    cd(SITE_DIR);
    exec("git add -A .");
    exec(`git commit -m "Added release blog post for ${tag}"`);
fork icon0
star icon0
watch icon1

+ 59 other calls in file

Ai Example

1
2
3
4
5
6
const shell = require("shelljs");

// Get the current working directory
const pwd = shell.pwd();

console.log("Current working directory:", pwd);

Output: bash Copy code

150
151
152
153
154
155
156
157
158
159
160
    };
}
exports.getCommonPackInfo = getCommonPackInfo;


var buildNodeTask = function (taskPath, outDir) {
    var originalDir = shell.pwd().toString();
    cd(taskPath);
    var packageJsonPath = rp('package.json');
    var overrideTscPath;
    if (test('-f', packageJsonPath)) {
fork icon0
star icon0
watch icon0

41
42
43
44
45
46
47
48
49
50
51
// sh.ls('-l').forEach(function (dir) {
//   // sh.exec('dirname', dir)
//   sh.echo(dir.name)
//   // if (dir.name == 'test') {
//   //     sh.cd(dir.name)
//   //     sh.pwd()
//   // }
// });


// for (let index = 0; index < projectNameArr.length; index++) {
fork icon0
star icon0
watch icon0