elm-codegen
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -31,3 +31,3 @@ "use strict"; | ||
var helpText = "\nWelcome to " + chalk_1.default.cyan("elm-codegen") + "!\n\nMake sure to check out the " + chalk_1.default.yellow("guides") + ":\n https://github.com/mdgriffith/elm-codegen#check-out-the-guide\n"; | ||
program.version("0.1.0").name("elm-codegen").addHelpText("before", helpText); | ||
program.version("0.3.0").name("elm-codegen").addHelpText("before", helpText); | ||
program | ||
@@ -40,3 +40,3 @@ .command("init") | ||
.command("install") | ||
.description("\n Install helpers for an " + chalk_1.default.yellow("Elm package") + " or a local Elm file.\n " + chalk_1.default.cyan("elm-codegen install elm/json") + "\n " + chalk_1.default.cyan("elm-codegen install codegen/helpers/LocalFile.elm") + "\n") | ||
.description("\n Install helpers for an " + chalk_1.default.yellow("Elm package") + "\n " + chalk_1.default.cyan("elm-codegen install elm/json") + "\n\n or a local directory with Elm files in it.\n " + chalk_1.default.cyan("elm-codegen install codegen/helpers/") + "\n") | ||
.argument("[package]") | ||
@@ -43,0 +43,0 @@ .argument("[version]") |
@@ -438,3 +438,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var install_dir, base, codeGenJson, updatedCodeGenJson, helperPath, elmSources; | ||
var install_dir, base, codeGenJson, updatedCodeGenJson; | ||
return __generator(this, function (_a) { | ||
@@ -458,17 +458,8 @@ switch (_a.label) { | ||
fs.mkdirSync(path.join(base, "Gen", "CodeGen")); | ||
fs.mkdirSync(path.join(base, "helpers")); | ||
fs.writeFileSync(path.join(base, "elm.json"), templates_1.default.init.elmJson()); | ||
fs.writeFileSync(path.join(base, "Generate.elm"), templates_1.default.init.starter()); | ||
fs.writeFileSync(path.join(base, "Gen", "CodeGen", "Generate.elm"), templates_1.default.init.codegenProgram()); | ||
fs.writeFileSync(path.join(base, "helpers", "Helper.elm"), templates_1.default.init.helper()); | ||
return [4 /*yield*/, install_package("elm/core", install_dir, null, codeGenJson)]; | ||
case 1: | ||
updatedCodeGenJson = _a.sent(); | ||
helperPath = path.join(base, "helpers") + path.sep; | ||
elmSources = []; | ||
getFilesWithin(helperPath, ".elm").forEach(function (elmPath) { | ||
elmSources.push(fs.readFileSync(elmPath).toString()); | ||
}); | ||
run_package_generator(install_dir, { elmSource: elmSources }); | ||
updatedCodeGenJson.dependencies.local.push(helperPath); | ||
fs.writeFileSync(path.join(base, "elm.codegen.json"), codeGenJsonToString(updatedCodeGenJson)); | ||
@@ -569,29 +560,2 @@ console.log(format_block([ | ||
} | ||
function copyHelpers(codeGenJson, options) { | ||
// create output directory if it doesn't exist | ||
fs.mkdirSync(options.output, { recursive: true }); | ||
var _loop_1 = function (item) { | ||
if (item.endsWith(".elm")) { | ||
fs.writeFileSync(path.join(options.output, item), fs.readFileSync(item).toString()); | ||
} | ||
else if (item.endsWith(path.sep)) { | ||
if (fs.existsSync(item)) { | ||
getFilesWithin(item, ".elm").forEach(function (elmPath) { | ||
var relative = path.relative(item, elmPath); | ||
var targetFilePath = path.join(options.output, relative); | ||
var targetDir = path.dirname(targetFilePath); | ||
if (!fs.existsSync(targetDir)) { | ||
fs.mkdirSync(targetDir, { recursive: true }); | ||
} | ||
fs.writeFileSync(targetFilePath, fs.readFileSync(elmPath).toString()); | ||
}); | ||
} | ||
} | ||
}; | ||
// copy over all local dependencies | ||
for (var _i = 0, _a = codeGenJson.dependencies.local; _i < _a.length; _i++) { | ||
var item = _a[_i]; | ||
_loop_1(item); | ||
} | ||
} | ||
function run_install(pkg, version) { | ||
@@ -675,3 +639,2 @@ return __awaiter(this, void 0, void 0, function () { | ||
codeGenJson = getCodeGenJson(install_dir); | ||
copyHelpers(codeGenJson, options); | ||
generate(options.debug, elmFile, moduleName, options.output, options.cwd || ".", options.flags); | ||
@@ -693,3 +656,3 @@ return [2 /*return*/]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var elmFile, cwd, parsed, fullSourcePath, output, flags, parsed, moduleName, install_dir, codeGenJson; | ||
var elmFile, cwd, parsed, fullSourcePath, output, flags, parsed, moduleName; | ||
return __generator(this, function (_a) { | ||
@@ -760,10 +723,2 @@ elmFile = "Generate.elm"; | ||
moduleName = path.parse(elmFile).name; | ||
install_dir = getCodeGenJsonDir(); | ||
codeGenJson = getCodeGenJson(install_dir); | ||
copyHelpers(codeGenJson, { | ||
debug: options.debug, | ||
output: options.output, | ||
flags: flags, | ||
cwd: null, | ||
}); | ||
if (options.watch) { | ||
@@ -770,0 +725,0 @@ // clear(output) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (function () { return "\n{\n \"elm-codegen-version\": \"0.1.0\",\n \"codegen-helpers\": {\n \"packages\": {},\n \"local\": []\n }\n}\n"; }); | ||
exports.default = (function () { return "\n{\n \"elm-codegen-version\": \"0.3.0\",\n \"codegen-helpers\": {\n \"packages\": {},\n \"local\": []\n }\n}\n"; }); |
@@ -10,3 +10,2 @@ "use strict"; | ||
var ElmCodeGen_json_1 = __importDefault(require("./ElmCodeGen.json")); | ||
var Helper_elm_1 = __importDefault(require("./Helper.elm")); | ||
exports.default = { | ||
@@ -18,4 +17,3 @@ init: { | ||
elmCodegenJson: ElmCodeGen_json_1.default, | ||
helper: Helper_elm_1.default, | ||
}, | ||
}; |
{ | ||
"name": "elm-codegen", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Codegen for Elm", | ||
@@ -10,3 +10,3 @@ "main": "./dist/index.js", | ||
"scripts": { | ||
"test": "npm run test:install ; elm-test", | ||
"test": "npm run test:install && elm make --docs=docs.json && elm-review && elm-test", | ||
"test:install": "npm run build; cd tests; node ../bin/elm-codegen install", | ||
@@ -54,2 +54,5 @@ "test:pkg-generation": "npm run build; cd tests/package-tests; ts-node run.ts", | ||
"@types/node-fetch": "^2.5.10", | ||
"elm": "^0.19.1-5", | ||
"elm-review": "^2.7.5", | ||
"elm-test": "^0.19.1-revision9", | ||
"ts-node": "^10.9.1", | ||
@@ -56,0 +59,0 @@ "typescript": "^4.2.4" |
@@ -44,2 +44,3 @@ # Elm CodeGen | ||
- [Using packages/helpers](https://github.com/mdgriffith/elm-codegen/tree/main/guide/UsingHelpers.md) | ||
- [Running via TypeScript](https://github.com/mdgriffith/elm-codegen/tree/main/guide/UsingElmCodeGenInTypeScript.md) | ||
@@ -46,0 +47,0 @@ And finally, the [elm-codegen package documentation](https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/). |
Sorry, the diff of this file is too big to display
59
884503
7
15
27588