Skip to content

Commit 52b3795

Browse files
authored
fixed creating temp directories for sync (#16)
1 parent a67ac05 commit 52b3795

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/util/file.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { existsSync, mkdtempSync } from 'fs';
2+
import { sync as mkdirp } from 'mkdirp';
3+
import { join } from 'path';
4+
5+
export function makeTempDirectory(base: string, prefix: string = 'tmp-') {
6+
if (!existsSync(base)) {
7+
mkdirp(base);
8+
}
9+
return mkdtempSync(join(base, prefix));
10+
}

tasks/api.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import getReleases, {
1313
ReleaseFilter
1414
} from '../src/commands/getReleases';
1515
import { join, resolve } from 'path';
16-
import { mkdtempSync } from 'fs';
1716
import installDependencies from '../src/commands/installDependencies';
1817
import { logger } from '../src/log';
18+
import { makeTempDirectory } from '../src/util/file';
1919

2020
interface BaseOptions {
2121
dest: string;
@@ -80,10 +80,6 @@ function getFilterOptions(filter?: RemoteApiOptions['filter']): ReleaseFilter[]
8080
return [ filter ];
8181
}
8282

83-
function createTempDirectory(name: string = ''): string {
84-
return mkdtempSync(join('.sync', name));
85-
}
86-
8783
export = function (grunt: IGrunt) {
8884
async function typedocTask(this: IMultiTask<any>) {
8985
const options: any = this.options<Partial<TaskOptions>>({
@@ -101,7 +97,8 @@ export = function (grunt: IGrunt) {
10197

10298
if (isRemoteOptions(options)) {
10399
const repo = getGitHub(options.repo);
104-
const cloneDirectory = options.cloneDirectory ? options.cloneDirectory : createTempDirectory(repo.name);
100+
const cloneDirectory = options.cloneDirectory ?
101+
options.cloneDirectory : makeTempDirectory(join('.sync', repo.name));
105102
const missing = await getMissing(repo, options);
106103
const pathTemplate = format === 'json' ? getJsonApiPath : getHtmlApiPath;
107104

tests/integration/all.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
import './file';
12
import './git';
23
import './typedoc';

tests/integration/file.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as registerSuite from 'intern!object';
2+
import * as assert from 'intern/chai!assert';
3+
import { makeTempDirectory } from 'src/util/file';
4+
import { existsSync, statSync } from 'fs';
5+
6+
registerSuite({
7+
name: 'file',
8+
9+
tempDirectory() {
10+
const path = makeTempDirectory('./test');
11+
assert.isTrue(existsSync(path));
12+
assert.isTrue(statSync(path).isDirectory());
13+
}
14+
});

tests/integration/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Git from 'src/util/Git';
44
import { tmpDirectory } from '../_support/tmpFiles';
55

66
registerSuite({
7-
name: 'typedoc',
7+
name: 'git',
88

99
async build() {
1010
const out = tmpDirectory();

0 commit comments

Comments
 (0)