-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI updated and new command
init
added to initialise configuration.
- Loading branch information
Showing
5 changed files
with
108 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { copyFileSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
|
||
export default function initConfig() { | ||
const sourceConfig = join(__dirname, "userconfig-template.js"); | ||
const dest = join(process.cwd(), "richie.config.js"); | ||
copyFileSync(sourceConfig, dest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,80 @@ | ||
#! node | ||
import { hideBin } from "yargs/helpers"; | ||
import yargs from "yargs/yargs"; | ||
#! /usr/bin/env node | ||
|
||
import { Command } from "commander"; | ||
import { richieOptions } from "../lib/types"; | ||
import iconAssociator from "./iconAssociator"; | ||
import initConfig from "./initConfig"; | ||
import { makeRichie } from "./richieMaker"; | ||
|
||
type availableCommandsOP = "init" | "make"; | ||
|
||
function main(): Promise<void> { | ||
const availableCommands: availableCommandsOP[] = ["init", "make"]; | ||
const givenCommand: availableCommandsOP = process | ||
.argv[2] as availableCommandsOP; | ||
|
||
const unsupportedAlert = (): void => { | ||
console.log( | ||
`Unsupported command\nAvailable commands are\n${availableCommands}`, | ||
); | ||
}; | ||
|
||
if (!availableCommands.includes(givenCommand)) { | ||
unsupportedAlert(); | ||
process.exit(1); | ||
} | ||
const program = new Command(); | ||
|
||
//handle flag options | ||
const argv: richieOptions = yargs(hideBin(process.argv)) | ||
.option("destDir", { | ||
alias: "d", | ||
type: "string", | ||
description: "Destination directory", | ||
default: "dist", | ||
}) | ||
.option("omitPatterns", { | ||
alias: "no", | ||
type: "array", | ||
description: "Omit directory / glob pattern", | ||
default: [], | ||
}) | ||
.option("norm", { | ||
alias: "p", | ||
type: "boolean", | ||
description: "Preserve current destination dir as it is", | ||
default: false, | ||
}).argv as richieOptions; | ||
async function main() { | ||
program | ||
.name("richie") | ||
.description( | ||
"Richie.js an open source SEO tool, rich result generator.", | ||
) | ||
.version("2.0.0"); | ||
|
||
return new Promise((resolve, reject) => { | ||
switch (givenCommand) { | ||
case "make": | ||
makeRichie({ | ||
destDir: argv.destDir, | ||
omitPatterns: argv.omitPatterns, | ||
norm: argv.norm, | ||
}) | ||
.then(() => { | ||
resolve(); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
break; | ||
// 'make' command | ||
program | ||
.command("make") | ||
.description("Generate rich result snippet for all HTML and inject it") | ||
.option("-d, --destDir <string>", "Destination directory", "dist") | ||
.option( | ||
"-o, --omitPatterns <patterns...>", | ||
"Omit directory / glob patterns", | ||
[], | ||
) | ||
.option( | ||
"-p, --norm", | ||
"Preserve current destination directory as it is", | ||
false, | ||
) | ||
.action(async (options: richieOptions) => { | ||
try { | ||
await makeRichie({ | ||
destDir: options.destDir, | ||
omitPatterns: options.omitPatterns, | ||
norm: options.norm, | ||
}); | ||
console.log( | ||
"✅ Rich result snippets are generated for all HTML & saved.", | ||
); | ||
} catch (err) { | ||
console.error("⚠️ Error generating rich result snippets:", err); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
case "init": | ||
iconAssociator() | ||
.then(() => { | ||
resolve(); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
break; | ||
default: | ||
unsupportedAlert(); | ||
// 'init' command | ||
program | ||
.command("init") | ||
.description("Initialize Richie.js configurations") | ||
.action(async () => { | ||
try { | ||
await iconAssociator(); | ||
initConfig(); | ||
console.log("🚀 Richie.js configuration initialised."); | ||
} catch (err) { | ||
console.error("⚠️ Error initializing icon associations:", err); | ||
process.exit(1); | ||
} | ||
} | ||
}); | ||
|
||
// Handle unsupported commands | ||
program.on("command:*", (commands) => { | ||
console.error( | ||
`⚠️ Unsupported command: ${commands[0]}\nAvailable commands are: make, init`, | ||
); | ||
process.exit(1); | ||
}); | ||
|
||
// Parse the arguments | ||
await program.parseAsync(process.argv); | ||
} | ||
|
||
main().catch((err) => { | ||
console.log(err); | ||
console.error("⚠️ Unexpected error:", err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** @type {import("@cresteem/richie-js").rjsOptions} */ | ||
const config = { | ||
domainAddress: "example.com", | ||
preference: { | ||
isCarousals: { | ||
movie: false, | ||
course: false, | ||
recipe: false, | ||
restaurant: false, | ||
}, | ||
isProductVar: false, | ||
breadcrumb: false, | ||
siteSearchBoxFieldName: "query", | ||
}, | ||
}; | ||
|
||
exports.default = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2112,6 +2112,11 @@ color-name@~1.1.4: | |
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" | ||
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== | ||
|
||
commander@^12.1.0: | ||
version "12.1.0" | ||
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" | ||
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
|
@@ -3553,6 +3558,11 @@ natural-compare@^1.4.0: | |
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" | ||
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw== | ||
|
||
ncp@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3" | ||
integrity sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA== | ||
|
||
netmask@^2.0.2: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/netmask/-/netmask-2.0.2.tgz#8b01a07644065d536383835823bc52004ebac5e7" | ||
|
@@ -4457,7 +4467,7 @@ yargs-parser@^21.1.1: | |
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" | ||
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== | ||
|
||
yargs@17.7.2, yargs@^17.3.1, yargs@^17.7.2: | ||
yargs@^17.3.1, yargs@^17.7.2: | ||
version "17.7.2" | ||
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269" | ||
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w== | ||
|