133 lines
3.8 KiB
JavaScript
133 lines
3.8 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
// returns an anonymous, unique identifier for a user on the current computer
|
|
let anonymousIdentifier = (() => {
|
|
var _ref = _asyncToGenerator(function* () {
|
|
const settings = yield userSettingsJsonFile();
|
|
let id = yield settings.getAsync('uuid', null);
|
|
|
|
if (!id) {
|
|
id = (_uuid || _load_uuid()).default.v4();
|
|
yield settings.setAsync('uuid', id);
|
|
}
|
|
|
|
return id;
|
|
});
|
|
|
|
return function anonymousIdentifier() {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
})();
|
|
|
|
var _fs = _interopRequireDefault(require('fs'));
|
|
|
|
var _uuid;
|
|
|
|
function _load_uuid() {
|
|
return _uuid = _interopRequireDefault(require('uuid'));
|
|
}
|
|
|
|
var _jsonFile;
|
|
|
|
function _load_jsonFile() {
|
|
return _jsonFile = _interopRequireDefault(require('@expo/json-file'));
|
|
}
|
|
|
|
var _mkdirp;
|
|
|
|
function _load_mkdirp() {
|
|
return _mkdirp = _interopRequireDefault(require('mkdirp'));
|
|
}
|
|
|
|
var _path = _interopRequireDefault(require('path'));
|
|
|
|
var _Env;
|
|
|
|
function _load_Env() {
|
|
return _Env = _interopRequireWildcard(require('./Env'));
|
|
}
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
|
|
|
const SETTINGS_FILE_NAME = 'state.json';
|
|
|
|
function userSettingsFile() {
|
|
let dir = dotExpoHomeDirectory();
|
|
let file = _path.default.join(dir, SETTINGS_FILE_NAME);
|
|
try {
|
|
// move exponent.json to state.json
|
|
let oldFile = _path.default.join(dir, 'exponent.json');
|
|
if (_fs.default.statSync(oldFile).isFile()) {
|
|
_fs.default.renameSync(oldFile, file);
|
|
}
|
|
} catch (e) {
|
|
// no old directory, continue
|
|
}
|
|
return file;
|
|
}
|
|
|
|
function userSettingsJsonFile() {
|
|
return new (_jsonFile || _load_jsonFile()).default(userSettingsFile(), {
|
|
jsonParseErrorDefault: {},
|
|
cantReadFileDefault: {}
|
|
});
|
|
}
|
|
|
|
function recentExpsJsonFile() {
|
|
return new (_jsonFile || _load_jsonFile()).default(_path.default.join(dotExpoHomeDirectory(), 'xde-recent-exps.json'), {
|
|
jsonParseErrorDefault: [],
|
|
cantReadFileDefault: []
|
|
});
|
|
}
|
|
|
|
var mkdirped = false;
|
|
function dotExpoHomeDirectory() {
|
|
let dirPath;
|
|
if (process.env.__UNSAFE_EXPO_HOME_DIRECTORY) {
|
|
dirPath = process.env.__UNSAFE_EXPO_HOME_DIRECTORY;
|
|
} else {
|
|
const home = (_Env || _load_Env()).home();
|
|
if (!home) {
|
|
throw new Error("Can't determine your home directory; make sure your $HOME environment variable is set.");
|
|
}
|
|
dirPath = _path.default.join(home, '.expo');
|
|
|
|
try {
|
|
// move .exponent to .expo
|
|
let oldDirPath = _path.default.join(home, '.exponent');
|
|
if (_fs.default.statSync(oldDirPath).isDirectory()) {
|
|
_fs.default.renameSync(oldDirPath, dirPath);
|
|
}
|
|
} catch (e) {
|
|
// no old directory, continue
|
|
}
|
|
}
|
|
if (!mkdirped) {
|
|
(_mkdirp || _load_mkdirp()).default.sync(dirPath);
|
|
mkdirped = true;
|
|
}
|
|
return dirPath;
|
|
}
|
|
|
|
const UserSettings = userSettingsJsonFile();
|
|
|
|
Object.assign(UserSettings, {
|
|
dotExpoHomeDirectory,
|
|
recentExpsJsonFile,
|
|
userSettingsFile,
|
|
userSettingsJsonFile,
|
|
anonymousIdentifier,
|
|
SETTINGS_FILE_NAME
|
|
});
|
|
|
|
exports.default = UserSettings;
|
|
//# sourceMappingURL=__sourcemaps__/UserSettings.js.map
|