Skip to content

Commit

Permalink
Migrated package json to new versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ubheamar committed Sep 11, 2024
1 parent fcac5da commit bc3dd6a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 46 deletions.
14 changes: 7 additions & 7 deletions generators/additionalmodules/index.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -189,6 +189,6 @@ module.exports = class extends Generator {
}
}

await fileaccess.writeYAML.call(this, "/mta.yaml", mta);
await writeYAML.call(this, "/mta.yaml", mta);
}
};
50 changes: 33 additions & 17 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
23 changes: 15 additions & 8 deletions generators/newwebapp/index.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -55,15 +60,17 @@ 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"
}
});
}

// 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";
Expand All @@ -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({
Expand Down
15 changes: 9 additions & 6 deletions helpers/fileaccess.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand All @@ -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 = {};
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -90,3 +91,5 @@ exports.manipulateYAML = async function (filePath, override) {
throw e;
}
};

export { writeJSON,writeYAML,manipulateJSON,manipulateYAML }
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}

0 comments on commit bc3dd6a

Please sign in to comment.