How to use load-json-file - 10 common examples

To help you get started, we’ve selected a few load-json-file examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Turfjs / turf / scripts / update-export-default-typescript.js View on Github external
glob.sync(path.join(__dirname, '..', 'packages', 'turf-*', 'index.js')).forEach(filepath => {
    let index = fs.readFileSync(filepath, 'utf8');
    const dir = path.parse(filepath).dir;
    const pckg = load.sync(path.join(dir, 'package.json'));
    const name = camelcase(pckg.name).replace('@turf/', '');

    // Modules without named export function
    if (index.includes('export default function (')) {
        // duplicate function names
        if (index.includes('function ' + name)) {
            throw new Error('duplicate function name', name);
        }
        index = index.replace('export default function (', `function ${name}(`);
        index += `\nexport default ${name};`;
        index += `\nmodule.exports.default = ${name};\n`;
        fs.writeFileSync(filepath, index);
    }
    // Modules with named export function
    if (index.includes(`export default function ${name}(`)) {
        index = index.replace(`export default function ${name}(`, `function ${name}(`);
github webiny / webiny-js / packages / api-page-builder / src / plugins / graphql / installResolver / install.js View on Github external
}

    const { step } = args;

    try {
        if (!installation.stepAvailable(step)) {
            return new ErrorResponse({
                code: "PB_INSTALL_ABORTED",
                message: `Installation step ${step} not available or already executed.`
            });
        }

        if (step === 1) {
            // /tmp/installation-files/apiPageBuilder/data/categoriesData.json'","
            const INSTALL_EXTRACT_DIR = await downloadInstallationFiles();
            const categoriesData = await loadJson(
                path.join(INSTALL_EXTRACT_DIR, "data/categoriesData.json")
            );
            installation.getStep(1).markAsStarted();
            const staticPageCount = await PbCategory.count({ query: { slug: "static" } });
            if (staticPageCount === 0) {
                for (let i = 0; i < categoriesData.length; i++) {
                    const instance = new PbCategory();
                    await instance.populate(categoriesData[i]).save();
                }
            }

            installation.getStep(1).markAsCompleted();
            await settings.save();
            return new Response(true);
        }
github apifytech / apify-cli / test / commands / push.js View on Github external
it('should work without actorId', async () => {
        const apifyJson = loadJson.sync('apify.json');
        apifyJson.env = {
            MY_ENV_VAR: 'envVarValue',
        };
        writeJson.sync('apify.json', apifyJson);

        await command.run(['push']);

        const userInfo = await getLocalUserInfo();
        const { name } = apifyJson;
        const actorId = `${userInfo.username}/${name}`;
        const createdActor = await testUserClient.acts.getAct({ actId: actorId });
        const createdActorVersion = await testUserClient.acts.getActVersion({
            actId: actorId,
            versionNumber: apifyJson.version,
        });
        const store = await testUserClient.keyValueStores.getOrCreateStore({ storeName: UPLOADS_STORE_NAME });
github lerna / lerna / test / Command.js View on Github external
it("is set from lerna.json config", async () => {
        const lernaJsonLocation = path.join(testDir, "lerna.json");
        const lernaConfig = await loadJsonFile(lernaJsonLocation);
        lernaConfig.loglevel = "warn";
        await writeJsonFile(lernaJsonLocation, lernaConfig, { indent: 2 });

        const ok = new OkCommand([], {}, testDir);
        await ok.run();

        expect(log.level).toBe("warn");
      });
    });
github zeit / now / test / unit.js View on Github external
test('`now.files` overrides `.gitignore` in Docker', async t => {
  const path = 'now-json-docker-gitignore-override';
  let files = await getDockerFiles(
    fixture(path),
    await loadJSON(getLocalConfigPath(fixture(path)))
  );
  files = files.sort(alpha);

  t.is(files.length, 5);
  t.is(base(files[0]), `${path}/Dockerfile`);
  t.is(base(files[1]), `${path}/a.js`);
  t.is(base(files[2]), `${path}/b.js`);
  t.is(base(files[3]), `${path}/build/a/c.js`);
  t.is(base(files[4]), `${path}/now.json`);
});
github lerna / lerna / test / Command.js View on Github external
it("should be added to the instance", async () => {
      const command = new Command([], {});
      const { version } = await loadJsonFile(path.resolve(__dirname, "../package.json"));
      expect(command.lernaVersion).toEqual(version);
    });
  });
github illarionvk / demo-wizard-state-machine / public / data / test-bicycles.js View on Github external
map(function(listingItem) {
        const { id } = listingItem

        return loadJsonFile(path.join(__dirname, './bicycles', `${id}.json`))
      }, bicycleListing)
    )
github webiny / webiny-js / packages / webiny-cli / src / apps / build.js View on Github external
module.exports = async ({ name }) => {
    const { env, ssr } = await getAppConfig(name);

    const cwd = path.resolve(`packages/${name}`);
    await execa("yarn", ["build"], {
        cwd,
        env: { ...env, REACT_APP_ENV: "browser" },
        stdio: "inherit"
    });

    if (ssr) {
        const pkg = loadJson.sync(path.join(cwd, "package.json"));
        if (!get(pkg, "scripts.build:ssr")) {
            logger.error(
                `%s doesn't have a script "build:ssr"! This script is mandatory for SSR enabled apps.`,
                name
            );
            process.exit(1);
        }

        await execa("yarn", ["build:ssr"], {
            cwd,
            env: { ...env, REACT_APP_ENV: "ssr" },
            stdio: "inherit"
        });
    }
};
github Turfjs / turf / src / boolean-equal / bench.js View on Github external
glob.sync(path.join(__dirname, 'test', '**', '*.geojson')).forEach(filepath => {
    const {name} = path.parse(filepath);
    const geojson = load.sync(filepath);
    const [feature1, feature2] = geojson.features;
    console.time(name);
    equal(feature1, feature2);
    console.timeEnd(name);
    suite.add(name, () => equal(feature1, feature2));
});
github Turfjs / turf / src / directional-mean / bench.js View on Github external
glob.sync(path.join(__dirname, 'test', 'in', '*.json')).forEach(filepath => {
    const { name } = path.parse(filepath);
    const geojson = load.sync(filepath);
    if (name === 'bus_route_gps.json') {
        console.time(name);
        directionalMean(geojson, {
            planar: false
        })
        console.timeEnd(name);
        console.time(name + ' segment');
        directionalMean(geojson, {
            planar: false,
            segment: true
        })
        console.timeEnd(name + ' segment');
        suite.add(name, () => directionalMean(geojson, {
            planar: false,
        }));
        suite.add(name + ' segment', () => directionalMean(geojson, {

load-json-file

Read and parse a JSON file

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis