initial commit

This commit is contained in:
Omer Sabic 2024-02-28 15:06:35 +01:00
commit 049472d0b5
11 changed files with 774 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

136
index.js Normal file
View File

@ -0,0 +1,136 @@
import chalk from "chalk";
import { input, select } from "@inquirer/prompts";
import fs from "node:fs";
import * as utils from './util.js'
import path from "node:path";
async function main() {
const directory = await input({ message: "Project directory: ", default: "./test" });
utils.ensure_directory(directory);
const choice = await select({
message: "What command do you want to execute?",
choices: [
{
name: 'Initialize project',
value: 'init',
description: 'Initialize a new myfactory addon'
},
{
name: 'Component',
value: 'component',
description: 'Choose from a set of templates to automatically insert into your myfactory addon',
},
]
});
try {
switch (choice) {
case "init":
if (fs.readdirSync(directory).length > 0) {
log.error("Directory must be empty.");
return;
}
const type = await select({
message: "What type of project do you want to initialize?",
choices: [
{
name: "Skeleton",
value: "skeleton",
description: "A basic skeleton project with nothing added"
},
{
name: "Hello World",
value: "helloworld",
description: "A simple hello world addon that generates a new page in the menu and displays some text"
}
]
});
init_project(directory, type)
break;
case "component": insert_component(directory);
}
} catch (e) {
log.error(e.message);
}
}
/**
* Initialize a new myfactory addon
* @param {string} dir Directory in which to initialize the project.
*/
async function init_project(dir, type) {
const projectname = await input({ message: "Project name: ", default: "Example Project" });
const partner = await input({ message: "Partner id: ", default: "ES" });
const module = await input({ message: "Module id: ", default: "Seiwert" });
const version = await input({ message: "Version: ", default: "1.0.0.0" });
const description = await input({ message: "Module description", default: "This is a myfactory Addon" });
utils.ensure_directory(path.join(dir, "Install"));
fs.cpSync(path.join("./templates", type, "/"), dir + "/Install", { recursive: true });
// Make xml def file
fs.writeFileSync(path.join(dir, "myfactory.xml"), utils.template("myfactoryXml", {
partnerid: partner,
moduleid: module,
version,
description
}));
replaceVariablesInNames(dir, {
projectname,
partner,
module
});
}
// Function to recursively replace variables in file and directory names
function replaceVariablesInNames(dir, variables) {
fs.readdirSync(dir).forEach(name => {
const oldPath = path.join(dir, name);
const newPath = replaceVariablesInName(name, variables);
const newPathFull = path.join(dir, newPath);
fs.renameSync(oldPath, newPathFull); // Rename the file or directory
if (fs.statSync(newPathFull).isDirectory()) {
replaceVariablesInNames(newPathFull, variables); // Recursively explore subdirectories
}
});
}
// Function to replace variables in a single name
function replaceVariablesInName(name, variables) {
// Replace all instances of {variable} with the corresponding value
Object.keys(variables).forEach(variable => {
const regex = new RegExp('{' + variable + '}', 'g');
name = name.replace(regex, variables[variable]);
});
return name;
}
/**
* Insert a component into an existing myfactory addon
* @param {string} dir
*/
async function insert_component(dir) {
if (!utils.isMyFactoryAddon(dir)) throw new Error("Invalid MyFactory Addon directory.")
const component = select({
message: "What component do you want to add?", choices: [
{
name: "ListView",
value: "listview",
description: "Add a simple listview to your project"
}
]
})
}
const log = {
error(string) {
console.error(chalk.red("ERROR"), string)
}
}
main();

540
package-lock.json generated Normal file
View File

