mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-01 07:45:22 +03:00
Remove webpack dependencies! 🎉
This commit is contained in:
parent
c581591114
commit
c9c63b8a3b
37236
examples/docs/package-lock.json
generated
37236
examples/docs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,207 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var spawn = require("cross-spawn");
|
||||
var _ = require("lodash");
|
||||
var elmBinaryName = "elm";
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var temp = require("temp").track();
|
||||
var findAllDependencies = require("find-elm-dependencies").findAllDependencies;
|
||||
|
||||
var defaultOptions = {
|
||||
spawn: spawn,
|
||||
cwd: undefined,
|
||||
pathToElm: undefined,
|
||||
help: undefined,
|
||||
output: undefined,
|
||||
report: undefined,
|
||||
debug: undefined,
|
||||
verbose: false,
|
||||
processOpts: undefined,
|
||||
docs: undefined,
|
||||
optimize: undefined,
|
||||
};
|
||||
|
||||
var supportedOptions = _.keys(defaultOptions);
|
||||
|
||||
function prepareSources(sources) {
|
||||
if (!(sources instanceof Array || typeof sources === "string")) {
|
||||
throw "compile() received neither an Array nor a String for its sources argument.";
|
||||
}
|
||||
|
||||
return typeof sources === "string" ? [sources] : sources;
|
||||
}
|
||||
|
||||
function prepareOptions(options, spawnFn) {
|
||||
return _.defaults({ spawn: spawnFn }, options, defaultOptions);
|
||||
}
|
||||
|
||||
function prepareProcessArgs(sources, options) {
|
||||
var preparedSources = prepareSources(sources);
|
||||
var compilerArgs = compilerArgsFromOptions(options);
|
||||
|
||||
return ["make"].concat(preparedSources ? preparedSources.concat(compilerArgs) : compilerArgs);
|
||||
}
|
||||
|
||||
function prepareProcessOpts(options) {
|
||||
var env = _.merge({ LANG: 'en_US.UTF-8' }, process.env);
|
||||
return _.merge({ env: env, stdio: "inherit", cwd: options.cwd }, options.processOpts);
|
||||
|
||||
}
|
||||
|
||||
function runCompiler(sources, options, pathToElm) {
|
||||
if (typeof options.spawn !== "function") {
|
||||
throw "options.spawn was a(n) " + (typeof options.spawn) + " instead of a function.";
|
||||
}
|
||||
|
||||
var processArgs = prepareProcessArgs(sources, options);
|
||||
var processOpts = prepareProcessOpts(options);
|
||||
|
||||
if (options.verbose) {
|
||||
console.log(["Running", pathToElm].concat(processArgs).join(" "));
|
||||
}
|
||||
|
||||
return options.spawn(pathToElm, processArgs, processOpts);
|
||||
}
|
||||
|
||||
function compilerErrorToString(err, pathToElm) {
|
||||
if ((typeof err === "object") && (typeof err.code === "string")) {
|
||||
switch (err.code) {
|
||||
case "ENOENT":
|
||||
return "Could not find Elm compiler \"" + pathToElm + "\". Is it installed?";
|
||||
|
||||
case "EACCES":
|
||||
return "Elm compiler \"" + pathToElm + "\" did not have permission to run. Do you need to give it executable permissions?";
|
||||
|
||||
default:
|
||||
return "Error attempting to run Elm compiler \"" + pathToElm + "\":\n" + err;
|
||||
}
|
||||
} else if ((typeof err === "object") && (typeof err.message === "string")) {
|
||||
return JSON.stringify(err.message);
|
||||
} else {
|
||||
return "Exception thrown when attempting to run Elm compiler " + JSON.stringify(pathToElm);
|
||||
}
|
||||
}
|
||||
|
||||
function compileSync(sources, options) {
|
||||
var optionsWithDefaults = prepareOptions(options, options.spawn || spawn.sync);
|
||||
var pathToElm = options.pathToElm || elmBinaryName;
|
||||
|
||||
try {
|
||||
return runCompiler(sources, optionsWithDefaults, pathToElm);
|
||||
} catch (err) {
|
||||
throw compilerErrorToString(err, pathToElm);
|
||||
}
|
||||
}
|
||||
|
||||
function compile(sources, options) {
|
||||
var optionsWithDefaults = prepareOptions(options, options.spawn || spawn);
|
||||
var pathToElm = options.pathToElm || elmBinaryName;
|
||||
|
||||
|
||||
try {
|
||||
return runCompiler(sources, optionsWithDefaults, pathToElm)
|
||||
.on('error', function (err) { throw (err); });
|
||||
} catch (err) {
|
||||
throw compilerErrorToString(err, pathToElm);
|
||||
}
|
||||
}
|
||||
|
||||
function getSuffix(outputPath, defaultSuffix) {
|
||||
if (outputPath) {
|
||||
return path.extname(outputPath) || defaultSuffix;
|
||||
} else {
|
||||
return defaultSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
// write compiled Elm to a string output
|
||||
// returns a Promise which will contain a Buffer of the text
|
||||
// If you want html instead of js, use options object to set
|
||||
// output to a html file instead
|
||||
// creates a temp file and deletes it after reading
|
||||
function compileToString(sources, options) {
|
||||
var suffix = getSuffix(options.output, '.js');
|
||||
return new Promise(function (resolve, reject) {
|
||||
temp.open({ suffix: suffix }, function (err, info) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
options.output = info.path;
|
||||
options.processOpts = { stdio: 'inherit' };
|
||||
var compiler;
|
||||
try {
|
||||
compiler = compile(sources, options);
|
||||
}
|
||||
catch (compileError) {
|
||||
return reject(compileError);
|
||||
}
|
||||
compiler.on("close", function (exitCode) {
|
||||
if (exitCode !== 0) {
|
||||
return reject('Compilation failed');
|
||||
}
|
||||
else if (options.verbose) {
|
||||
console.log(output);
|
||||
}
|
||||
fs.readFile(info.path, { encoding: "utf8" }, function (err, data) {
|
||||
return err ? reject(err) : resolve(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function compileToStringSync(sources, options) {
|
||||
const suffix = getSuffix(options.output, '.js');
|
||||
|
||||
const file = temp.openSync({ suffix });
|
||||
options.output = file.path;
|
||||
compileSync(sources, options);
|
||||
|
||||
return fs.readFileSync(file.path, { encoding: "utf8" });
|
||||
}
|
||||
|
||||
// Converts an object of key/value pairs to an array of arguments suitable
|
||||
// to be passed to child_process.spawn for elm-make.
|
||||
function compilerArgsFromOptions(options) {
|
||||
return _.flatten(_.map(options, function (value, opt) {
|
||||
if (value) {
|
||||
switch (opt) {
|
||||
case "help": return ["--help"];
|
||||
case "output": return ["--output", value];
|
||||
case "report": return ["--report", value];
|
||||
case "debug": return ["--debug"];
|
||||
case "docs": return ["--docs", value];
|
||||
case "optimize": return ["--optimize"];
|
||||
case "runtimeOptions": return [].concat(["+RTS"], value, ["-RTS"]);
|
||||
default:
|
||||
if (supportedOptions.indexOf(opt) === -1) {
|
||||
if (opt === "yes") {
|
||||
throw new Error('node-elm-compiler received the `yes` option, but that was removed in Elm 0.19. Try re-running without passing the `yes` option.');
|
||||
} else if (opt === "warn") {
|
||||
throw new Error('node-elm-compiler received the `warn` option, but that was removed in Elm 0.19. Try re-running without passing the `warn` option.');
|
||||
} else if (opt === "pathToMake") {
|
||||
throw new Error('node-elm-compiler received the `pathToMake` option, but that was renamed to `pathToElm` in Elm 0.19. Try re-running after renaming the parameter to `pathToElm`.');
|
||||
} else {
|
||||
throw new Error('node-elm-compiler was given an unrecognized Elm compiler option: ' + opt);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
compile: compile,
|
||||
compileSync: compileSync,
|
||||
compileWorker: require("./worker")(compile),
|
||||
compileToString: compileToString,
|
||||
compileToStringSync: compileToStringSync,
|
||||
findAllDependencies: findAllDependencies,
|
||||
_prepareProcessArgs: prepareProcessArgs
|
||||
};
|
@ -1,128 +0,0 @@
|
||||
var temp = require("temp").track();
|
||||
var path = require("path");
|
||||
var jsEmitterFilename = "emitter.js";
|
||||
|
||||
var KNOWN_MODULES =
|
||||
[
|
||||
"fullscreen",
|
||||
"embed",
|
||||
"worker",
|
||||
"Basics",
|
||||
"Maybe",
|
||||
"List",
|
||||
"Array",
|
||||
"Char",
|
||||
"Color",
|
||||
"Transform2D",
|
||||
"Text",
|
||||
"Graphics",
|
||||
"Debug",
|
||||
"Result",
|
||||
"Task",
|
||||
"Signal",
|
||||
"String",
|
||||
"Dict",
|
||||
"Json",
|
||||
"Regex",
|
||||
"VirtualDom",
|
||||
"Html",
|
||||
"Css"
|
||||
];
|
||||
|
||||
|
||||
// elmModuleName is optional, and is by default inferred based on the filename.
|
||||
module.exports = function (compile) {
|
||||
return function (projectRootDir, modulePath, moduleName, workerArgs) {
|
||||
var originalWorkingDir = process.cwd();
|
||||
process.chdir(projectRootDir);
|
||||
|
||||
return createTmpDir()
|
||||
.then(function (tmpDirPath) {
|
||||
var dest = path.join(tmpDirPath, jsEmitterFilename);
|
||||
|
||||
return compileEmitter(compile, modulePath, { output: dest })
|
||||
.then(function () { return runWorker(dest, moduleName, workerArgs) });
|
||||
})
|
||||
.then(function (worker) {
|
||||
process.chdir(originalWorkingDir);
|
||||
return worker;
|
||||
})
|
||||
.catch(function (err) {
|
||||
process.chdir(originalWorkingDir);
|
||||
throw Error(err);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
function createTmpDir() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
temp.mkdir("node-elm-compiler", function (err, tmpDirPath) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(tmpDirPath);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function suggestModulesNames(Elm) {
|
||||
return Object.keys(Elm).filter(function (key) {
|
||||
return KNOWN_MODULES.indexOf(key) === -1;
|
||||
})
|
||||
}
|
||||
|
||||
function missingEntryModuleMessage(moduleName, Elm) {
|
||||
var errorMessage = "I couldn't find the entry module " + moduleName + ".\n";
|
||||
var suggestions = suggestModulesNames(Elm);
|
||||
|
||||
if (suggestions.length > 1) {
|
||||
errorMessage += "\nMaybe you meant one of these: " + suggestions.join(",");
|
||||
} else if (suggestions.length === 1) {
|
||||
errorMessage += "\nMaybe you meant: " + suggestions;
|
||||
}
|
||||
|
||||
errorMessage += "\nYou can pass me a different module to use with --module=<moduleName>";
|
||||
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
function noPortsMessage(moduleName) {
|
||||
var errorMessage = "The module " + moduleName + " doesn't expose any ports!\n";
|
||||
|
||||
errorMessage += "\n\nTry adding something like";
|
||||
errorMessage += "port foo : Value\nport foo =\n someValue\n\nto " + moduleName + "!";
|
||||
|
||||
return errorMessage.trim();
|
||||
}
|
||||
|
||||
function runWorker(jsFilename, moduleName, workerArgs) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var Elm = require(jsFilename).Elm;
|
||||
|
||||
if (!(moduleName in Elm)) {
|
||||
return reject(missingEntryModuleMessage(moduleName, Elm));
|
||||
}
|
||||
|
||||
var worker = Elm[moduleName].init(workerArgs);
|
||||
|
||||
if (Object.keys(worker.ports).length === 0) {
|
||||
return reject(noPortsMessage(moduleName));
|
||||
}
|
||||
|
||||
return resolve(worker);
|
||||
});
|
||||
}
|
||||
|
||||
function compileEmitter(compile, src, options) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
compile(src, options)
|
||||
.on("close", function (exitCode) {
|
||||
if (exitCode === 0) {
|
||||
resolve(exitCode);
|
||||
} else {
|
||||
reject("Errored with exit code " + exitCode);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
const { compileToStringSync } = require("../node-elm-compiler/index.js");
|
||||
XMLHttpRequest = require("xhr2");
|
||||
|
||||
module.exports = runElm;
|
||||
function runElm(/** @type string */ mode) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const elmBaseDirectory = "./elm-stuff/elm-pages";
|
||||
const mainElmFile = "../../src/Main.elm";
|
||||
const startingDir = process.cwd();
|
||||
process.chdir(elmBaseDirectory);
|
||||
const data = compileToStringSync([mainElmFile], {});
|
||||
process.chdir(startingDir);
|
||||
(function () {
|
||||
const warnOriginal = console.warn;
|
||||
console.warn = function () { };
|
||||
eval(data.toString());
|
||||
const app = Elm.Main.init({
|
||||
flags: { secrets: process.env, mode, staticHttpCache: global.staticHttpCache }
|
||||
});
|
||||
|
||||
app.ports.toJsPort.subscribe((/** @type {{tag: string; args: ['Success' | 'Errors']}} */ payload) => {
|
||||
|
||||
if (payload.tag === "Success") {
|
||||
global.staticHttpCache = payload.args[0].staticHttpCache;
|
||||
resolve(payload.args[0])
|
||||
} else if (payload.command === "log") {
|
||||
console.log(payload.value);
|
||||
} else {
|
||||
reject(payload.args[0])
|
||||
}
|
||||
delete Elm;
|
||||
console.warn = warnOriginal;
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
});
|
||||
}
|
@ -2,7 +2,6 @@ const path = require("path");
|
||||
const dir = "content/";
|
||||
const glob = require("glob");
|
||||
const fs = require("fs");
|
||||
const sharp = require("sharp");
|
||||
const parseFrontmatter = require("./frontmatter.js");
|
||||
|
||||
// Because we use node-glob, we must use `/` as a separator on all platforms. See https://github.com/isaacs/node-glob#windows
|
||||
|
37
package.json
37
package.json
@ -21,42 +21,14 @@
|
||||
"author": "Dillon Kearns",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"babel-loader": "^8.0.6",
|
||||
"copy-webpack-plugin": "^5.0.4",
|
||||
"cross-spawn": "7.0.3",
|
||||
"css-loader": "^3.2.0",
|
||||
"elm": "^0.19.1-3",
|
||||
"elm-hot-webpack-loader": "^1.1.2",
|
||||
"elm-optimize-level-2": "^0.1.4",
|
||||
"elm-webpack-loader": "^6.0.0",
|
||||
"express": "^4.17.1",
|
||||
"favicons-webpack-plugin": "^3.0.0",
|
||||
"file-loader": "^4.2.0",
|
||||
"find-elm-dependencies": "2.0.2",
|
||||
"globby": "^10.0.1",
|
||||
"gray-matter": "^4.0.2",
|
||||
"html-webpack-plugin": "^4.2.0",
|
||||
"imagemin-mozjpeg": "^8.0.0",
|
||||
"imagemin-webpack-plugin": "^2.4.2",
|
||||
"lodash": "4.17.19",
|
||||
"micromatch": "^4.0.2",
|
||||
"node-sass": "^4.12.0",
|
||||
"prerender-spa-plugin": "^3.4.0",
|
||||
"raw-loader": "^4.0.0",
|
||||
"sass-loader": "^8.0.0",
|
||||
"script-ext-html-webpack-plugin": "^2.1.4",
|
||||
"sharp": "^0.25.2",
|
||||
"style-loader": "^1.0.0",
|
||||
"temp": "^0.9.0",
|
||||
"terser": "^5.3.7",
|
||||
"terser-webpack-plugin": "^2.3.5",
|
||||
"webpack": "4.42.1",
|
||||
"webpack-dev-middleware": "^3.7.0",
|
||||
"webpack-hot-middleware": "^2.25.0",
|
||||
"webpack-merge": "^4.2.1",
|
||||
"workbox-webpack-plugin": "^4.3.1",
|
||||
"xhr2": "^0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -64,9 +36,6 @@
|
||||
"@types/jest": "^25.2.2",
|
||||
"@types/micromatch": "^4.0.1",
|
||||
"@types/node": "^12.7.7",
|
||||
"@types/webpack": "^4.32.1",
|
||||
"@types/webpack-dev-middleware": "^2.0.3",
|
||||
"elm-format": "^0.8.2",
|
||||
"elm-review": "^2.4.6",
|
||||
"elm-test": "^0.19.1-revision2",
|
||||
"elm-tooling": "^1.3.0",
|
||||
@ -79,8 +48,6 @@
|
||||
"generator/src/"
|
||||
],
|
||||
"bin": {
|
||||
"elm-pages": "generator/src/elm-pages.js",
|
||||
"elm-pages-beta": "generator/src/cli.js",
|
||||
"elm-pages-generate": "generator/src/codegen-template-module.js"
|
||||
"elm-pages": "generator/src/cli.js"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user