@nomiclabs/buidler
Version:
Buidler is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
79 lines • 2.85 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = __importDefault(require("debug"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const log = debug_1.default("buidler:core:global-dir");
async function generatePaths() {
const { default: envPaths } = await Promise.resolve().then(() => __importStar(require("env-paths")));
return envPaths("buidler");
}
async function getConfigDir() {
const { config } = await generatePaths();
await fs_extra_1.default.ensureDir(config);
return config;
}
async function getDataDir() {
const { data } = await generatePaths();
await fs_extra_1.default.ensureDir(data);
return data;
}
async function getCacheDir() {
const { cache } = await generatePaths();
await fs_extra_1.default.ensureDir(cache);
return cache;
}
async function readAnalyticsId() {
const globalDataDir = await getDataDir();
const idFile = path_1.default.join(globalDataDir, "analytics.json");
return readId(idFile);
}
exports.readAnalyticsId = readAnalyticsId;
function readLegacyAnalyticsId() {
const oldIdFile = path_1.default.join(os_1.default.homedir(), ".buidler", "config.json");
return readId(oldIdFile);
}
exports.readLegacyAnalyticsId = readLegacyAnalyticsId;
async function readId(idFile) {
log(`Looking up Client Id at ${idFile}`);
let clientId;
try {
const data = await fs_extra_1.default.readJSON(idFile, { encoding: "utf8" });
clientId = data.analytics.clientId;
}
catch (error) {
return null;
}
log(`Client Id found: ${clientId}`);
return clientId;
}
async function writeAnalyticsId(clientId) {
const globalDataDir = await getDataDir();
const idFile = path_1.default.join(globalDataDir, "analytics.json");
await fs_extra_1.default.writeJSON(idFile, {
analytics: {
clientId,
},
}, { encoding: "utf-8" });
log(`Stored clientId ${clientId}`);
}
exports.writeAnalyticsId = writeAnalyticsId;
async function getCompilersDir() {
const cache = await getCacheDir();
const compilersCache = path_1.default.join(cache, "compilers");
await fs_extra_1.default.ensureDir(compilersCache);
return compilersCache;
}
exports.getCompilersDir = getCompilersDir;
//# sourceMappingURL=global-dir.js.map
;