run.js 724 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const format = require('./format-lines');
  4. function getVersion (path) {
  5. try {
  6. return fs
  7. .readFileSync(path, 'utf8')
  8. .match(/\/\/ OpenZeppelin Contracts \(last updated v\d+\.\d+\.\d+\)/)[0];
  9. } catch (err) {
  10. return null;
  11. }
  12. }
  13. for (const [ file, template ] of Object.entries({
  14. 'utils/math/SafeCast.sol': './templates/SafeCast',
  15. 'mocks/SafeCastMock.sol': './templates/SafeCastMock',
  16. })) {
  17. const path = `./contracts/${file}`;
  18. const version = getVersion(path);
  19. const content = format(
  20. '// SPDX-License-Identifier: MIT',
  21. (version ? version + ` (${file})\n` : ''),
  22. require(template).trimEnd(),
  23. );
  24. fs.writeFileSync(path, content);
  25. }