return Q.nfcall<fs.Stats>(fs.stat, p).then((stats: fs.Stats) => {
     if (stats.isDirectory()) {
         return Q.nfcall<string[]>(fs.readdir, p).then((childPaths: string[]) => {
             let result = Q<void>(void 0);
             childPaths.forEach(childPath =>
                 result = result.then<void>(() => this.removePathRecursivelyAsync(path.join(p, childPath))));
             return result;
         }).then(() =>
             Q.nfcall<void>(fs.rmdir, p));
     } else {
         /* file */
         return Q.nfcall<void>(fs.unlink, p);
     }
 });
Beispiel #2
0
    function runTest(testFileName: string) {
        const testFilePath = path.resolve(__dirname, '..', 'fixtures', testFileName);

        logger.info({testFilePath: testFilePath}, 'Running test file');

        return q.nfcall(tmp.file.bind(tmp), {postfix: '.js'})
            .spread(function(jsOutputFilePath: string) {
                logger.info({jsOutputFilePath: jsOutputFilePath, lsc: lsc}, 'Compiling to js output');
                return lsc(testFilePath, jsOutputFilePath)
                    .then(function() {
                        const command = `node ${jsOutputFilePath}`;
                        logger.info({command: command}, 'Spawning node on generated js');
                        return q.nfcall(child_process.exec.bind(child_process), command);
                    })
                    .fail(function(err: any) {
                        logger.error(err, 'lsc failed');
                        throw err;
                    });
            }).spread(function(stdout: Buffer, stderr: Buffer) {
                if (stderr.length) {
                   throw new Error(stderr.toString());
                }

                logger.info({stdout: stdout.toString()}, 'Nodejs spawn complete');
                return stdout.toString();
            });
    }
Beispiel #3
0
export function getHistoryModel(
    options,
    basePath = remote.app.getPath('userData')
) {
    let buffer: any[] = []
    let promise = q()
    const fileName = basePath + '/' + options.file
    const history = {
        push(item) {
            promise = promise.then(() => {
                buffer.splice(0, 0, item)
                if (buffer.length > options.max) {
                    buffer = buffer.slice(0, options.min)
                }
                return q.nfcall(
                    writeFile,
                    fileName,
                    buffer.map(obj => JSON.stringify(obj)).join(',')
                )
            })
            return promise
        },
        list: () => buffer,
    }
    return q.nfcall(readFile, fileName).then(
        content => {
            buffer = JSON.parse('[' + content + ']')
            return history
        },
        () => history
    )
}
Beispiel #4
0
 Q.all([Q.nfcall(fs.exists, jsconfigPath), Q.nfcall(fs.exists, tsconfigPath)]).spread((jsExists: boolean, tsExists: boolean) => {
     if (!jsExists && !tsExists) {
         Q.nfcall(fs.writeFile, jsconfigPath, "{}").then(() => {
             // Any open file must be reloaded to enable intellisense on them, so inform the user
             vscode.window.showInformationMessage("A 'jsconfig.json' file was created to enable IntelliSense. You may need to reload your open JS file(s).");
         });
     }
 });
            .then(function(exists: boolean) {
                if (!exists) {
                    return Q.nfcall(child_process.exec, `npm install --prefix ${typeScriptNextDest} typescript@next`)
                        .then(() => { return true; });
                }

                return isRestartRequired;
            });
 public findFilesByExtension(folder: string, extension: string): Q.Promise<string[]> {
     return Q.nfcall(fs.readdir, folder).then((files: string[]) => {
         const extFiles = files.filter((file: string) => path.extname(file) === `.${extension}`);
         if (extFiles.length === 0) {
             throw new Error(`Unable to find any ${extension} files.`);
         }
         return extFiles;
     });
 }
 /**
  *  Helper (asynchronous) function to check if a file or directory exists
  */
 public exists(filename: string): Q.Promise<boolean> {
     return Q.nfcall(fs.stat, filename)
         .then(function() {
             return Q.resolve(true);
         })
         .catch(function(err) {
             return Q.resolve(false);
         });
 }
Beispiel #8
0
 promise = promise.then(() => {
     buffer.splice(0, 0, item)
     if (buffer.length > options.max) {
         buffer = buffer.slice(0, options.min)
     }
     return q.nfcall(
         writeFile,
         fileName,
         buffer.map(obj => JSON.stringify(obj)).join(',')
     )
 })
 public static getBundleIdentifier(projectRoot: string): Q.Promise<string> {
     return Q.nfcall(fs.readdir, path.join(projectRoot, 'platforms', 'ios')).then((files: string[]) => {
         let xcodeprojfiles = files.filter((file: string) => /\.xcodeproj$/.test(file));
         if (xcodeprojfiles.length === 0) {
             throw new Error('Unable to find xcodeproj file');
         }
         let xcodeprojfile = xcodeprojfiles[0];
         let projectName = /^(.*)\.xcodeproj/.exec(xcodeprojfile)[1];
         let plist = pl.parseFileSync(path.join(projectRoot, 'platforms', 'ios', projectName, projectName + '-Info.plist'));
         return plist.CFBundleIdentifier;
     });
 }
async function ensureNuGetDownloads(): Promise<void> {
    if (!fs.existsSync(tempDir)) {
        await Q.nfcall(fs.mkdir, tempDir);
    }

    for (let i of nuGetVersions) {
        if (!fs.existsSync(i.filePath)) {
            // tslint:disable-next-line
            console.log(`Downloading ${i.url} to ${i.filePath}`);
            await download(i.url, i.filePath);
        }
    }
}