How to use the @truffle/config.detect function in @truffle/config

To help you get started, we’ve selected a few @truffle/config 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 trufflesuite / truffle / packages / truffle-db / bin / server.js View on Github external
const { ApolloServer } = require("apollo-server");

const { TruffleDB } = require("truffle-db");
const Config = require("@truffle/config");

const port = 4444;

const config = Config.detect({
  workingDirectory: process.argv[2] || process.cwd()
});

if (!config.db.enabled) {
  console.log("Experimental truffle-db feature is disabled.");
  process.exit(0);
}

const db = new TruffleDB({
  contracts_build_directory: config.contracts_build_directory,
  contracts_directory: config.contracts_directory,
  working_directory: config.working_directory
});

const { schema, context } = db;
github trufflesuite / truffle / packages / core / lib / commands / migrate.js View on Github external
run: function(options, done) {
    const Artifactor = require("@truffle/artifactor");
    const Resolver = require("@truffle/resolver");
    const Migrate = require("@truffle/migrate");
    const Contracts = require("@truffle/workflow-compile");
    const Provider = require("@truffle/provider");
    const { Environment } = require("@truffle/environment");
    const Config = require("@truffle/config");
    const temp = require("temp").track();
    const { promisify } = require("util");
    const promisifiedCopy = promisify(require("../copy"));

    const conf = Config.detect(options);

    Contracts.compile(conf)
      .then(async () => {
        await Provider.testConnection(conf);
        await Environment.detect(conf);

        const {
          dryRunOnly,
          dryRunAndMigrations
        } = command.determineDryRunSettings(conf, options);

        if (dryRunOnly) {
          conf.dryRun = true;
          await setupDryRunEnvironmentThenRunMigrations(conf);
        } else if (dryRunAndMigrations) {
          const currentBuild = conf.contracts_build_directory;
github trufflesuite / truffle / packages / migrate / index.js View on Github external
assemble: function(options) {
    const config = Config.detect(options);

    if (
      fs.existsSync(config.migrations_directory) &&
      fs.readdirSync(config.migrations_directory).length > 0
    ) {
      const files = dir.files(config.migrations_directory, { sync: true });
      if (!files) return [];

      let migrations = files
        .filter(file => isNaN(parseInt(path.basename(file))) === false)
        .filter(
          file =>
            path.extname(file).match(config.migrations_file_extension_regexp) !=
            null
        )
        .map(file => new Migration(file, Migrate.reporter, config));
github trufflesuite / truffle / packages / core / lib / commands / migrate.js View on Github external
prepareConfigForRealMigrations: async function(buildDir, options) {
    const Artifactor = require("@truffle/artifactor");
    const Resolver = require("@truffle/resolver");
    const Migrate = require("@truffle/migrate");
    const { Environment } = require("@truffle/environment");
    const Config = require("@truffle/config");

    let accept = true;

    if (options.interactive) {
      accept = await Migrate.acceptDryRun();
    }

    if (accept) {
      const config = Config.detect(options);

      config.contracts_build_directory = buildDir;
      config.artifactor = new Artifactor(buildDir);
      config.resolver = new Resolver(config);

      try {
        await Environment.detect(config);
      } catch (error) {
        throw new Error(error);
      }

      config.dryRun = false;
      return { config, proceed: true };
    } else {
      return { proceed: false };
    }
github trufflesuite / truffle / packages / truffle-db / src / loaders / artifacts / index.ts View on Github external
contracts.map(async ({ contractName, bytecode }) => {
        const name = contractName.toString().concat(".json");
        const artifactsNetworksPath = fse.readFileSync(
          path.join(artifacts, name)
        );
        const artifactsNetworks = JSON.parse(artifactsNetworksPath.toString())
          .networks;
        let configNetworks = [];
        if (Object.keys(artifactsNetworks).length) {
          const config = Config.detect({ workingDirectory: workingDirectory });
          for (let network of Object.keys(config.networks)) {
            config.network = network;
            await Environment.detect(config);
            let networkId;
            let web3;
            try {
              web3 = new Web3(config.provider);
              networkId = await web3.eth.net.getId();
            } catch (err) {}

            if (networkId) {
              let filteredNetwork = Object.entries(artifactsNetworks).filter(
                network => network[0] == networkId
              );
              //assume length of filteredNetwork is 1 -- shouldn't have multiple networks with same id in one contract
              if (filteredNetwork.length > 0) {
github trufflesuite / truffle / packages / core / lib / commands / networks.js View on Github external
run: function(options, done) {
    var Config = require("@truffle/config");
    var Networks = require("../networks");

    var config = Config.detect(options);

    if (options.clean) {
      Networks.clean(config, done);
    } else {
      Networks.display(config, done);
    }
  }
};

@truffle/config

Utility for interacting with truffle-config.js files

MIT
Latest version published 1 year ago

Package Health Score

53 / 100
Full package analysis