run.js 716 Bytes
Newer Older
vicotor's avatar
vicotor committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/env node

const fs = require('fs');
const format = require('./format-lines');

function getVersion (path) {
  try {
    return fs
      .readFileSync(path, 'utf8')
      .match(/\/\/ OpenZeppelin Contracts \(last updated v[^)]+\)/)[0];
  } catch (err) {
    return null;
  }
}

for (const [ file, template ] of Object.entries({
  'utils/math/SafeCast.sol': './templates/SafeCast',
  'mocks/SafeCastMock.sol': './templates/SafeCastMock',
})) {
  const path = `./contracts/${file}`;
  const version = getVersion(path);
  const content = format(
    '// SPDX-License-Identifier: MIT',
    (version ? version + ` (${file})\n` : ''),
    require(template).trimEnd(),
  );

  fs.writeFileSync(path, content);
}