Skip to content

Commit

Permalink
https://github.com/haxtheweb/issues/issues/2170
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Oct 24, 2024
1 parent e72bda7 commit 66f44c7
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 59 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"start": "npm run build && node ./dist/create.js && chmod 774 dist/create.js",
"release": "npm run build && commit-and-tag-version && git push --follow-tags origin main && npm publish",
"hax": "hax",
"debug": "nodemon --watch src",
"dev": "nodemon --watch src",
"haxcms-nodejs-cli": "haxcms-nodejs-cli"
},
"bin": {
Expand All @@ -42,7 +42,7 @@
"dependencies": {
"@clack/core": "0.3.4",
"@clack/prompts": "0.7.0",
"@haxtheweb/haxcms-nodejs": "^9.0.13",
"@haxtheweb/haxcms-nodejs": "^9.0.14",
"ejs": "3.1.10",
"picocolors": "1.0.1",
"commander": "12.1.0"
Expand Down
56 changes: 37 additions & 19 deletions src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import color from 'picocolors';

import { haxIntro, communityStatement } from "./lib/statements.js";
import { webcomponentProcess, webcomponentCommandDetected } from "./lib/programs/webcomponent.js";
import { siteProcess, siteCommandDetected } from "./lib/programs/site.js";

import { siteActions, siteNodeOperations, siteProcess, siteCommandDetected } from "./lib/programs/site.js";
import { camelToDash } from "./lib/utils.js";
import * as hax from "@haxtheweb/haxcms-nodejs";
const HAXCMS = hax.HAXCMS;

Expand Down Expand Up @@ -41,11 +41,10 @@ async function main() {
.option('--org <char>', 'organization for package.json')
.option('--author <char>', 'author for site / package.json')


// options for site
// options for site
.option('--node-op <char>', 'node operation to perform')
.option('--item-id <char>', 'node ID to operate on')
.option('--name <char>', 'name of the project')
.option('--title <char>', 'node title')
.option('--domain <char>', 'published domain name')
.helpCommand(true);

Expand All @@ -62,9 +61,14 @@ async function main() {
});

// site operations and actions
program
.command('site')
.argument('[action]', 'action to take')
let strActions = '';
siteActions().forEach(action => {
strActions+= `${action.value} - ${action.label}` + "\n\r";
});
let siteProg = program
.command('site');
siteProg
.argument('[action]', 'Actions to perform on site include:' + "\n\r" + strActions)
.action((action) => {
commandRun = {
command: 'site',
Expand All @@ -73,15 +77,18 @@ async function main() {
},
options: {
skip: true,
y: (action) ? true : false
}
};
})
.option('--name <char>', 'name of the site (when creating a new one)')
.option('--title <char>', 'node title')
.option('--domain <char>', 'published domain name')
.option('--node-op <char>', 'node operation to perform')
.version(await HAXCMS.getHAXCMSVersion());

let siteNodeOps = siteNodeOperations();
for (var i in siteNodeOps) {
program.option(`--${camelToDash(siteNodeOps[i].value)} <char>`, `${siteNodeOps[i].label}`)
siteProg.option(`--${camelToDash(siteNodeOps[i].value)} <char>`, `${siteNodeOps[i].label}`)
}
// webcomponent program
program
.command('webcomponent')
Expand All @@ -91,13 +98,15 @@ async function main() {
commandRun = {
command: 'webcomponent',
arguments: {
name: name
},
options: {
skip: true,
y: (name) ? true : false
}
};
if (name) {
commandRun.arguments.name = name;
}
})
.option('--org <char>', 'organization for package.json')
.option('--author <char>', 'author for site / package.json');
Expand Down Expand Up @@ -251,7 +260,7 @@ async function main() {
}
},
name: ({ results }) => {
if (!commandRun.options.name) {
if (!commandRun.arguments.name) {
let placeholder = "mysite";
let message = "Site name:";
if (commandRun.command === "webcomponent" || results.type === "webcomponent") {
Expand Down Expand Up @@ -355,12 +364,21 @@ async function main() {
);
// merge cli options with project options assume this is NOT a monorepo
// but spread will overwrite if needed
project = {
isMonorepo: false,
...project,
...commandRun.arguments,
...commandRun.options,
};
if (commandRun.command === 'webcomponent' && !commandRun.arguments.name) {
project = {
isMonorepo: false,
...project,
...commandRun.options,
};
}
else {
project = {
isMonorepo: false,
...project,
...commandRun.arguments,
...commandRun.options,
};
}
project.year = new Date().getFullYear();
project.version = await HAXCMS.getHAXCMSVersion();
// resolve site vs multi-site
Expand Down
Loading

0 comments on commit 66f44c7

Please sign in to comment.