UNPKG

truffle

Version:

Truffle - Simple development framework for Ethereum

678 lines (549 loc) 17.5 kB
#!/usr/bin/env node /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 89664: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const path = __webpack_require__(71017); const fse = __webpack_require__(55674); const templates = { test: { filename: path.join(__dirname, "templates", "example.js"), variable: "example" }, contract: { filename: path.join(__dirname, "templates", "Example.sol"), name: "Example", license: "MIT", variable: "example" }, migration: { filename: path.join(__dirname, "templates", "migration.js") } }; const replaceContents = (filePath, find, replacement) => { const data = fse.readFileSync(filePath, { encoding: "utf8" }); if (typeof find === "string") { find = new RegExp(find, "g"); } const result = data.replace(find, replacement); fse.writeFileSync(filePath, result, { encoding: "utf8" }); }; const toUnderscoreFromCamel = (string) => { string = string.replace(/([A-Z])/g, function ($1) { return "_" + $1.toLowerCase(); }); if (string[0] === "_") { string = string.substring(1); } return string; }; // getLicense return the license property value from Truffle config first and // in case that the file doesn't exist it will fallback to package.json const getLicense = (options) => { try { const license = (__webpack_require__(20553).detect)(options).license; if (license) { return license; } } catch (err) { console.log(err); } try { return __webpack_require__(76775)(path.join(process.cwd(), "package.json")).license; } catch {} }; const Create = { contract: function (directory, name, options) { const from = templates.contract.filename; const to = path.join(directory, name + ".sol"); if (!options.force && fse.existsSync(to)) { throw new Error("Can not create " + name + ".sol: file exists"); } fse.copySync(from, to); replaceContents(to, templates.contract.name, name); const license = getLicense(options); if (license) { replaceContents(to, templates.contract.license, license); } }, test: function (directory, name, options) { let underscored = toUnderscoreFromCamel(name); underscored = underscored.replace(/\./g, "_"); const from = templates.test.filename; const to = path.join(directory, underscored + ".js"); if (!options.force && fse.existsSync(to)) { throw new Error("Can not create " + underscored + ".js: file exists"); } fse.copySync(from, to); replaceContents(to, templates.contract.name, name); replaceContents(to, templates.contract.variable, underscored); }, migration: function (directory, name, options) { let underscored = toUnderscoreFromCamel(name || ""); underscored = underscored.replace(/\./g, "_"); const from = templates.migration.filename; let filename = (new Date().getTime() / 1000) | 0; // Only do seconds. if (name != null && name !== "") { filename += "_" + underscored; } filename += ".js"; const to = path.join(directory, filename); if (!options.force && fse.existsSync(to)) { throw new Error("Can not create " + filename + ": file exists"); } fse.copySync(from, to); } }; module.exports = Create; /***/ }), /***/ 42957: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = { run: __webpack_require__(59442), meta: __webpack_require__(46038) }; /***/ }), /***/ 46038: /***/ ((module) => { module.exports = { command: "create", description: "Helper to create new contracts, migrations and tests", builder: { all: { type: "boolean", default: false }, force: { type: "boolean", default: false } }, help: { usage: "truffle create <artifact_type> <ArtifactName>", options: [ { option: "<artifact_type>", description: "Create a new artifact where artifact_type is one of the following: " + "contract, migration,\n test or all. The new artifact is created " + "along with one (or all) of the following\n files: `contracts/ArtifactName.sol`, " + "`migrations/####_artifact_name.js` or\n `tests/artifact_name.js`. (required)" }, { option: "<ArtifactName>", description: "Name of new artifact. (required)" } ], allowedGlobalOptions: [] } }; /***/ }), /***/ 59442: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = async function (options) { const Config = __webpack_require__(20553); const ConfigurationError = __webpack_require__(48937); const create = __webpack_require__(89664); const config = Config.detect(options); let type = config.type; if (type == null && config._.length > 0) { type = config._[0]; } let name = config.name; if (name == null && config._.length > 1) { name = config._[1]; } if (type == null) { throw new ConfigurationError( "Please specify the type of item to create. Example: truffle create contract MyContract" ); } if (name == null) { throw new ConfigurationError( "Please specify the name of item to create. Example: truffle create contract MyContract" ); } if (!/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) { throw new ConfigurationError( `The name ${name} is invalid. Please enter a valid name using alpha-numeric characters.` ); } const fn = create[type]; const destinations = { contract: config.contracts_directory, migration: config.migrations_directory, test: config.test_directory }; if (type === "all") { for (const key of Object.keys(destinations)) { await create[key](destinations[key], name, options); } return; } else if (fn == null) { throw new ConfigurationError(`Cannot find creation type: ${type}`); } else { return create[type](destinations[type], name, options); } }; /***/ }), /***/ 48937: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var TruffleError = __webpack_require__(73321); class ConfigurationError extends TruffleError { constructor(message) { super(message); } } module.exports = ConfigurationError; /***/ }), /***/ 76775: /***/ ((module) => { function webpackEmptyContext(req) { var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } webpackEmptyContext.keys = () => ([]); webpackEmptyContext.resolve = webpackEmptyContext; webpackEmptyContext.id = 76775; module.exports = webpackEmptyContext; /***/ }), /***/ 44516: /***/ ((module) => { "use strict"; module.exports = require("original-require"); /***/ }), /***/ 39491: /***/ ((module) => { "use strict"; module.exports = require("assert"); /***/ }), /***/ 50852: /***/ ((module) => { "use strict"; module.exports = require("async_hooks"); /***/ }), /***/ 14300: /***/ ((module) => { "use strict"; module.exports = require("buffer"); /***/ }), /***/ 32081: /***/ ((module) => { "use strict"; module.exports = require("child_process"); /***/ }), /***/ 22057: /***/ ((module) => { "use strict"; module.exports = require("constants"); /***/ }), /***/ 6113: /***/ ((module) => { "use strict"; module.exports = require("crypto"); /***/ }), /***/ 82361: /***/ ((module) => { "use strict"; module.exports = require("events"); /***/ }), /***/ 57147: /***/ ((module) => { "use strict"; module.exports = require("fs"); /***/ }), /***/ 13685: /***/ ((module) => { "use strict"; module.exports = require("http"); /***/ }), /***/ 95687: /***/ ((module) => { "use strict"; module.exports = require("https"); /***/ }), /***/ 41808: /***/ ((module) => { "use strict"; module.exports = require("net"); /***/ }), /***/ 22037: /***/ ((module) => { "use strict"; module.exports = require("os"); /***/ }), /***/ 71017: /***/ ((module) => { "use strict"; module.exports = require("path"); /***/ }), /***/ 85477: /***/ ((module) => { "use strict"; module.exports = require("punycode"); /***/ }), /***/ 63477: /***/ ((module) => { "use strict"; module.exports = require("querystring"); /***/ }), /***/ 14521: /***/ ((module) => { "use strict"; module.exports = require("readline"); /***/ }), /***/ 12781: /***/ ((module) => { "use strict"; module.exports = require("stream"); /***/ }), /***/ 71576: /***/ ((module) => { "use strict"; module.exports = require("string_decoder"); /***/ }), /***/ 24404: /***/ ((module) => { "use strict"; module.exports = require("tls"); /***/ }), /***/ 76224: /***/ ((module) => { "use strict"; module.exports = require("tty"); /***/ }), /***/ 57310: /***/ ((module) => { "use strict"; module.exports = require("url"); /***/ }), /***/ 73837: /***/ ((module) => { "use strict"; module.exports = require("util"); /***/ }), /***/ 59796: /***/ ((module) => { "use strict"; module.exports = require("zlib"); /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ id: moduleId, /******/ loaded: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = __webpack_modules__; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = __webpack_module_cache__; /******/ /******/ // the startup function /******/ __webpack_require__.x = () => { /******/ // Load entry module and return exports /******/ var __webpack_exports__ = __webpack_require__.O(undefined, [5158,9129,5674,4957,553], () => (__webpack_require__(42957))) /******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__); /******/ return __webpack_exports__; /******/ }; /******/ /************************************************************************/ /******/ /* webpack/runtime/amd options */ /******/ (() => { /******/ __webpack_require__.amdO = {}; /******/ })(); /******/ /******/ /* webpack/runtime/chunk loaded */ /******/ (() => { /******/ var deferred = []; /******/ __webpack_require__.O = (result, chunkIds, fn, priority) => { /******/ if(chunkIds) { /******/ priority = priority || 0; /******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1]; /******/ deferred[i] = [chunkIds, fn, priority]; /******/ return; /******/ } /******/ var notFulfilled = Infinity; /******/ for (var i = 0; i < deferred.length; i++) { /******/ var [chunkIds, fn, priority] = deferred[i]; /******/ var fulfilled = true; /******/ for (var j = 0; j < chunkIds.length; j++) { /******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) { /******/ chunkIds.splice(j--, 1); /******/ } else { /******/ fulfilled = false; /******/ if(priority < notFulfilled) notFulfilled = priority; /******/ } /******/ } /******/ if(fulfilled) { /******/ deferred.splice(i--, 1) /******/ var r = fn(); /******/ if (r !== undefined) result = r; /******/ } /******/ } /******/ return result; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/ensure chunk */ /******/ (() => { /******/ __webpack_require__.f = {}; /******/ // This file contains only the entry chunk. /******/ // The chunk loading function for additional chunks /******/ __webpack_require__.e = (chunkId) => { /******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => { /******/ __webpack_require__.f[key](chunkId, promises); /******/ return promises; /******/ }, [])); /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/get javascript chunk filename */ /******/ (() => { /******/ // This function allow to reference async chunks and sibling chunks for the entrypoint /******/ __webpack_require__.u = (chunkId) => { /******/ // return url for filenames based on template /******/ return "" + chunkId + ".bundled.js"; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/node module decorator */ /******/ (() => { /******/ __webpack_require__.nmd = (module) => { /******/ module.paths = []; /******/ if (!module.children) module.children = []; /******/ return module; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/require chunk loading */ /******/ (() => { /******/ // no baseURI /******/ /******/ // object to store loaded chunks /******/ // "1" means "loaded", otherwise not loaded yet /******/ var installedChunks = { /******/ 886: 1 /******/ }; /******/ /******/ __webpack_require__.O.require = (chunkId) => (installedChunks[chunkId]); /******/ /******/ var installChunk = (chunk) => { /******/ var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime; /******/ for(var moduleId in moreModules) { /******/ if(__webpack_require__.o(moreModules, moduleId)) { /******/ __webpack_require__.m[moduleId] = moreModules[moduleId]; /******/ } /******/ } /******/ if(runtime) runtime(__webpack_require__); /******/ for(var i = 0; i < chunkIds.length; i++) /******/ installedChunks[chunkIds[i]] = 1; /******/ __webpack_require__.O(); /******/ }; /******/ /******/ // require() chunk loading for javascript /******/ __webpack_require__.f.require = (chunkId, promises) => { /******/ // "1" is the signal for "already loaded" /******/ if(!installedChunks[chunkId]) { /******/ if(true) { // all chunks have JS /******/ installChunk(require("./" + __webpack_require__.u(chunkId))); /******/ } else installedChunks[chunkId] = 1; /******/ } /******/ }; /******/ /******/ // no external install chunk /******/ /******/ // no HMR /******/ /******/ // no HMR manifest /******/ })(); /******/ /******/ /* webpack/runtime/startup chunk dependencies */ /******/ (() => { /******/ var next = __webpack_require__.x; /******/ __webpack_require__.x = () => { /******/ __webpack_require__.e(5158); /******/ __webpack_require__.e(9129); /******/ __webpack_require__.e(5674); /******/ __webpack_require__.e(4957); /******/ __webpack_require__.e(553); /******/ return next(); /******/ }; /******/ })(); /******/ /************************************************************************/ /******/ /******/ // module cache are used so entry inlining is disabled /******/ // run startup /******/ var __webpack_exports__ = __webpack_require__.x(); /******/ var __webpack_export_target__ = exports; /******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i]; /******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true }); /******/ /******/ })() ; //# sourceMappingURL=create.bundled.js.map