How to use xdg-basedir - 10 common examples

To help you get started, we’ve selected a few xdg-basedir 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 TencentCloudBase / cloudbase-cli / src / utils / store / db.ts View on Github external
import os from 'os'
import fse from 'fs-extra'
import low from 'lowdb'
import path from 'path'
import FileSync from 'lowdb/adapters/FileSync'
import xdgBasedir from 'xdg-basedir'

// 系统配置目录
const configDir = xdgBasedir.config || path.join(os.tmpdir(), '.config')
// cloudbase 配置目录
const cloudbaseConfigDir = path.join(configDir, '.cloudbase')

// 确保目录存在
fse.ensureDirSync(cloudbaseConfigDir)

export function getAuthDB() {
    const dbPath = path.join(cloudbaseConfigDir, 'auth.json')
    const adapter = new FileSync(dbPath)
    const db = low(adapter)
    return db
}
github kevva / xdg-trashdir / index.js View on Github external
if (process.platform !== 'linux') {
		return Promise.reject(new Error('Only Linux systems are supported'));
	}

	if (!filePath) {
		return Promise.resolve(path.join(xdgBasedir.data, 'Trash'));
	}

	const [homeMountPoint, fileMountPoint] = await Promise.all([
		mountPoint(userHome),
		// Ignore errors in case `file` is a dangling symlink
		mountPoint(filePath).catch(() => {})
	]);

	if (!fileMountPoint || fileMountPoint === homeMountPoint) {
		return path.join(xdgBasedir.data, 'Trash');
	}

	return check(path.join(fileMountPoint, '.Trash'));
};
github facebook / flipper / static / launcher.js View on Github external
const checkIsCycle = async () => {
  const dir = path.join(xdg.cache, 'flipper');
  const filePath = path.join(dir, 'last-launcher-run');
  // This isn't monotonically increasing, so there's a change we get time drift
  // between the checks, but the worst case here is that we do two roundtrips
  // before this check works.
  const rightNow = Date.now();

  let backThen;
  try {
    backThen = parseInt(await promisify(fs.readFile)(filePath), 10);
  } catch (e) {
    backThen = 0;
  }

  const delta = rightNow - backThen;
  await promisify(mkdirp)(dir);
  await promisify(fs.writeFile)(filePath, rightNow);
github bezoerb / generator-sf / generators / backend / symfony / index.js View on Github external
symfonyBase: function () {
    const source = 'https://github.com/symfony/symfony-standard/archive/v' + this.props.commit + '.zip';
    const dest = this.destinationRoot();
    const cache = path.join(xdgBasedir.cache, 'generator-sf');

    // Will be generated from the zip
    const dirname = 'symfony-standard-' + this.props.commit;
    const log = this.log.write();

    // Check cache first
    return fs.statAsync(path.join(cache, dirname))
      .catch(() => {
        log.info('Fetching %s ...', source)
          .info(chalk.yellow('This might take a few moments'));
        return download(source, cache, {extract: true});
      })
      .then(() => {
        return fs.copyAsync(path.join(cache, dirname) + '/', dest + '/.');
      });
  },
github googleapis / nodejs-storage / test / file.ts View on Github external
get() {
    return xdgConfigOverride === false
      ? false
      : xdgConfigOverride || xdgBasedirCached.config;
  },
});
github goto-bus-stop / statusbar / packages / statusbar / cli.js View on Github external
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const xdg = require('xdg-basedir')

const config = process.argv[2] || path.join(xdg.config, 'statusbar')

if (!config) {
  console.log('Usage: statusbar ')
  process.exit(1)
}

const configPath = path.resolve(process.cwd(), config)
let configModule
try {
  configModule = require.resolve(configPath)
} catch (err) {
  console.error(`Could not find config file "${config}"`)
  process.exit(1)
}

global.bar = require('.')()
github psychokinesis-dev / free-share / app / file-store.js View on Github external
const os = require('os');
const mkdirp = require('mkdirp');
const path = require('path');
const fs = require('fs');
const splitFile = require('split-file');
const async = require('async');
const xdgBasedir = require('xdg-basedir');
const md5File = require('md5-file');
const request = require('request');
const send = require('send');

const configDir = path.join(xdgBasedir.config || path.join(os.tmpdir(), '.config'), 'freeshare');
const storeDir = path.join(xdgBasedir.data || path.join(os.tmpdir(), '.local'), 'free-share-store');

let instance = null;

class FileStore {
    constructor() {
        if (!instance) {
            instance = this;
        }

        return instance;
    }

    init() {
        this.fileMap = new Map();

        return new Promise((resolve, reject) => {
github icyflame / terminal-wallet / export-module.js View on Github external
function exportToFile (exportFilepath, printToConsole) {
  var fs = require('fs');
  var xdgBasedir = require('xdg-basedir');
  var logSymbols = require('log-symbols');

  var expensesFilepath = xdgBasedir.data + '/wallet/expenses.csv';
  var contents = fs.readFileSync(expensesFilepath);

  var prettyDate = require('date-format').asString('yyyy-MM-dd', new Date());

  var defaultExportFilepath = xdgBasedir.data +
    '/wallet/exported/export-' +
    prettyDate + '.csv';

  exportFilepath = exportFilepath || defaultExportFilepath;

  fs.writeFileSync(exportFilepath, 'Date,Remarks,Category,Credit,Debit\n');
  fs.appendFileSync(exportFilepath, contents);

  if (printToConsole === undefined) {
    console.log();
    console.log(logSymbols.success + ' Your file can be found at :-');
github ranjithprabhuk / ng2-Dashboard / node_modules / configstore / index.js View on Github external
'use strict';
var path = require('path');
var fs = require('graceful-fs');
var osenv = require('osenv');
var assign = require('object-assign');
var mkdirp = require('mkdirp');
var uuid = require('uuid');
var xdgBasedir = require('xdg-basedir');
var osTmpdir = require('os-tmpdir');
var writeFileAtomic = require('write-file-atomic');
var dotProp = require('dot-prop');

var user = (osenv.user() || uuid.v4()).replace(/\\/g, '');
var configDir = xdgBasedir.config || path.join(osTmpdir(), user, '.config');
var permissionError = 'You don\'t have access to this file.';
var defaultPathMode = parseInt('0700', 8);
var writeFileOptions = {mode: parseInt('0600', 8)};

function Configstore(id, defaults, opts) {
	opts = opts || {};

	var pathPrefix = opts.globalConfigPath ?
		path.join(id, 'config.json') :
		path.join('configstore', id + '.json');

	this.path = path.join(configDir, pathPrefix);

	this.all = assign({}, defaults || {}, this.all || {});
}

xdg-basedir

Get XDG Base Directory paths

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis