diff --git a/generators/additionalmodules/index.js b/generators/additionalmodules/index.js index 7bb73c8..9801298 100644 --- a/generators/additionalmodules/index.js +++ b/generators/additionalmodules/index.js @@ -1,9 +1,9 @@ -const Generator = require("yeoman-generator"), - fileaccess = require("../../helpers/fileaccess"), - path = require("path"), - glob = require("glob"); - -module.exports = class extends Generator { +import Generator from "yeoman-generator"; +import { glob } from "glob"; +import yaml from "yaml"; +import path from "path"; +import { writeYAML } from "../../helpers/fileaccess.js"; +export default class extends Generator { static hidden = true; prompting() { @@ -189,6 +189,6 @@ module.exports = class extends Generator { } } - await fileaccess.writeYAML.call(this, "/mta.yaml", mta); + await writeYAML.call(this, "/mta.yaml", mta); } }; diff --git a/generators/app/index.js b/generators/app/index.js index 703b126..8e0fe70 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -1,12 +1,21 @@ -"use strict"; -const Generator = require("yeoman-generator"), - fileaccess = require("../../helpers/fileaccess"), - path = require("path"), - chalk = require("chalk"), - yosay = require("yosay"), - glob = require("glob"); - -module.exports = class extends Generator { + +import chalk from "chalk"; +import fs from "fs"; +import Generator from "yeoman-generator"; +import yaml from "yaml"; +import path from "path"; +import yosay from "yosay"; +import { glob } from "glob"; +import { writeJSON } from "../../helpers/fileaccess.js"; +import url from "url"; +import WebAppGenerator from "../newwebapp/index.js"; +import AdditionModulesGenerator from "../additionalmodules/index.js"; +import { createRequire } from "node:module" +const require = createRequire(import.meta.url) +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); + + +export default class extends Generator { static displayName = "Create a new Fiori Launchpad Plugin"; constructor(args, opts) { @@ -114,10 +123,16 @@ module.exports = class extends Generator { oSubGen.modulename = "uimodule"; if (oConfig.platform === "SAP Launchpad service") { - this.composeWith(require.resolve("../additionalmodules"), oSubGen); + this.composeWith({ + Generator : AdditionModulesGenerator, + path: require.resolve("../additionalmodules") + }, oSubGen); } - this.composeWith(require.resolve("../newwebapp"), oSubGen); + this.composeWith({ + Generator:WebAppGenerator, + path : require.resolve("../newwebapp") + }, oSubGen); } async addPackage() { @@ -187,16 +202,17 @@ module.exports = class extends Generator { packge.ui5.dependencies.push("ui5-middleware-route-proxy"); packge.scripts["deploy"] = "run-s build:ui"; } - - await fileaccess.writeJSON.call(this, "/package.json", packge); + var sPackageJsonPath = this.destinationPath("package.json"); + console.info("Package Path : "+ sPackageJsonPath); + this.fs.extendJSON(sPackageJsonPath, packge); + //await writeJSON.call(this,sPackageJsonPath , packge); } install() { this.config.set("setupCompleted", true); - this.installDependencies({ - bower: false, - npm: true - }); + this.spawnCommandSync("npm", ["install"], { + cwd: this.destinationPath() + }); } end() { diff --git a/generators/newwebapp/index.js b/generators/newwebapp/index.js index a1cd401..63f647a 100644 --- a/generators/newwebapp/index.js +++ b/generators/newwebapp/index.js @@ -1,9 +1,14 @@ -const Generator = require("yeoman-generator"), - fileaccess = require("../../helpers/fileaccess"), - path = require("path"), - glob = require("glob"); -module.exports = class extends Generator { +import Generator from "yeoman-generator"; +import path from "path"; +import { glob } from "glob"; +import url from "url"; +import { manipulateJSON,writeYAML } from "../../helpers/fileaccess.js"; +import { createRequire } from "node:module" +const require = createRequire(import.meta.url) +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); + +export default class extends Generator { static hidden = true; prompting() { @@ -55,7 +60,7 @@ module.exports = class extends Generator { }); if (this.options.oneTimeConfig.platform === "SAP Launchpad service") { - await fileaccess.manipulateJSON.call(this, "/" + sModuleName + "/webapp/manifest.json", { + await manipulateJSON.call(this, "/" + sModuleName + "/webapp/manifest.json", { ["sap.cloud"]: { service: this.options.oneTimeConfig.projectname + ".service" } @@ -63,7 +68,9 @@ module.exports = class extends Generator { } // Append to Main package.json - await fileaccess.manipulateJSON.call(this, "/package.json", function (packge) { + var sPackageJsonPath = this.destinationPath("package.json"); + console.info("Package Path : "+ sPackageJsonPath); + this.fs.extendJSON( sPackageJsonPath, function (packge) { packge.scripts["serve:" + sModuleName] = "ui5 serve --config=" + sModuleName + "/ui5.yaml"; packge.scripts["build:ui"] += " build:" + sModuleName; let buildCommand = "ui5 build --config=" + sModuleName + "/ui5.yaml --clean-dest"; @@ -81,7 +88,7 @@ module.exports = class extends Generator { }); if (this.options.oneTimeConfig.platform === "SAP Launchpad service") { - await fileaccess.writeYAML.call(this, "/mta.yaml", (mta) => { + await writeYAML.call(this, "/mta.yaml", (mta) => { const deployer = mta.modules.find((module) => module.name === "webapp_deployer"); deployer["build-parameters"]["requires"].push({ diff --git a/helpers/fileaccess.js b/helpers/fileaccess.js index 2ed3619..8496f96 100644 --- a/helpers/fileaccess.js +++ b/helpers/fileaccess.js @@ -1,8 +1,9 @@ -const objectAssignDeep = require("object-assign-deep"), - yaml = require("yaml"); +import objectAssignDeep from "object-assign-deep"; +import yaml from "yaml" + // overide can be an object or a function that receives the current object -exports.writeJSON = async function (filePath, override) { +const writeJSON = async function (filePath, override) { try { const fullFilePath = process.cwd() + filePath; let oldContent = {}; @@ -26,7 +27,7 @@ exports.writeJSON = async function (filePath, override) { }; // overide can be an object or a function that receives the current object -exports.writeYAML = async function (filePath, override) { +const writeYAML = async function (filePath, override) { try { const fullFilePath = process.cwd() + filePath; let oldContent = {}; @@ -51,7 +52,7 @@ exports.writeYAML = async function (filePath, override) { }; // overide can be an object or a function that receives the current object -exports.manipulateJSON = async function (filePath, override) { +const manipulateJSON = async function (filePath, override) { try { const fullFilePath = process.cwd() + filePath; const oldContent = this.fs.readJSON(fullFilePath); @@ -72,7 +73,7 @@ exports.manipulateJSON = async function (filePath, override) { }; // overide can be an object or a function that receives the current object -exports.manipulateYAML = async function (filePath, override) { +const manipulateYAML = async function (filePath, override) { try { const fullFilePath = process.cwd() + filePath; const oldContent = yaml.parse(this.fs.read(fullFilePath)); @@ -90,3 +91,5 @@ exports.manipulateYAML = async function (filePath, override) { throw e; } }; + +export { writeJSON,writeYAML,manipulateJSON,manipulateYAML } diff --git a/package.json b/package.json index d54988d..337b9a3 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,10 @@ "test": "mocha", "workaround": "find . -name '.DS_Store' -delete", "test:manual": "cd test/ui5-app && ui5 serve", + "debug:project": "node --inspect node_modules/yo/lib/cli.js ui5-project:flp-plugin", "prettier": "prettier --write ." }, + "type": "module", "keywords": [ "yeoman-generator", "sap", @@ -29,20 +31,24 @@ "generators" ], "dependencies": { - "chalk": "^4.1.0", - "glob": "^7.1.6", + "glob": "^11.0.0", "object-assign-deep": "^0.4.0", + "package-json": "^10.0.1", "valid-filename": "^3.1.0", - "yaml": "^1.10.2", - "yeoman-environment": "^3.2.0", - "yeoman-generator": "^4.13.0", - "yosay": "^2.0.2" + "chalk": "^5.3.0", + "path": "^0.12.7", + "yaml": "^2.3.4", + "yeoman-environment": "^4.1.3", + "yeoman-generator": "^7.1.1", + "yosay": "^2.0.2", + "semver": "^7.6.3" }, "devDependencies": { "execa": "^5.0.0", - "mocha": "^8.3.2", + "mocha": "^10.4.0", "prettier": "2.2.1", "yeoman-assert": "^3.1.1", - "yeoman-test": "^3.0.0" + "yeoman-test": "^8.3.0", + "yo": "^5.0.0" } }