@expo/xdl
Version:
The Expo Development Library
161 lines (118 loc) • 4.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _jsonFile() {
const data = _interopRequireDefault(require("@expo/json-file"));
_jsonFile = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = _interopRequireDefault(require("fs-extra"));
_fsExtra = function () {
return data;
};
return data;
}
function _path() {
const data = _interopRequireDefault(require("path"));
_path = function () {
return data;
};
return data;
}
function _uuid() {
const data = _interopRequireDefault(require("uuid"));
_uuid = function () {
return data;
};
return data;
}
function Env() {
const data = _interopRequireWildcard(require("./Env"));
Env = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const SETTINGS_FILE_NAME = 'state.json';
function userSettingsFile() {
const dir = dotExpoHomeDirectory();
const file = _path().default.join(dir, SETTINGS_FILE_NAME);
try {
// move exponent.json to state.json
const oldFile = _path().default.join(dir, 'exponent.json');
if (_fsExtra().default.statSync(oldFile).isFile()) {
_fsExtra().default.renameSync(oldFile, file);
}
} catch (e) {// no old directory, continue
}
return file;
}
function userSettingsJsonFile() {
return new (_jsonFile().default)(userSettingsFile(), {
jsonParseErrorDefault: {},
cantReadFileDefault: {}
});
}
let mkdirped = false;
function dotExpoHomeDirectory() {
let dirPath;
if (process.env.__UNSAFE_EXPO_HOME_DIRECTORY) {
dirPath = process.env.__UNSAFE_EXPO_HOME_DIRECTORY;
} else {
const home = Env().home();
if (!home) {
throw new Error("Can't determine your home directory; make sure your $HOME environment variable is set.");
}
if (process.env.EXPO_STAGING) {
dirPath = _path().default.join(home, '.expo-staging');
} else if (process.env.EXPO_LOCAL) {
dirPath = _path().default.join(home, '.expo-local');
} else {
dirPath = _path().default.join(home, '.expo');
}
try {
// move .exponent to .expo
const oldDirPath = _path().default.join(home, '.exponent');
if (_fsExtra().default.statSync(oldDirPath).isDirectory()) {
_fsExtra().default.renameSync(oldDirPath, dirPath);
}
} catch (e) {// no old directory, continue
}
}
if (!mkdirped) {
_fsExtra().default.mkdirpSync(dirPath);
mkdirped = true;
}
return dirPath;
} // returns an anonymous, unique identifier for a user on the current computer
async function anonymousIdentifier() {
const settings = await userSettingsJsonFile();
let id = await settings.getAsync('uuid', null);
if (!id) {
id = _uuid().default.v4();
await settings.setAsync('uuid', id);
}
return id;
}
function accessToken() {
return process.env.EXPO_TOKEN || null;
}
const UserSettings = Object.assign(userSettingsJsonFile(), {
dotExpoHomeDirectory,
userSettingsFile,
userSettingsJsonFile,
accessToken,
anonymousIdentifier,
SETTINGS_FILE_NAME
});
var _default = UserSettings;
exports.default = _default;
//# sourceMappingURL=__sourcemaps__/UserSettings.js.map