How to use the cp function from shelljs

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

186
187
188
189
190
191
192
193
194
const files = getLocaleSourceCatalogFiles(locale);

if (files.length === 1) {
  // For languages with a single source ("en", "pseudo_LOCALE"),
  // don't concatenate anything.
  const cpResult = shell.cp(
    path.join(getLocalePath(locale), files[0]),
    path.join(getLocalePath(locale), 'messages.po')
  );
fork icon621
star icon0
watch icon161

192
193
194
195
196
197
198
199
200
201
    return path.includes(`templates/${projectName}/`);
  },
});

// Copy files into current working dir
sh.cp(
  '-r',
  `${path.join(TEMP, 'templates', projectName)}${path.sep}.`,
  '.'
);
fork icon29
star icon93
watch icon20

+ 59 other calls in file

49
50
51
52
53
54
55
56
57
58
        sourceFiles.push(files[i] + '/');
    } else if (files[i].split('/').length <= 2) {
        sourceFiles.push(files[i]);
    }
}
shelljs.cp('-R', sourceFiles, './ej2aspmvc/');

// navigate to cloned location
shelljs.cd('./ej2aspmvc');
// git add remote, add files and commit
fork icon27
star icon9
watch icon13

+ 24 other calls in file

503
504
505
506
507
508
509
510
511
512
513
 * Discover all examples and extract information from them.
 */
(async () => {
  shell.mkdir('-p', distPath);
  shell.rm('-rf', examplesRootPath);
  shell.cp('-r', sourceExamplesRootPath, examplesRootPath);


  const loadedGDevelop = await loadGDevelopCoreAndExtensions({
    gdevelopRootPath,
  });
fork icon12
star icon26
watch icon4

108
109
110
111
112
113
114
115
116
117
118
    // If project contains 'merges' for our platform, use them as another overrides
    var merges_path = path.join(cordovaProject.root, 'merges', 'ios');
    if (fs.existsSync(merges_path)) {
        events.emit('verbose', 'Found "merges" for ios platform. Copying over existing "www" files.');
        var overrides = path.join(merges_path, '*');
        shell.cp('-rf', overrides, destinations.www);
    }
}


/**
fork icon9
star icon20
watch icon4

+ 113 other calls in file

95
96
97
98
99
100
101
102
103
104
     * exceeds the default test timeout, so raise it just for this hook.
     * Mocha uses `this` to set timeouts on an individual hook level.
     */
    this.timeout(60 * 1000);
    shell.mkdir("-p", fixtureDir);
    shell.cp("-r", "./tests/fixtures/.", fixtureDir);
});

beforeEach(() => {
    ({ Ec0lint } = require("../../../lib/ec0lint/ec0lint"));
fork icon5
star icon131
watch icon1

+ 34 other calls in file

184
185
186
187
188
189
190
191
192
  expandHermesSourceTarball();
}

// need to move the scripts inside the local hermes cloned folder
// cp sdks/hermes-engine/utils/*.sh <your_hermes_checkout>/utils/.
cp(
  `${reactNativePackagePath}/sdks/hermes-engine/utils/*.sh`,
  `${reactNativePackagePath}/sdks/hermes/utils/.`,
);
fork icon2
star icon0
watch icon0

216
217
218
219
220
221
222
223
224
225
226


    if (link) {
        fs.symlinkSync(path.relative(path.dirname(dest), src), dest);
    } else if (fs.statSync(src).isDirectory()) {
        // XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
        shell.cp('-Rf', src+'/*', dest);
    } else {
        shell.cp('-f', src, dest);
    }
}
fork icon2
star icon0
watch icon0

+ 3 other calls in file

155
156
157
158
159
160
161
162
163
164
165
 * @param {String} source
 * @param {String} dest
 * @returns {Void}
 */
function copy(options, source, dest) {
    Shell.cp(options, source, dest);
}


