How to use the default function from fs-extra

Find comprehensive JavaScript fs-extra.default code examples handpicked from public code repositorys.

49
50
51
52
53
54
55
56
57
58
const uuid_1 = require("uuid");
const validate_1 = require("./validate");
function cleanup(intermediateOutputDirectory, logger) {
    logger.info('\n\nCleaning up...');
    if (fs_extra_1.default.existsSync(intermediateOutputDirectory)) {
        const tempDirectory = fs_extra_1.default.mkdtempSync(path.join(os_1.default.tmpdir(), `coda-packs-${(0, uuid_1.v4)()}`));
        fs_extra_1.default.moveSync(intermediateOutputDirectory, path.join(tempDirectory, 'build'));
        logger.info(`Intermediate files are moved to ${tempDirectory}`);
    }
}
fork icon18
star icon68
watch icon16

+ 47 other calls in file

93
94
95
96
97
98
99
100
101
102
function writeFile(path, data) {
    const normalizedPath = normalizePath(path);
    if (!exists(path_1.dirname(normalizedPath))) {
        createDir(path_1.dirname(normalizedPath));
    }
    fs_extra_1.default.writeFileSync(normalizedPath, data);
    // update cache
    existsCache.set(normalizedPath, true);
    if (readDirCache.has(path_1.dirname(normalizedPath))) {
        readDirCache.delete(path_1.dirname(normalizedPath));
fork icon0
star icon0
watch icon1

+ 31 other calls in file

60
61
62
63
64
65
66
67
68
69
function getVueEmbeddedSource(fileName) {
    if (!fs_extra_1.default.existsSync(fileName)) {
        return undefined;
    }
    const compiler = loadVueTemplateCompiler();
    const vueSourceText = fs_extra_1.default.readFileSync(fileName, { encoding: 'utf-8' });
    let script;
    if (isVueTemplateCompilerV2(compiler)) {
        const parsed = compiler.parseComponent(vueSourceText, {
            pad: 'space',
fork icon0
star icon0
watch icon1

+ 3 other calls in file

83
84
85
86
87
88
89
90
91
92
    });
}
// Copied from the eslint 6 implementation, as it's not available in eslint 8
function directoryExists(resolvedPath) {
    try {
        return fs_extra_1.default.statSync(resolvedPath).isDirectory();
    }
    catch (error) {
        if (error && error.code === 'ENOENT') {
            return false;
fork icon0
star icon0
watch icon1

+ 3 other calls in file

172
173
174
175
176
177
178
179
180
181
if (fs_extra_1.default.existsSync(`${root}/node_modules/${template}`)) {
    fs_extra_1.default.copySync(`${root}/node_modules/${template}`, root);
}
try {
    if (fs_extra_1.default.existsSync(`${root}/package.json`)) {
        const raw = fs_extra_1.default.readFileSync(`${root}/package.json`, 'utf-8');
        const json = JSON.parse(raw);
        json.name = appName;
        json.version = "0.0.1";
        json.private = true;
fork icon0
star icon0
watch icon2

+ 5 other calls in file

199
200
201
202
203
204
205
206
207
208
    runErrors.push(e_4);
    return [3, 21];
case 21:
    if (outputReport) {
        reportPath = path_1.default.resolve(process.cwd(), "./".concat(constants_1.PKG_NAME, "-report.json"));
        fs_extra_1.default.outputFile(reportPath, JSON.stringify(results, null, 2), function () { });
    }
    return [2, {
            results: results,
            errorCount: results.reduce(function (count, _a) {
fork icon0
star icon0
watch icon1

+ 23 other calls in file

141
142
143
144
145
146
147
148
149
150
                    try {
                        if (willRemovePackage_1_1 && !willRemovePackage_1_1.done && (_b = willRemovePackage_1.return)) _b.call(willRemovePackage_1);
                    }
                    finally { if (e_2) throw e_2.error; }
                }
                fs_extra_1.default.writeFileSync(path_1.default.resolve(cwd, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
                return [2, pkg];
        }
    });
}); });
fork icon0
star icon0
watch icon1

+ 23 other calls in file

164
165
166
167
168
169
170
171
172
173
const getPageData = pagePath => {
  const pageDataPath = getPageDataPath(pagePath);

  const absolutePageDataPath = _path.default.join(publicDir, pageDataPath);

  const pageDataJson = _fsExtra.default.readFileSync(absolutePageDataPath, `utf8`);

  try {
    return JSON.parse(pageDataJson);
  } catch (err) {
fork icon0
star icon0
watch icon1

+ 9 other calls in file

364
365
366
367
368
369
370
371
372
373
        }
    });
}
async function readOpenapiFiles(openapiPath) {
    if (!(0, index_1.isURL)(openapiPath)) {
        const stat = await fs_extra_1.default.lstat(openapiPath);
        if (stat.isDirectory()) {
            // TODO: Add config for inlcude/ignore
            const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
                cwd: openapiPath,
fork icon0
star icon0
watch icon1

+ 8 other calls in file

77
78
79
80
81
82
83
84
85
86
const unescapeHtml_1 = __importDefault(require("./unescapeHtml"));
exports.unescapeHtml = unescapeHtml_1.default;
const chalk_1 = __importDefault(require("chalk"));
exports.chalk = chalk_1.default;
const fs_extra_1 = __importDefault(require("fs-extra"));
exports.fs = fs_extra_1.default;
const path_1 = __importDefault(require("path"));
exports.path = path_1.default;
const globby_1 = __importDefault(require("globby"));
exports.globby = globby_1.default;
fork icon0
star icon0
watch icon1

+ 4 other calls in file

61
62
63
64
65
66
67
68
69
70
    }
    finally {
        if (fs_1.default.existsSync(dest)) {
            fs_1.default.rmdirSync(dest, { recursive: true });
        }
        fs_extra_1.default.moveSync(tmpDir, dest);
    }
};
const runPrebuildAndCreateNwjsProject = function (opts, callback) {
    child_process_1.default.execSync("npm run nwjs:prebuild --if-present", { cwd: opts.projectDir, stdio: 'inherit', encoding: 'utf-8' });
fork icon0
star icon0
watch icon1

+ 39 other calls in file

550
551
552
553
554
555
556
557
558
559
  pathName = "/index.html";
} else if (url.length > 2 && url[1] === "client") {
  pathName = url.join("/").replace("/client", "");
}
const extName = import_path.default.extname(pathName);
import_fs_extra.default.readFile(`./static${pathName}`, function(err, data) {
  if (err) {
    console.error(err);
    res.status(400).json(err);
  } else {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)