()
| 487 | }; |
| 488 | |
| 489 | protected emitSourceStructure(): void { |
| 490 | const exports: Sourcelike[] = []; |
| 491 | let topLevelDecoders: List<Sourcelike> = List(); |
| 492 | this.forEachTopLevel("none", (_, name) => { |
| 493 | let { encoder, decoder } = defined(this._topLevelDependents.get(name)); |
| 494 | if (decoder === undefined) { |
| 495 | decoder = defined(this._namedTypeDependents.get(name)).decoder; |
| 496 | } |
| 497 | topLevelDecoders = topLevelDecoders.push(decoder); |
| 498 | exports.push(name, encoder, decoder); |
| 499 | }); |
| 500 | this.forEachClass("none", (t, name) => { |
| 501 | if (!this.topLevels.contains(t)) exports.push(name); |
| 502 | }); |
| 503 | this.forEachUnion("none", (t, name) => { |
| 504 | if (!this.topLevels.contains(t)) exports.push([name, "(..)"]); |
| 505 | }); |
| 506 | |
| 507 | this.emitMultiline(`-- To decode the JSON data, add this file to your project, run |
| 508 | -- |
| 509 | -- elm-package install NoRedInk/elm-decode-pipeline |
| 510 | -- |
| 511 | -- add these imports |
| 512 | -- |
| 513 | -- import Json.Decode exposing (decodeString)`); |
| 514 | this.emitLine( |
| 515 | "-- import ", |
| 516 | this._moduleName, |
| 517 | " exposing (", |
| 518 | intercalate(", ", topLevelDecoders).toArray(), |
| 519 | ")" |
| 520 | ); |
| 521 | this.emitMultiline(`-- |
| 522 | -- and you're off to the races with |
| 523 | --`); |
| 524 | this.forEachTopLevel("none", (_, name) => { |
| 525 | let { decoder } = defined(this._topLevelDependents.get(name)); |
| 526 | if (decoder === undefined) { |
| 527 | decoder = defined(this._namedTypeDependents.get(name)).decoder; |
| 528 | } |
| 529 | this.emitLine("-- decodeString ", decoder, " myJsonString"); |
| 530 | }); |
| 531 | this.emitNewline(); |
| 532 | |
| 533 | this.emitLine("module ", this._moduleName, " exposing"); |
| 534 | this.indent(() => { |
| 535 | for (let i = 0; i < exports.length; i++) { |
| 536 | this.emitLine(i === 0 ? "(" : ",", " ", exports[i]); |
| 537 | } |
| 538 | this.emitLine(")"); |
| 539 | }); |
| 540 | this.emitNewline(); |
| 541 | |
| 542 | this.emitMultiline(`import Json.Decode as Jdec |
| 543 | import Json.Decode.Pipeline as Jpipe |
| 544 | import Json.Encode as Jenc |
| 545 | import Dict exposing (Dict, map, toList)`); |
| 546 | if (this._useList) { |
no test coverage detected