mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-22 11:21:31 +03:00
Add CLI handler for elm-pages add command.
This commit is contained in:
parent
0c6c8610cc
commit
6258ec0b06
@ -45,5 +45,5 @@ Then you need to install the NPM pacakge from the top-level project with `npm in
|
||||
### Commands
|
||||
|
||||
- Run a dev server - `elm-pages dev`
|
||||
- Generate scaffolding for a new Page Template - `../../generator/src/codegen-template-module.js Slide.Number_`
|
||||
- Generate scaffolding for a new Page Template - `elm-pages add Slide.Number_`
|
||||
- Run a build - `elm-pages build`
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const build = require("./build.js");
|
||||
const dev = require("./dev-server.js");
|
||||
const generate = require("./codegen-template-module.js");
|
||||
|
||||
const commander = require("commander");
|
||||
|
||||
@ -29,6 +30,13 @@ async function main() {
|
||||
await dev.start(options);
|
||||
});
|
||||
|
||||
program
|
||||
.command("add <moduleName>")
|
||||
.description("create a new Page Template module")
|
||||
.action(async (moduleName) => {
|
||||
await generate.run({ moduleName });
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("./dir-helpers.js");
|
||||
const path = require("path");
|
||||
const routeHelpers = require("./route-codegen-helpers");
|
||||
|
||||
async function run() {
|
||||
if (process.argv.length === 3) {
|
||||
const moduleName = process.argv[2];
|
||||
async function run({ moduleName }) {
|
||||
if (!moduleName.match(/[A-Z][A-Za-z0-9]+(\.[A-Z][A-Za-z0-9])*/)) {
|
||||
console.error("Invalid module name.");
|
||||
process.exit(1);
|
||||
@ -18,17 +14,13 @@ async function run() {
|
||||
);
|
||||
await fs.tryMkdir(path.dirname(fullFilePath));
|
||||
fs.writeFile(fullFilePath, content);
|
||||
} else {
|
||||
console.error(`Unexpected CLI options: ${process.argv}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} templateName
|
||||
*/
|
||||
function fileContent(templateName) {
|
||||
return `module Template.${templateName} exposing (Model, Msg, template)
|
||||
return `module Template.${templateName} exposing (Model, Msg, StaticData, template)
|
||||
|
||||
import Element exposing (Element)
|
||||
import Document exposing (Document)
|
||||
@ -95,4 +87,4 @@ view static =
|
||||
`;
|
||||
}
|
||||
|
||||
run();
|
||||
module.exports = { run };
|
||||
|
Loading…
Reference in New Issue
Block a user