/**
 * Removes the Files
fork icon0
star icon3
watch icon0

202
203
204
205
206
207
208
209
210
211
212
213
        fs.mkdirSync(destFolder);
    }


    var destFilePath = path.join(destFolder, isNinePatch ? ninePatchName : name);
    events.emit('verbose', 'copying image from ' + src + ' to ' + destFilePath);
    shell.cp('-f', src, destFilePath);
}


function handleSplashes(projectConfig, platformRoot) {
    var resources = projectConfig.getSplashScreens('android');
fork icon1
star icon2
watch icon1

+ 84 other calls in file

352
353
354
355
356
357
358
359
360
361
362
363


// Copy files
extras.copy = function (from, to) {
  from = extras.resolve(from)
  to = extras.resolve(to)
  return sh.cp('-R', from, to)
}


// Is directory?
extras.isDir = function (file) {
fork icon0
star icon3
watch icon1

+ 56 other calls in file

132
133
134
135
136
137
138
139
140
141
142
    shell.cp('-r', srcScriptsDir, projectPath);
    shell.cp('-r', path.join(ROOT, 'bin', 'node_modules'), destScriptsDir);
    shell.cp(path.join(ROOT, 'bin', 'check_reqs'), path.join(destScriptsDir, 'check_reqs'));
    shell.cp(path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(projectPath, 'cordova', 'lib', 'check_reqs.js'));
    shell.cp(path.join(ROOT, 'bin', 'android_sdk_version'), path.join(destScriptsDir, 'android_sdk_version'));
    shell.cp(path.join(ROOT, 'bin', 'lib', 'android_sdk_version.js'), path.join(projectPath, 'cordova', 'lib', 'android_sdk_version.js'));
}


/**
 * Test whether a package name is acceptable for use as an android project.
fork icon0
star icon2
watch icon1

+ 209 other calls in file

337
338
339
340
341
342
343
344
345
346
    path.join(repo_build_dir, '*'),
    artifact_repo_path
)
core.info(`cp build: ${res_cp_build.code}`)

const res_cp_pkg = shell.cp(
    `${repo}/package.json`,
    `${artifact_repo_path}/package.json`
)
core.info(`cp pkg: ${res_cp_pkg.code}`)
fork icon1
star icon1
watch icon24

+ 473 other calls in file

67
68
69
70
71
72
73
74
75
76
} else {
    shell.mkdir('-p', nestedCordovaLibPath);
    shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath);
    shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath);
    shell.cp('-f', path.join(ROOT, 'framework', 'build.gradle'), nestedCordovaLibPath);
    shell.cp('-f', path.join(ROOT, 'framework', 'cordova.gradle'), nestedCordovaLibPath);
    shell.cp('-r', path.join(ROOT, 'framework', 'src'), nestedCordovaLibPath);
    // Create an eclipse project file and set the name of it to something unique.
    // Without this, you can't import multiple CordovaLib projects into the same workspace.
    var eclipseProjectFilePath = path.join(nestedCordovaLibPath, '.project');
fork icon0
star icon1
watch icon1

+ 19 other calls in file

63
64
65
66
67
68
69
70
71
72
73
74
75
		templateType.toLowerCase()
	)


	shell.cd(projectName);


	return shell.cp('-r', `${templateDir}/*`, process.cwd())
}


const initGit = async function(){
	const result = await execa('git', ['init'], {
fork icon0
star icon1
watch icon1

+ 9 other calls in file

777
778
779
780
781
782
783
784
785
786
    shelljs.cp('-R', filePath, toPath);
    Util.log(`Copied ${Util.relativePath(filePath)}`);
    if (withMap) {
        const mapFile = Util.getMapFile(filePath);
        if (mapFile) {
            shelljs.cp('-R', mapFile, toPath);
            Util.log(`Copied ${Util.relativePath(mapFile)}`);
        }
    }
},
fork icon0
star icon1
watch icon1

+ 15 other calls in file

85
86
87
88
89
90
91
92
93
94
95
96
97
98


async function packageRust() {
  shell.echo("PACKAGING RUST...");


  shell.mkdir("./bin-package");
  shell.cp("./native/index.node", "./bin-package");


  shell.exec("npm run package");


  const version = JSON.parse(await fs.promises.readFile("./package.json")).version;
fork icon0
star icon1
watch icon0

+ 3 other calls in file

73
74
75
76
77
78
79
80
81
let buildTool = taskParams["buildTool"];
log.debug("Build Tool: ", buildTool);

// log.debug("Copy source code from shared drive to container");
// shell.mkdir("-p", workdir);
// shell.cp("-R", dir + "/repository/*", testdir);

const testTypes = typeof taskParams["testType"] === "string" ? taskParams["testType"].split(",") : [];
const version = parseVersion(taskParams["version"], taskParams["appendBuildNumber"]);
fork icon1
star icon0
watch icon6

+ 53 other calls in file

139
140
141
142
143
144
145
146
147
148
// If defaults.xml is present, overwrite platform config.xml with it.
// Otherwise save whatever is there as defaults so it can be
// restored or copy project config into platform if none exists.
if (fs.existsSync(defaultConfigPath)) {
    this.events.emit('verbose', 'Generating config.xml from defaults for platform "' + this.platform + '"');
    shell.cp('-f', defaultConfigPath, ownConfigPath);
} else if (fs.existsSync(ownConfigPath)) {
    this.events.emit('verbose', 'Generating defaults.xml from own config.xml for platform "' + this.platform + '"');
    shell.cp('-f', ownConfigPath, defaultConfigPath);
} else {
fork icon0
star icon1
watch icon1

+ 3 other calls in file

2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
});
const badFile = fs.realpathSync(getFixturePath("cache/src", "fail-file.js"));
const goodFile = fs.realpathSync(getFixturePath("cache/src", "test-file.js"));
const goodFileCopy = path.resolve(`${path.dirname(goodFile)}`, "test-file-copy.js");

shell.cp(goodFile, goodFileCopy);

await eslint.lintFiles([badFile, goodFileCopy]);
let fileCache = fCache.createFromFile(cacheLocation, true);
const entries = fileCache.normalizeEntries([badFile, goodFileCopy]);
fork icon0
star icon0
watch icon1

+ 59 other calls in file