Skip to content

Commit

Permalink
Merge pull request #260 from dillonkearns/move-internals-outside-package
Browse files Browse the repository at this point in the history
Move internals outside package
  • Loading branch information
dillonkearns authored Dec 11, 2021
2 parents fd04b17 + 6327087 commit d51b9f0
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 34 deletions.
9 changes: 2 additions & 7 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
"Pages.Secrets",
"Pages.Manifest",
"Pages.Manifest.Category",
"Pages.Flags",
"Pages.Internal.Platform",
"Pages.Internal.Platform.Cli",
"Pages.Internal.Router",
"Pages.Internal.RoutePattern",
"Pages.Internal.NotFoundReason"
"Pages.Flags"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
Expand Down Expand Up @@ -58,4 +53,4 @@
"avh4/elm-program-test": "3.1.0 <= v < 4.0.0",
"elm-explorations/test": "1.2.2 <= v < 2.0.0"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 66 additions & 27 deletions generator/src/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,17 @@ async function generate(basePath) {
ensureDirSync("./elm-stuff/elm-pages/.elm-pages");

const uiFileContent = elmPagesUiFile();

await Promise.all([
fs.promises.copyFile(
path.join(__dirname, `./Page.elm`),
`./.elm-pages/Page.elm`
),
copyToBoth("Page.elm"),
copyToBoth("SharedTemplate.elm"),
copyToBoth("SiteConfig.elm"),

fs.promises.writeFile("./.elm-pages/Pages.elm", uiFileContent),
fs.promises.copyFile(
path.join(__dirname, `./elm-application.json`),
`./elm-stuff/elm-pages/elm-application.json`
),
fs.promises.copyFile(
path.join(__dirname, `./Page.elm`),
`./elm-stuff/elm-pages/.elm-pages/Page.elm`
),
fs.promises.copyFile(
path.join(__dirname, `./SharedTemplate.elm`),
`./.elm-pages/SharedTemplate.elm`
),
fs.promises.copyFile(
path.join(__dirname, `./SharedTemplate.elm`),
`./elm-stuff/elm-pages/.elm-pages/SharedTemplate.elm`
),
fs.promises.copyFile(
path.join(__dirname, `./SiteConfig.elm`),
`./.elm-pages/SiteConfig.elm`
),
fs.promises.copyFile(
path.join(__dirname, `./SiteConfig.elm`),
`./elm-stuff/elm-pages/.elm-pages/SiteConfig.elm`
),
fs.promises.writeFile("./.elm-pages/Pages.elm", uiFileContent),
// write `Pages.elm` with cli interface
fs.promises.writeFile(
"./elm-stuff/elm-pages/.elm-pages/Pages.elm",
Expand All @@ -67,10 +48,68 @@ async function generate(basePath) {
browserCode.mainModule
),
fs.promises.writeFile("./.elm-pages/Route.elm", browserCode.routesModule),
// write modified elm.json to elm-stuff/elm-pages/
copyModifiedElmJson(),
...(await listFiles("./Pages/Internal")).map(copyToBoth),
]);
}

/**
* @param {string} moduleToCopy
* @returns { Promise<void> }
*/
async function copyToBoth(moduleToCopy) {
await Promise.all([
fs.promises.mkdir(path.dirname(path.join(`./.elm-pages/`, moduleToCopy)), {
recursive: true,
}),
fs.promises.mkdir(
path.dirname(
path.join(`./elm-stuff/elm-pages/.elm-pages/`, moduleToCopy)
),
{ recursive: true }
),
]);
await Promise.all([
fs.promises.copyFile(
path.join(__dirname, moduleToCopy),
path.join(`./.elm-pages/`, moduleToCopy)
),
fs.promises.copyFile(
path.join(__dirname, moduleToCopy),
path.join(`./elm-stuff/elm-pages/.elm-pages/`, moduleToCopy)
),
]);
}

// write modified elm.json to elm-stuff/elm-pages/
copyModifiedElmJson();
/**
* @param {string} dir
* @returns {Promise<string[]>}
*/
async function listFiles(dir) {
const fullDir = path.join(__dirname, dir);
const files = await fs.promises.readdir(fullDir);
return merge(
await Promise.all(
files.flatMap(async (file_) => {
const file = path.join(dir, path.basename(file_));
if (
(await fs.promises.stat(path.join(__dirname, file))).isDirectory()
) {
return await listFiles(file);
} else {
return [file];
}
})
)
);
}

/**
* @param {any[]} arrays
*/
function merge(arrays) {
return [].concat.apply([], arrays);
}

module.exports = { generate };
1 change: 1 addition & 0 deletions tests/Pages/Internal

0 comments on commit d51b9f0

Please sign in to comment.