@ -0,0 +1,540 @@
{
"name": "devfactory",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "devfactory",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@inquirer/prompts": "^4.1.0",
"chalk": "^5.3.0"
}
},
"node_modules/@inquirer/checkbox": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@inquirer/checkbox/-/checkbox-2.1.0.tgz",
"integrity": "sha512-DyvMAKFoqJ5BCVBqHqiQELSJvwHTqXaJmV1onATgjxyM3vtp6b8xbfPE5feX1pR9wvH+sso02Pb326S92h6Q/A==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0",
"ansi-escapes": "^4.3.2",
"chalk": "^4.1.2",
"figures": "^3.2.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/checkbox/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/confirm": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/confirm/-/confirm-3.0.0.tgz",
"integrity": "sha512-LHeuYP1D8NmQra1eR4UqvZMXwxEdDXyElJmmZfU44xdNLL6+GcQBS0uE16vyfZVjH8c22p9e+DStROfE/hyHrg==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/core": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/core/-/core-7.0.0.tgz",
"integrity": "sha512-g13W5yEt9r1sEVVriffJqQ8GWy94OnfxLCreNSOTw0HPVcszmc/If1KIf7YBmlwtX4klmvwpZHnQpl3N7VX2xA==",
"dependencies": {
"@inquirer/type": "^1.2.0",
"@types/mute-stream": "^0.0.4",
"@types/node": "^20.11.16",
"@types/wrap-ansi": "^3.0.0",
"ansi-escapes": "^4.3.2",
"chalk": "^4.1.2",
"cli-spinners": "^2.9.2",
"cli-width": "^4.1.0",
"figures": "^3.2.0",
"mute-stream": "^1.0.0",
"run-async": "^3.0.0",
"signal-exit": "^4.1.0",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^6.2.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/core/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/editor": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/editor/-/editor-2.0.0.tgz",
"integrity": "sha512-0n3agxb1X23A/lx+MI5sV6s/qeywGr4xmKAzZS7ZhToee7L/6DXotWa/VvvwNEoBT0mSuk9SDIAoQ0zLkJmpHg==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0",
"external-editor": "^3.1.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/expand": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/expand/-/expand-2.0.0.tgz",
"integrity": "sha512-2VETEz+RyRrIeBwULKc5o+PJzKqbsibyT6IY0oP0XvM/17flO6eW7P+rdGCAvFP6g2hKieIH23ZVrcgsosb1/g==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0",
"chalk": "^4.1.2",
"figures": "^3.2.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/expand/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/input": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/input/-/input-2.0.0.tgz",
"integrity": "sha512-qOjxSHLzqp/u6TvK7UtidPERoCa6BSSKyKG17aEaSOBl9uAQ4XIIqs9TtcEqwDloakarWS6xxTfR0sE1qvLwIQ==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/password": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/password/-/password-2.0.0.tgz",
"integrity": "sha512-PlUek3wTMiGZothmmGIL4OBLo+rDSCxqIUHsyroyM/+AnR3xr5NHMM0/5z6CuptpJs1ZbQewqslaNi7k6goWMw==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0",
"ansi-escapes": "^4.3.2"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/prompts": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-4.1.0.tgz",
"integrity": "sha512-HUVJ5yLjDUEq61LQiujs26qqFrKIaZOnpzDRmnYT67bsXUD8gxPmLg+DJq2ENniiDSQyBK33qVQIbeeAdR3ZlQ==",
"dependencies": {
"@inquirer/checkbox": "^2.1.0",
"@inquirer/confirm": "^3.0.0",
"@inquirer/core": "^7.0.0",
"@inquirer/editor": "^2.0.0",
"@inquirer/expand": "^2.0.0",
"@inquirer/input": "^2.0.0",
"@inquirer/password": "^2.0.0",
"@inquirer/rawlist": "^2.0.0",
"@inquirer/select": "^2.0.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/rawlist": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/rawlist/-/rawlist-2.0.0.tgz",
"integrity": "sha512-o4jHJBAvknVE6K15zX8AuLMemb1eN1EL0l+BIbJ2JgtpoU2zSuLf6jT98omvtWk/gbaowjw7RLsW7X5F+G19KA==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0",
"chalk": "^4.1.2"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/rawlist/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/select": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@inquirer/select/-/select-2.0.0.tgz",
"integrity": "sha512-ZxWP1gHbReAH6HdoNQRV/9W/UjgKSeiiQX2DxJ6w3GDiQeC3fRAL+lukuMM+QGteGqaTjWwIEWhPLvgbGIrRgg==",
"dependencies": {
"@inquirer/core": "^7.0.0",
"@inquirer/type": "^1.2.0",
"ansi-escapes": "^4.3.2",
"chalk": "^4.1.2",
"figures": "^3.2.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@inquirer/select/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/type": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@inquirer/type/-/type-1.2.0.tgz",
"integrity": "sha512-/vvkUkYhrjbm+RolU7V1aUFDydZVKNKqKHR5TsE+j5DXgXFwrsOPcoGUJ02K0O7q7O53CU2DOTMYCHeGZ25WHA==",
"engines": {
"node": ">=18"
}
},
"node_modules/@types/mute-stream": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz",
"integrity": "sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/node": {
"version": "20.11.20",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.20.tgz",
"integrity": "sha512-7/rR21OS+fq8IyHTgtLkDK949uzsa6n8BkziAKtPVpugIkO6D+/ooXMvzXxDnZrmtXVfjb1bKQafYpb8s89LOg==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/@types/wrap-ansi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz",
"integrity": "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g=="
},
"node_modules/ansi-escapes": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
"integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==",
"dependencies": {
"type-fest": "^0.21.3"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/chalk": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
"integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/chardet": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
"integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA=="
},
"node_modules/cli-spinners": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz",
"integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==",
"engines": {
"node": ">=6"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/cli-width": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz",
"integrity": "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==",
"engines": {
"node": ">= 12"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
},
"node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/external-editor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz",
"integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==",
"dependencies": {
"chardet": "^0.7.0",
"iconv-lite": "^0.4.24",
"tmp": "^0.0.33"
},
"engines": {
"node": ">=4"
}
},
"node_modules/figures": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
"integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==",
"dependencies": {
"escape-string-regexp": "^1.0.5"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"engines": {
"node": ">=8"
}
},
"node_modules/mute-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-1.0.0.tgz",
"integrity": "sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==",
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
"node_modules/os-tmpdir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/run-async": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/run-async/-/run-async-3.0.0.tgz",
"integrity": "sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==",
"engines": {
"node": ">=0.12.0"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/signal-exit": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
"dependencies": {
"os-tmpdir": "~1.0.2"
},
"engines": {
"node": ">=0.6.0"
}
},
"node_modules/type-fest": {
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz",
"integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
"node_modules/wrap-ansi": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=8"
}
}
}
}

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "devfactory",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"@inquirer/prompts": "^4.1.0",
"chalk": "^5.3.0"
}
}

