Skip to content

Commit

Permalink
move adjustment of .tsconfig to post-processing and remove dependency…
Browse files Browse the repository at this point in the history
… @types/qunit as it comes with OpenUI5 or SAPUI5
  • Loading branch information
heimwege committed Oct 18, 2024
1 parent 55061d7 commit 6075447
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
1 change: 0 additions & 1 deletion generators/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default {
"@sap/approuter": "latest",
"@ui5/linter": "latest",
"cds-plugin-ui5": "latest",
"@types/qunit": "2.5.4",
"mbt": "^1",
"rimraf": "latest",
"OpenUI5": "1.120.13",
Expand Down
9 changes: 2 additions & 7 deletions generators/opa5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "../helpers.js"
import path, { dirname } from "path"
import { fileURLToPath } from "url"
import dependencies from "../dependencies.js";
const __dirname = dirname(fileURLToPath(import.meta.url))

export default class extends Generator {
Expand All @@ -28,6 +27,8 @@ export default class extends Generator {
// prioritize manually passed parameter over config from file, as the latter is not up to date when subgenerator is composed
this.options.config.uimoduleName = this.options.uimoduleName
}
// remember tests were generated for post-processing to add the respective types to .tsconfig as well
this.options.config.enableTests = true
}

async writing() {
Expand Down Expand Up @@ -60,12 +61,6 @@ export default class extends Generator {

const uimodulePackageJson = JSON.parse(fs.readFileSync(this.destinationPath("package.json")))
uimodulePackageJson.scripts["opa5"] = "fiori run --open test/opaTests.qunit.html"
if (this.options.config.enableTypescript) {
uimodulePackageJson["devDependencies"]["@types/qunit"] = dependencies["@types/qunit"]
const tsconfigJson = JSON.parse(fs.readFileSync(this.destinationPath("tsconfig.json")))
tsconfigJson.compilerOptions.types.includes("qunit") || tsconfigJson.compilerOptions.types.push( "qunit" )
fs.writeFileSync(this.destinationPath("tsconfig.json"), JSON.stringify(tsconfigJson, null, 4))
}
fs.writeFileSync(this.destinationPath("package.json"), JSON.stringify(uimodulePackageJson, null, 4))
}

Expand Down
9 changes: 2 additions & 7 deletions generators/qunit/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import chalk from "chalk"
import fs from "fs"
import Generator from "yeoman-generator"
import dependencies from "../dependencies.js"
import prompts from "./prompts.js"
import {
lookForParentUI5ProjectAndPrompt,
Expand All @@ -25,6 +24,8 @@ export default class extends Generator {
// prioritize manually passed parameter over config from file, as the latter is not up to date when subgenerator is composed
this.options.config.uimoduleName = this.options.uimoduleName
}
// remember tests were generated for post-processing to add the respective types to .tsconfig as well
this.options.config.enableTests = true
}

async writing() {
Expand All @@ -43,12 +44,6 @@ export default class extends Generator {

const uimodulePackageJson = JSON.parse(fs.readFileSync(this.destinationPath("package.json")))
uimodulePackageJson.scripts["qunit"] = "fiori run --open test/unitTests.qunit.html"
if (this.options.config.enableTypescript) {
uimodulePackageJson["devDependencies"]["@types/qunit"] = dependencies["@types/qunit"]
const tsconfigJson = JSON.parse(fs.readFileSync(this.destinationPath("tsconfig.json")))
tsconfigJson.compilerOptions.types.includes("qunit") || tsconfigJson.compilerOptions.types.push( "qunit" )
fs.writeFileSync(this.destinationPath("tsconfig.json"), JSON.stringify(tsconfigJson, null, 4))
}
fs.writeFileSync(this.destinationPath("package.json"), JSON.stringify(uimodulePackageJson, null, 4))
}

Expand Down
5 changes: 5 additions & 0 deletions generators/uimodule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ export default class extends Generator {
tsconfigJson.compilerOptions.types = [ "@sapui5/types" ]
fs.writeFileSync(this.destinationPath("tsconfig.json"), JSON.stringify(tsconfigJson, null, 4))
}
if (this.options.config.enableTypescript && this.options.config.enableTests) {
const tsconfigJson = JSON.parse(fs.readFileSync(this.destinationPath("tsconfig.json")))
tsconfigJson.compilerOptions.types.includes("qunit") || tsconfigJson.compilerOptions.types.push( "qunit" )
fs.writeFileSync(this.destinationPath("tsconfig.json"), JSON.stringify(tsconfigJson, null, 4))
}
}

end() {
Expand Down

0 comments on commit 6075447

Please sign in to comment.