-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite.js
94 lines (72 loc) · 3.34 KB
/
rewrite.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
//************************WARNING: THIS PROGRAM WRITES OVER EXISTING CONTRACT DATA**********************
// JAVASCRIPT DIRECTORY TOOLS
const path = require("path");
const isLocal = typeof process.pkg === "undefined";
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
const fs = require('fs')
console.log(basePath)
// VARIABLES TO BE REPLACED
const ContractName = "OpenPunks"
const contractName = "openPunks"
const ContractSpace = "Open Punks"
const ContractUnder = "open_punks"
// NEW VARIABLE NAMES - *** UPDATE THESE BEFORE RUNNING ***
const NewContract = "POVTexas"
const NewSpace = "POV Texas"
const newContract = "povTexas"
const setContract = "setPOVTexas"
const newPackage = "pov_texas"
const newConfig = "pov-texas"
// PATHS TO FILES NEEDING VARIABLE REWRITE
const contract = path.join(basePath, "src/contracts/OpenPunks.sol")
const newcontract = path.join(basePath, "src/contracts/", NewContract + ".sol")
const originalTest = path.join(basePath, "test/OpenPunks.test.js")
const newtest = path.join(basePath, "test/", NewContract + ".test.js")
const deployContract = path.join(basePath, "migrations/2_deploy_contracts.js")
const packagejson = path.join(basePath, "package.json")
// CONSOLE LOGS
console.log(contract + " >>> " + newcontract)
console.log(ContractName + " >>> " + NewContract)
console.log(contractName + " >>> " + newContract)
// REPLACE VARIABLES IN MAIN CONTRACT
fs.readFile(contract, 'utf8', function (err,data) {
var formatted = data.replace(/OpenPunks/g, NewContract).replace(/openPunks/g, newContract).replace(/'Open Punks'/g, ContractSpace);
fs.writeFile(newcontract, formatted, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// REPLACE VARIABLES IN TEST FILE
fs.readFile(originalTest, 'utf8', function (err,data) {
var formatted = data.replace(/OpenPunks/g, NewContract).replace(/openPunks/g, newContract).replace(/"Open Punks"/g, ContractSpace);
fs.writeFile(newtest, formatted, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// Replace VARIABLES IN 2_deploy_contracts.js
fs.readFile(deployContract, 'utf8', function (err,data) {
var formatted = data.replace(/OpenPunks/g, NewContract).replace(/openPunks/g, newContract).replace(/"Open Punks"/g, ContractSpace);
fs.writeFile(deployContract, formatted, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// REPLACE VARIABLES IN App.js
fs.readFile(path.join(basePath, "src/components/App.js"), 'utf8', function (err,data) {
var formatted = data.replace(/OpenPunks/g, NewContract).replace(/openPunks/g, newContract).replace(/"Open Punks"/g, ContractSpace).replace(/"setOpenPunks"/g, setContract);
fs.writeFile(path.join(basePath, "src/components/App.js"), formatted, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// Replace package.json
fs.readFile(packagejson, 'utf8', function (err,data) {
var formatted = data.replace(/open_punks/g, newPackage)
.replace(/openPunks/g, newContract)
.replace(/"Open Punks"/g, ContractSpace)
.replace(/"setOpenPunks"/g, setContract);
fs.writeFile(packagejson, formatted, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// Replace index.html NEEDS MANUAL
// Replace .env NEEDS MANUAL
//replace value in app.js