How to use jsonfile - 10 common examples

To help you get started, we’ve selected a few jsonfile 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 SAP / chevrotain / scripts / pre_release_build.js View on Github external
)
    process.exit(-1)
}

var oldVersion = config.currVersion
var newVersion = semver.inc(config.currVersion, config.mode)

var bumpedPkgJson = _.clone(config.pkgJson)
bumpedPkgJson.version = newVersion
var oldVersionRegExpGlobal = new RegExp(oldVersion, "g")
var bumpedApiString = config.apiString.replace(
    oldVersionRegExpGlobal,
    newVersion
)

jf.writeFileSync(config.packagePath, bumpedPkgJson, { spaces: 2 })
fs.writeFileSync(config.versionPath, bumpedApiString)

// updating CHANGELOG.md date
var nowDate = new Date()
var nowDateString = nowDate.toLocaleDateString("en-US").replace(/\//g, "-")
var changeLogDate = config.changeLogString.replace(
    dateTemplateRegExp,
    "## " + newVersion + " " + "(" + nowDateString + ")"
)
fs.writeFileSync(config.changeLogPath, changeLogDate)

var docsOldVersionRegExp = new RegExp(oldVersion.replace(/\./g, "_"), "g")
_.forEach(config.docFilesPaths, function(currDocPath) {
    console.log("bumping file: <" + currDocPath + ">")
    var currItemContents = fs.readFileSync(currDocPath, "utf8").toString()
    var bumpedItemContents = currItemContents.replace(
github krhoyt / IBM / bluemix / websocket / server / app.js View on Github external
// Constant
var BARCODE_REMOVE = 'barcode_remove';
var BARCODE_SHOW = 'barcode_show';
var BUILDINGS_VALUE = 'buildings';
var CHAT_CREATE = 'create_chat';
var CHAT_READ_ALL = 'read_all_chat';
var PETROLPAL_VALUE = 'petropal';
var PHOTOCELL_VALUE = 'photocell';
var TETRIS_DOWN = 'tetris_down';
var TETRIS_JOIN = 'tetris_join';
var TETRIS_UP = 'tetris_up';

// Environment
var environment = cfenv.getAppEnv();
var configuration = jsonfile.readFileSync( path.join( __dirname, 'configuration.json' ) );

// Database
mongoose.connect( configuration.compose );

mongoose.connection.on( 'connected', function() {
    console.log( 'Connected to Compose.' );
} );

// Models
var Chat = require( path.join( __dirname, 'models/chat' ) );

// Web
var app = express();

// Middleware
app.use( parser.json() );
github mukesh-kumar1905 / al / lib / tasks / addp.js View on Github external
export default function(path){
  // add path to current paths
  const paths = json.readFileSync(join(cwd, 'path.json'));
  if (paths.indexOf(path) !== -1){
    console.log(red(`Path ${path} already exists in paths`));
    return;
  }
  paths.push(path);
  json.writeFileSync(join(cwd, 'path.json'), paths, {spaces: 2});

  // give instruction on how to load
  console.log(yellow(`Added ${path} to paths config`));
  console.log(`Run ${green('al load')} to load config`);
}
github Esri / arcgis-rest-js / demos / ago-node-cli / lib / item-export-command.js View on Github external
.then((maybeData) => {
      if (maybeData) {
        model.data = maybeData;
      }
      // now write out the file...
      jsonfile.writeFileSync(fileName, model,  {spaces: 2});
      console.info(`Done. Exported "${model.item.title}" to ${fileName}`);
    })
    .catch((err) => {
github Whitevinyl / ARP / js / node / _SCHEDULER.js View on Github external
else {
                    t = timeSlot('day');
                }
                ev = {
                    action: action,
                    time: t + (dayTime*h)
                };
                events.push(ev);
            }
        }
    }


    // WRITE IT //
    var s = writeSchedule(time,events);
    jsonfile.writeFile(file, s, function(err) {
        if (err) {
            console.log("failed to write new schedule window");
        } else {
            console.log("written new schedule window");
        }
    });
}
github Whitevinyl / ARP / js / node / _SCHEDULER.js View on Github external
function checkSchedule() {
    console.log('checking schedule...');

    // READ SCHEDULE JSON //
    jsonfile.readFile(file, function(err, obj) {
        if (err) {
            console.log('schedule read error');
        } else {


            // IF WE'RE DUE A NEW SCHEDULE WINDOW //
            var time = new Date();
            var rescheduling = false;
            if (obj.reschedule) {
                var rescheduleTime = new Date(obj.reschedule);
                if (time > rescheduleTime) {
                    rescheduling = true;
                }
            } else {
                console.log('obj.reschedule not found');
                rescheduling = true;
github SteeltoeOSS / Steeltoe / scripts / patch-project-json.js View on Github external
var buildNumber = version.substring(lastDash + 1, version.length);
var num = "00000000" + parseInt(buildNumber);
buildNumber = num.substr(num.length-5);  

var dependsVersion = version.substring(0, lastDash) + '-*';
    
if (tag) {
    // Turn version into tag, dependsVersion = version
    version = tag;
    dependsVersion = version;
} else {
    version = version.substring(0, lastDash) + '-' + buildNumber;
}    
    

jsonfile.readFile(file, function (err, project) {
    
    if (err)
        console.error(err);

    console.log("Version: " + version);
    console.log("Dependency Version: " + dependsVersion);
    
    // Patch the project.version 
    project.version = version;

    // Patch dependencies
    if (project.dependencies['Steeltoe.CloudFoundry.Connector'] ) {
        project.dependencies['Steeltoe.CloudFoundry.Connector'] = dependsVersion;
    }

    if (project.dependencies['Steeltoe.Extensions.Configuration.CloudFoundry']) {
github gatsbyjs / gatsby / packages / gatsby-telemetry / src / telemetry.js View on Github external
getGatsbyCliVersion() {
    try {
      const jsonfile = join(
        require
          .resolve(`gatsby-cli`) // Resolve where current gatsby-cli would be loaded from.
          .split(sep)
          .slice(0, -2) // drop lib/index.js
          .join(sep),
        `package.json`
      )
      const { version } = require(jsonfile).version
      return version
    } catch (e) {
      // ignore
    }
    return undefined
  }
  captureEvent(type = ``, tags = {}, opts = { debounce: false }) {
github joelpurra / talkie / src / split-environments / node / manifest-provider.js View on Github external
getSync() {
        // NOTE: making sure it's a synchronous call.
        // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/getManifest
        if (this.manifest === null) {
            /* eslint-disable no-sync */
            this.manifest = jsonfile.readFileSync(MANIFEST_FILENAME);
            /* eslint-enable no-sync */
        }

        return this.manifest;
    }
}
github krhoyt / IBM / shackcaddy / server / app.js View on Github external
// Constants
var ESRI_GEOCODE = 'find';
var ESRI_REVERSE = 'reverseGeocode';
var ESRI_URI = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer';
var LANGUAGE = 'en-US';
var UNITS = 'e';
var WEATHER_CURRENT = 'api/weather/v2/observations/current';
var WEATHER_FORECAST = 'api/weather/v2/forecast/daily/10day';

// Load Weahter Insight credentials
// From Bluemix configuration or local file
if( process.env.VCAP_SERVICES ) {
    var environment = JSON.parse( process.env.VCAP_SERVICES );
    var credentials = environment['weatherinsights'][0].credentials;    
} else {
    var credentials = jsonfile.readFileSync( 'configuration.json' );
}

// Authentication
passport.use( new ImfBackendStrategy() );

// Web server
var app = express();
app.use( passport.initialize() );

// Root redirects to public content
app.get( '/', function( req, res ) {
	res.sendfile( 'public/index.html' );
} );

// Public static content
app.use( '/public', express.static( __dirname + '/public' ) );