3
templates.json Normal file
View File

@ -0,0 +1,3 @@
{
"myfactoryXml": "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n<myfactory>\n <PartnerID>{partnerid}</PartnerID>\n <ModuleID>{moduleid}</ModuleID>\n <Version>{version}</Version>\n <ModuleDesc>{description}</ModuleDesc>\n <MinDBVersion>wf70_Nov21</MinDBVersion>\n</myfactory>"
}

View File

View File

View File

View File

8
test/myfactory.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<myfactory>
<PartnerID>ES</PartnerID>
<ModuleID>Seiwert</ModuleID>
<Version>1.0.0.0</Version>
<ModuleDesc>This is a myfactory Addon</ModuleDesc>
<MinDBVersion>wf70_Nov21</MinDBVersion>
</myfactory>

69
util.js Normal file
View File

@ -0,0 +1,69 @@
import fs from 'node:fs';
const templates = JSON.parse(fs.readFileSync('./templates.json'));
/**
* Checks whether a specific directory is a valid MyFactory Addon
* @param {*} dir
*/
export async function isMyFactoryAddon(dir) {
try {
// Check if directory exists
await fs.access(directoryPath, fs.constants.F_OK);
// Check for "myfactory.xml" file
const fileStats = await fs.stat(`${directoryPath}/myfactory.xml`);
if (!fileStats.isFile()) {
throw new Error(`"myfactory.xml" is not a file.`);
}
// Check for "Install" directory
await fs.access(`${directoryPath}/Install`, fs.constants.F_OK);
// Check for nested directories "DB" and "Files" inside "Install"
const installDirStats = await fs.stat(`${directoryPath}/Install`);
if (!installDirStats.isDirectory()) {
throw new Error(`"Install" is not a directory.`);
}
const dbDirStats = await fs.stat(`${directoryPath}/Install/DB`);
if (!dbDirStats.isDirectory()) {
throw new Error(`"DB" directory is missing inside "Install".`);
}
const filesDirStats = await fs.stat(`${directoryPath}/Install/Files`);
if (!filesDirStats.isDirectory()) {
throw new Error(`"Files" directory is missing inside "Install".`);
}
console.log("Directory structure is valid!");
} catch (error) {
console.error("Error verifying directory structure:", error.message);
}
}
/**
* If a directory does not exist, create it.
* @param {string} path Path to directory
*/
export async function ensure_directory(path) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
}
}
/**
* Fill out and return a template string from ./templates.json
* @param {string} template The field name of the template
* @param {object<any>} data Data to fill out
*/
export function template(template, data) {
/** @type {string} */
var templateText = templates[template];
if(!templateText) throw new Error("Unknown template");
Object.keys(data).forEach(key => {
templateText = templateText.replaceAll(`{${key}}`, data[key]);
});
return templateText;
}