|
- #!/usr/bin/env node
-
- if (process.argv.length < 4) {
- console.error("Usage: toSwift SRC DST");
- process.exit(1);
- }
-
- var fs = require("fs");
-
- let fileSrc = process.argv[2];
- let fileDst = process.argv[3];
-
- let replacements = {
- "function": "func",
- "number": "Float",
- "):": ") ->",
- };
-
- console.log(`Converting '${fileSrc}' to '${fileDst}'`);
-
- var linesDst = [];
- let linesSrc = fs.readFileSync(fileSrc).toString().split(/\r?\n/);
- for (let i in linesSrc) {
- let ln = linesSrc[i];
- linesDst.push(convert(ln));
- }
-
- let contentsDst = linesDst.join("\r\n");
- fs.writeFileSync(fileDst, contentsDst);
-
-
- // Functions making decisions.
-
- function convert(line) {
- var result = line;
- for (let src in replacements) {
- let dst = replacements[src];
- result = result.replace(src, dst);
- }
- return result;
- }
|