Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-lib-sub-gen): move app info file writing to writing phase #2463

Merged
merged 7 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-onions-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/ui5-library-sub-generator': patch
---

move app info file writing to writing phase
5 changes: 5 additions & 0 deletions .changeset/tough-books-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sap-ux/project-access": patch
---

refactor: Update variable declarations in getCapModelAndServices function
6 changes: 3 additions & 3 deletions packages/project-access/src/project/cap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ export async function getCapCustomPaths(capProjectPath: string): Promise<CapCust
export async function getCapModelAndServices(
projectRoot: string | { projectRoot: string; logger?: Logger; pathSelection?: Set<'app' | 'srv' | 'db'> }
): Promise<{ model: csn; services: ServiceInfo[]; cdsVersionInfo: CdsVersionInfo }> {
let _projectRoot;
let _logger;
let _pathSelection;
let _projectRoot: string;
let _logger: Logger | undefined;
let _pathSelection: Set<string> | undefined;
const defaultPathSelection = new Set(['app', 'srv', 'db']);
if (typeof projectRoot === 'object') {
_projectRoot = projectRoot.projectRoot;
Expand Down
5 changes: 3 additions & 2 deletions packages/ui5-library-sub-generator/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export default class extends Generator implements Ui5LibGenerator {

if (this.answers.targetFolder) {
this.targetFolder = this.answers.targetFolder;
this.projectPath = join(this.targetFolder, `${this.answers.namespace}.${this.answers.libraryName}`);
}

try {
await generate(this.targetFolder, ui5Lib, this.fs);
writeApplicationInfoSettings(this.projectPath);
} catch (e) {
ReuseLibGenLogger.logger.error(e);
throw new Error(t('error.generatingUi5Lib'));
Expand All @@ -108,7 +110,6 @@ export default class extends Generator implements Ui5LibGenerator {
const npm = platform() === 'win32' ? 'npm.cmd' : 'npm';

ReuseLibGenLogger.logger.info(t('info.installingDependencies'));
this.projectPath = join(this.targetFolder, `${this.answers.namespace}.${this.answers.libraryName}`);
await runner.run(npm, ['install'], { cwd: this.projectPath });
ReuseLibGenLogger.logger.info(t('info.dependenciesInstalled'));
} catch (error) {
Expand All @@ -118,7 +119,7 @@ export default class extends Generator implements Ui5LibGenerator {
}

async end(): Promise<void> {
writeApplicationInfoSettings(this.projectPath, this.fs);
ReuseLibGenLogger.logger.info(t('info.openingAppInfo'));
await runPostLibGenHook({
path: this.projectPath,
vscodeInstance: this.vscode as VSCodeInstance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"info": {
"openingAppInfo": "Opening application info...",
"installingDependencies": "Installing dependencies...",
"dependenciesInstalled": "Library dependencies have been installed."
},
Expand Down
3 changes: 3 additions & 0 deletions packages/ui5-library-sub-generator/test/unit/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import yeomanTest from 'yeoman-test';
import ReuseLibGen from '../../src/app';
import { CommandRunner } from '@sap-ux/nodejs-utils';
import type { Editor } from 'mem-fs-editor';
import * as fioriToolsSettings from '@sap-ux/fiori-tools-settings';

jest.mock('@sap-ux/fiori-generator-shared', () => ({
// eslint-disable-next-line
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('Test reuse lib generator', () => {
it('should run the generator', async () => {
fs.mkdirSync(testOutputDir, { recursive: true });
jest.spyOn(ui5LibraryInquirer, 'getPrompts').mockResolvedValue(mockPrompts);
const writeApplicationInfoSettingsSpy = jest.spyOn(fioriToolsSettings, 'writeApplicationInfoSettings');

await yeomanTest
.run(ReuseLibGen, {
Expand All @@ -89,6 +91,7 @@ describe('Test reuse lib generator', () => {
});

expect(join(testOutputDir, 'com.sap.library1')).toMatchFolder(join(expectedOutputPath, 'library1'));
expect(writeApplicationInfoSettingsSpy).toHaveBeenCalledWith(join(testOutputDir, 'com.sap.library1'));
});

it('should run the generator (typescript)', async () => {
Expand Down
Loading