How to use the mkdirSync function from temp
Find comprehensive JavaScript temp.mkdirSync code examples handpicked from public code repositorys.
temp.mkdirSync is a function in the temp package that creates a unique directory synchronously.
22 23 24 25 26 27 28 29 30 31 32 33
] describe('mmap-object', function () { before(function () { temp.track() this.dir = temp.mkdirSync('node-shared') }) describe('Writer', function () { beforeEach(function () {
379 380 381 382 383 384 385 386 387 388 389 390
}); }); //Extending the yeoman helper method function runGenerator(generatorType, name, context, promptAnswers, done) { var workspace = context.workspace = temp.mkdirSync(); helpers.testDirectory(workspace, function(err) { if (err) { return done(err);
How does temp.mkdirSync work?
temp.mkdirSync is a synchronous function in the temp module of Node.js that creates a unique temporary directory and returns its path. The function takes an optional prefix parameter that sets the directory name prefix and a options object that allows for setting the directory mode and other options.
3 4 5 6 7 8 9 10 11 12 13 14
const inputPath = __dirname + "/input"; const expectedPath = __dirname + "/expected-output"; const jscodeshiftPath = __dirname + "/../node_modules/.bin/jscodeshift"; const transformPath = __dirname + "/../index.js"; const tempPath = temp.mkdirSync("ember-k-codemod-tests"); const TIMEOUT = 10000; const VERBOSE_ENV_VAR = "VERBOSE_JSCODESHIFT"; process.env.RETURN_THIS = "true";
28 29 30 31 32 33 34 35 36 37 38 39
describe('Windows Squirrel Update', function() { let tempHomeDirectory = null; beforeEach(function() { // Prevent the actual home directory from being manipulated tempHomeDirectory = temp.mkdirSync('atom-temp-home-'); spyOn(fs, 'getHomeDirectory').andReturn(tempHomeDirectory); // Prevent any spawned command from actually running and affecting the host spyOn(Spawner, 'spawn').andCallFake((
Ai Example
1 2 3 4 5 6 7 8 9 10 11
const temp = require("temp"); const fs = require("fs"); // Create a temporary directory const dir = temp.mkdirSync("my-temp-dir"); // Write a file to the temporary directory fs.writeFileSync(`${dir}/file.txt`, "Hello, world!"); // Print the contents of the temporary directory console.log(fs.readdirSync(dir));
In this example, temp.mkdirSync is used to create a temporary directory with the prefix 'my-temp-dir'. The function returns the path to the newly created directory, which is then used to write a file to the directory using the built-in fs module. Finally, the contents of the directory are printed to the console using fs.readdirSync.
GitHub: Pansero87/Atom
136 137 138 139 140 141 142 143 144 145
}); }); it('does not deserialize buffers when their path is now a directory', () => { const pathToOpen = path.join( temp.mkdirSync('atom-spec-project'), 'file.txt' ); waitsForPromise(() => atom.workspace.open(pathToOpen));
+ 20 other calls in file
133 134 135 136 137 138 139 140 141 142
// with another object. expect(process.env).toBe(initialProcessEnv); }); it('allows ATOM_HOME to be overwritten only if the new value is a valid path', async function() { let newAtomHomePath = temp.mkdirSync('atom-home'); process.env = { WILL_BE_DELETED: 'hi', NODE_ENV: 'the-node-env',
431 432 433 434 435 436 437 438 439 440 441
}); }); }); function copyRepository() { const workingDirPath = temp.mkdirSync('atom-spec-git'); fs.copySync( path.join(__dirname, 'fixtures', 'git', 'working-dir'), workingDirPath );
159 160 161 162 163 164 165 166 167 168
}, done); } // Copy source files to temporary directory function copyFilesToTempDir(done) { o.tempDir = temp.mkdirSync(); async.forEach(o.files, function(file, next) { grunt.file.copy(file, path.join(o.tempDir, o.rename(file))); next(); }, done);
15 16 17 18 19 20 21 22 23 24 25 26
console.log(testFilePath); describe("shared-file-view", function () { before(function () { temp.track(); this.dir = temp.mkdirSync("node-shared"); }); describe("Static functions", function () { it("it creates", function (done) {
1 2 3 4 5 6 7 8 9 10 11
const fs = require('fs-extra') const { spawnSync } = require('child_process') const path = require('path') const temp = require('temp').track() const workingDir = temp.mkdirSync('mksnapshot-workdir') const crossArchDirs = [ 'clang_x86_v8_arm', 'clang_x64_v8_arm64', 'win_clang_x64'
41 42 43 44 45 46 47 48 49
var compiled = Schema.normalize(result.contracts["Example"]); abi = compiled.abi; binary = compiled.bytecode; // Setup var dirPath = temp.mkdirSync({ dir: path.resolve("./"), prefix: 'tmp-test-contract-' });
+ 2 other calls in file
GitHub: ukm/atom
32 33 34 35 36 37 38 39 40 41
}) it('uses ATOM_HOME if no write access to portable .atom folder', () => { if (process.platform === 'win32') return const readOnlyPath = temp.mkdirSync('atom-path-spec-no-write-access') process.env.ATOM_HOME = readOnlyPath fs.chmodSync(portableAtomHomePath, 444) atomPaths.setAtomHome(app.getPath('home')) expect(process.env.ATOM_HOME).toEqual(readOnlyPath)
+ 2 other calls in file
62 63 64 65 66 67 68 69 70 71
// with another object. expect(process.env).toBe(initialProcessEnv) }) it('allows ATOM_HOME to be overwritten only if the new value is a valid path', async function () { let newAtomHomePath = temp.mkdirSync('atom-home') process.env = { WILL_BE_DELETED: 'hi', NODE_ENV: 'the-node-env',
863 864 865 866 867 868 869 870 871 872
// No project paths. Don't try to run specs. atom.commands.dispatch(workspaceElement, 'window:run-package-specs') expect(ipcRenderer.send).not.toHaveBeenCalledWith('run-package-specs') const projectPaths = [temp.mkdirSync('dir1-'), temp.mkdirSync('dir2-')] atom.project.setPaths(projectPaths) // No active item. Use first project directory. atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
6 7 8 9 10 11 12 13 14 15
let installer, resourcesPath, installationPath, atomBinPath, apmBinPath beforeEach(() => { installationPath = temp.mkdirSync('atom-bin') resourcesPath = temp.mkdirSync('atom-app') atomBinPath = path.join(resourcesPath, 'app', 'atom.sh') apmBinPath = path.join(resourcesPath, 'app', 'apm', 'node_modules', '.bin', 'apm') fs.writeFileSync(atomBinPath, '') fs.writeFileSync(apmBinPath, '')
GitHub: ukm/atom
2 3 4 5 6 7 8 9 10 11 12 13
describe('StyleManager', () => { let [styleManager, addEvents, removeEvents, updateEvents] = [] beforeEach(() => { styleManager = new StyleManager({configDirPath: temp.mkdirSync('atom-config')}) addEvents = [] removeEvents = [] updateEvents = [] styleManager.onDidAddStyleElement((event) => { addEvents.push(event) })
GitHub: ukm/atom
406 407 408 409 410 411 412 413 414 415
}) describe('adding a project folder', () => { it('does nothing if the user dismisses the file picker', () => { const initialPaths = atom.project.getPaths() const tempDirectory = temp.mkdirSync('a-new-directory') spyOn(atom, 'pickFolder').andCallFake(callback => callback(null)) atom.addProjectFolder() expect(atom.project.getPaths()).toEqual(initialPaths) })
+ 5 other calls in file
GitHub: ukm/atom
2137 2138 2139 2140 2141 2142 2143 2144 2145 2146
beforeEach(() => { dir1 = atom.project.getPaths()[0] file1 = path.join(dir1, 'a-dir', 'oh-git') dir2 = temp.mkdirSync('a-second-dir') const aDir2 = path.join(dir2, 'a-dir') file2 = path.join(aDir2, 'a-file') fs.mkdirSync(aDir2) fs.writeFileSync(file2, 'ccc aaaa')
+ 2 other calls in file
10 11 12 13 14 15 16 17 18 19
fn(); screenUpdates++; }); spyOn(window, 'cancelAnimationFrame').andCallFake(i => null); projectPath = temp.mkdirSync('git-diff-spec-'); fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath); fs.moveSync( path.join(projectPath, 'git.git'),
GitHub: OddEssA/Atom
11 12 13 14 15 16 17 18 19 20
screenUpdates++; }); spyOn(window, 'cancelAnimationFrame').andCallFake(i => null); projectPath = temp.mkdirSync('git-diff-spec-'); const otherPath = temp.mkdirSync('some-other-path-'); fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath); fs.moveSync( path.join(projectPath, 'git.git'),
temp.mkdirSync is the most popular function in temp (129 examples)