mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 21:02:33 +03:00
Move internal-only modules outside of Elm package and into generated code folders.
This commit is contained in:
parent
00e8fd82bd
commit
86eeb4cef9
9
elm.json
9
elm.json
@ -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": {
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
@ -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",
|
||||
@ -69,8 +50,66 @@ async function generate(basePath) {
|
||||
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)
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 };
|
||||
|
Loading…
Reference in New Issue
Block a user