Skip to content

Commit

Permalink
fix(unity_project): workaround to fix incorrectly-generated TS declar…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
toverux committed May 16, 2017
1 parent e42870d commit def2363
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/unity_project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logger } from '@mitm/unityinvoker';
import * as fs from 'fs-extra';
import * as fs from 'fs';
import * as fsx from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { BuildContext } from './build_context';
Expand All @@ -16,7 +17,7 @@ const CompilerScriptDest = path.resolve(`${ProjectDirectory}/Assets/Editor/Asset
function copyStreamInDirectory(fileStream: fs.ReadStream, directory: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
const fileName = path.basename(fileStream.path as string);
const fileDestStream = fs.createWriteStream(path.join(directory, fileName));
const fileDestStream = fsx.createWriteStream(path.join(directory, fileName));

fileStream.pipe(fileDestStream);

Expand All @@ -33,16 +34,16 @@ async function copyStreamsInDirectory(fileStreams: fs.ReadStream[], directory: s

export async function shouldCreateProject(): Promise<boolean> {
try {
await fs.access(ProjectDirectory, fs.constants.R_OK | fs.constants.W_OK);
await fsx.access(ProjectDirectory, fsx.constants.R_OK | fsx.constants.W_OK);
return false;
} catch (err) {
return true;
}
}

export async function copyEditorScript(): Promise<void> {
await fs.mkdirp(path.dirname(CompilerScriptDest));
await fs.copy(CompilerScriptSource, CompilerScriptDest);
await fsx.mkdirp(path.dirname(CompilerScriptDest));
await fsx.copy(CompilerScriptSource, CompilerScriptDest);
}

export async function warmupProject(context: BuildContext): Promise<void> {
Expand All @@ -51,9 +52,9 @@ export async function warmupProject(context: BuildContext): Promise<void> {
await copyEditorScript();
}

await fs.mkdir(context.editorScriptsDir);
await fs.mkdir(context.assetsDir);
await fs.mkdir(context.assetBundleDir);
await fsx.mkdir(context.editorScriptsDir);
await fsx.mkdir(context.assetsDir);
await fsx.mkdir(context.assetBundleDir);
}

export async function copyEditorScriptsInProject(
Expand Down Expand Up @@ -100,16 +101,16 @@ export async function moveGeneratedAssetBundle(
const assetBundlePath = path.resolve(`${context.assetBundleDir}/assetbundle`);

if (typeof finalDest === 'string') {
await fs.move(assetBundlePath, finalDest, { overwrite });
await fsx.move(assetBundlePath, finalDest, { overwrite });
} else if (streamMaker.isWriteStream(finalDest)) {
if (!overwrite) {
try {
await fs.access(finalDest.path);
await fsx.access(finalDest.path);
throw new Error(`File ${finalDest.path} already exists, overwrite option is false, aborting.`);
} finally { /* pass */ }
}

const assetBundleStream = fs.createReadStream(assetBundlePath);
const assetBundleStream = fsx.createReadStream(assetBundlePath);

return new Promise<void>((resolve, reject) => {
assetBundleStream.pipe(finalDest as fs.WriteStream)
Expand All @@ -120,9 +121,9 @@ export async function moveGeneratedAssetBundle(
}

export async function cleanupProject(context: BuildContext): Promise<void> {
await fs.remove(context.editorScriptsDir);
await fs.remove(context.editorScriptsDir + '.meta');
await fs.remove(context.assetsDir);
await fs.remove(context.assetsDir + '.meta');
await fs.remove(context.assetBundleDir);
await fsx.remove(context.editorScriptsDir);
await fsx.remove(context.editorScriptsDir + '.meta');
await fsx.remove(context.assetsDir);
await fsx.remove(context.assetsDir + '.meta');
await fsx.remove(context.assetBundleDir);
}

0 comments on commit def2363

Please sign in to comment.