Run elm code to get manifest config.

This commit is contained in:
Dillon Kearns 2019-08-19 15:58:55 -07:00
parent 61e3a26c0f
commit 6f4cdc1b05
3 changed files with 56 additions and 43 deletions

View File

@ -33,8 +33,8 @@ class AddFilesPlugin {
}
module.exports = { start, run };
function start({ routes, debug }) {
const config = webpackOptions(false, routes, { debug });
function start({ routes, debug, manifestConfig }) {
const config = webpackOptions(false, routes, { debug, manifestConfig });
const compiler = webpack(config);
const options = {
@ -52,27 +52,31 @@ function start({ routes, debug }) {
});
}
function run({ routes, fileContents }, callback) {
webpack(webpackOptions(true, routes, { debug: false, fileContents })).run(
(err, stats) => {
if (err) {
console.error(err);
process.exit(1);
} else {
callback();
}
console.log(
stats.toString({
chunks: false, // Makes the build much quieter
colors: true // Shows colors in the console
})
);
function run({ routes, fileContents, manifestConfig }, callback) {
webpack(
webpackOptions(true, routes, { debug: false, fileContents, manifestConfig })
).run((err, stats) => {
if (err) {
console.error(err);
process.exit(1);
} else {
callback();
}
);
console.log(
stats.toString({
chunks: false, // Makes the build much quieter
colors: true // Shows colors in the console
})
);
});
}
function webpackOptions(production, routes, { debug, fileContents }) {
function webpackOptions(
production,
routes,
{ debug, fileContents, manifestConfig }
) {
const common = {
entry: { hello: "./index.js" },
mode: production ? "production" : "development",
@ -126,20 +130,20 @@ function webpackOptions(production, routes, { debug, fileContents }) {
logo: path.resolve(process.cwd(), "./icon.svg"),
favicons: {
path: "/", // Path for overriding default icons path. `string`
appName: null, // Your application's name. `string`
appShortName: null, // Your application's short_name. `string`. Optional. If not set, appName will be used
appDescription: null, // Your application's description. `string`
appName: manifestConfig.name, // Your application's name. `string`
appShortName: manifestConfig.short_name, // Your application's short_name. `string`. Optional. If not set, appName will be used
appDescription: manifestConfig.description, // Your application's description. `string`
developerName: null, // Your (or your developer's) name. `string`
developerURL: null, // Your (or your developer's) URL. `string`
dir: "auto", // Primary text direction for name, short_name, and description
lang: "en-US", // Primary language for name and short_name
background: "#fff", // Background colour for flattened icons. `string`
theme_color: "#fff", // Theme color user for example in Android's task switcher. `string`
background: manifestConfig.background_color, // Background colour for flattened icons. `string`
theme_color: manifestConfig.theme_color, // Theme color user for example in Android's task switcher. `string`
appleStatusBarStyle: "black-translucent", // Style for Apple status bar: "black-translucent", "default", "black". `string`
display: "standalone", // Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser". `string`
orientation: "any", // Default orientation: "any", "natural", "portrait" or "landscape". `string`
scope: "/", // set of URLs that the browser considers within your app
start_url: "/?homescreen=1", // Start URL when launching the application from a device. `string`
display: manifestConfig.display, // Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser". `string`
orientation: manifestConfig.orientation, // Default orientation: "any", "natural", "portrait" or "landscape". `string`
scope: manifestConfig.serviceworker.scope, // set of URLs that the browser considers within your app
start_url: manifestConfig.start_url, // Start URL when launching the application from a device. `string`
version: "1.0", // Your application's version string. `string`
logging: false, // Print logs to console? `boolean`
pixel_art: false, // Keeps pixels "sharp" when scaling up, for pixel art. Only supported in offline mode.

View File

@ -8,6 +8,7 @@ const develop = require("./develop.js");
const chokidar = require("chokidar");
const matter = require("gray-matter");
const runElm = require("./compile-elm.js");
const doCliStuff = require("./generate-elm-stuff.js");
const contentGlobPath = "content/**/*.emu";
@ -59,15 +60,25 @@ function run() {
fs.writeFileSync("./gen/RawContent.elm", contents.rawContent);
fs.writeFileSync("./src/js/image-assets.js", contents.imageAssets);
console.log("elm-pages DONE");
if (contents.watch) {
startWatchIfNeeded();
develop.start({ routes: contents.routes, debug: contents.debug });
} else {
develop.run(
{ routes: contents.routes, fileContents: contents.fileContents },
() => {}
);
}
doCliStuff(contents.rawContent, function(manifestConfig) {
if (contents.watch) {
startWatchIfNeeded();
develop.start({
routes: contents.routes,
debug: contents.debug,
manifestConfig
});
} else {
develop.run(
{
routes: contents.routes,
fileContents: contents.fileContents,
manifestConfig
},
() => {}
);
}
});
});
}

View File

@ -47,7 +47,7 @@ application config =
}
`;
module.exports = function run() {
module.exports = function run(rawContentFile, callback) {
// mkdir -p elm-stuff/elm-pages/
// requires NodeJS >= 10.12.0
fs.mkdirSync("./elm-stuff/elm-pages", { recursive: true });
@ -56,13 +56,11 @@ module.exports = function run() {
fs.writeFileSync("./elm-stuff/elm-pages/PagesNew.elm", elmPagesCliFile);
// generate RawContent.elm
// TODO
fs.writeFileSync("./elm-stuff/elm-pages/RawContent.elm", rawContentFile);
// write modified elm.json to elm-stuff/elm-pages/
copyModifiedElmJson();
// run Main.elm from elm-stuff/elm-pages with `runElm`
runElm(function(payload) {
console.log("Received payload!", payload);
});
runElm(callback);
};