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: add missing files in workspace #2682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 0 additions & 43 deletions .commitlintrc.json

This file was deleted.

50 changes: 50 additions & 0 deletions commitlint.config.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type {
UserConfig,
} from '@commitlint/types';

export default {
extends: [
'@commitlint/config-conventional',
'@commitlint/config-angular'
],
rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'header-max-length': [2, 'always', 100],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [2, 'never',
[
'sentence-case',
'start-case',
'pascal-case',
'upper-case'
]
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [2, 'always',
[
'build',
'chore',
'ci',
'docs',
'deprecate',
'feat',
'feature',
'features',
'fix',
'bugfix',
'fixes',
'bugfixes',
'improvement',
'perf',
'refactor',
'revert',
'style',
'test'
]
]
}
} as const satisfies UserConfig;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@
"@babel/core": "~7.26.0",
"@babel/preset-typescript": "~7.26.0",
"@commitlint/cli": "^19.0.0",
"@commitlint/config-angular": "^19.0.0",
"@commitlint/config-conventional": "^19.0.0",
"@commitlint/types": "^19.0.0",
"@compodoc/compodoc": "^1.1.19",
"@design-factory/design-factory": "~18.1.0",
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './interfaces';
export * from './npm-exec';
export * from './npm-install';
export * from './npm-node-run';
export * from './npm-run';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
NodeRunScriptTask,
} from './npm-node-run';

describe('NodeRunScriptTask', () => {
test('should use the correct working directory and provided package manager', () => {
const task1 = new NodeRunScriptTask('', 'test-directory-1', 'npm');
const task2 = new NodeRunScriptTask('', 'test-directory-2', 'yarn');
const config1: any = task1.toConfiguration();
const config2: any = task2.toConfiguration();

expect(config1.options.command).toBe('exec');
expect(config1.options.workingDirectory).toBe('test-directory-1');
expect(config1.options.packageManager).toBe('npm');

expect(config2.options.command).toBe('exec');
expect(config2.options.workingDirectory).toBe('test-directory-2');
expect(config2.options.packageManager).toBe('yarn');
});

describe('script', () => {
const scriptToRun = `console.log('test mesagge with "double quotes" and \\'single quote\\'.')`;

test('should generate proper command in npm context', () => {
const task = new NodeRunScriptTask(scriptToRun, undefined, 'npm');
expect(task.toConfiguration().options.packageName)
.toBe(`exec --call "node -e \\"console.log('test mesagge with ' + String.fromCharCode(34) + 'double quotes' + String.fromCharCode(34) + ' and \\'single quote\\'.')\\""`);
});

test('should generate proper command in yarn context', () => {
const task = new NodeRunScriptTask(scriptToRun, undefined, 'yarn');
expect(task.toConfiguration().options.packageName)
.toBe(`node -e "console.log('test mesagge with \\"double quotes\\" and \\\\'single quote\\\\'.')"`);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
TaskConfiguration,
TaskConfigurationGenerator,
} from '@angular-devkit/schematics';
import {
NodePackageName,
NodePackageTaskOptions,
} from '@angular-devkit/schematics/tasks/package-manager/options';
import {
getPackageManager,
type SupportedPackageManagers,
} from '../../utility/package-manager-runner';

/**
* Configuration used to run Node script via Package Manager.
* Warning: The command only supports single quote strings when run with NPM. In NPM, the " character will be replaced by its char code
* Note that this only works if the necessary files are created on the disk (doesn't work on tree)
*/
export class NodeRunScriptTask implements TaskConfigurationGenerator<NodePackageTaskOptions> {
constructor(
private readonly script: string,
private readonly workingDirectory?: string,
private readonly packageManager?: SupportedPackageManagers
) {}

public toConfiguration(): TaskConfiguration<NodePackageTaskOptions> {
const packageManager = this.packageManager || getPackageManager();
const scriptString = JSON.stringify(this.script);
const scriptStringInQuotes = this.script
.replace(/"/g, '\' + String.fromCharCode(34) + \'');
const script = packageManager === 'npm'
? `exec --call "node -e \\"${scriptStringInQuotes}\\""`
: `node -e ${scriptString}`;
return {
name: NodePackageName,
options: {
command: 'exec',
packageName: script,
workingDirectory: this.workingDirectory,
packageManager
}
};
}
}
9 changes: 8 additions & 1 deletion packages/@o3r/workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@
},
"generatorDependencies": {
"@angular/material": "~18.2.0",
"@commitlint/cli": "^19.0.0",
"@commitlint/config-angular": "^19.0.0",
"@commitlint/config-conventional": "^19.0.0",
"@commitlint/types": "^19.0.0",
"@ngrx/router-store": "~18.1.0",
"@ngrx/effects": "~18.1.0",
"@ngrx/store-devtools": "~18.1.0",
"lerna": "^8.1.7"
"editorconfig-checker": "^5.1.8",
"husky": "~9.1.0",
"lerna": "^8.1.7",
"lint-staged": "^15.0.0"
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0"
Expand Down
7 changes: 6 additions & 1 deletion packages/@o3r/workspace/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ describe('new otter workspace', () => {
'jest.config.js',
'tsconfig.builders.json',
'tsconfig.json',
'testing/setup-jest.ts'];
'testing/setup-jest.ts'
];
expect(() => packageManagerExec({ script: 'ng', args: ['g', 'library', libName] }, execAppOptions)).not.toThrow();
expect(existsSync(path.join(workspacePath, 'project'))).toBe(false);
generatedLibFiles.forEach((file) => expect(existsSync(path.join(inLibraryPath, file))).toBe(true));
Expand All @@ -134,5 +135,9 @@ describe('new otter workspace', () => {
expect(rootPackageJson.workspaces).toContain('apps/*');
expect(existsSync(path.join(workspacePath, '.renovaterc.json'))).toBe(true);
expect(existsSync(path.join(workspacePath, '.editorconfig'))).toBe(true);
expect(existsSync(path.join(workspacePath, '.husky/commit-msg'))).toBe(true);
expect(existsSync(path.join(workspacePath, '.husky/pre-commit'))).toBe(true);
expect(existsSync(path.join(workspacePath, 'commitlint.config.cts'))).toBe(true);
await expect(fs.readFile(path.join(workspacePath, '.husky/pre-commit'), { encoding: 'utf8' })).resolves.toMatch(/lint-stage/);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import * as path from 'node:path';
import {
Tree,
} from '@angular-devkit/schematics';
import {
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import {
firstValueFrom,
} from 'rxjs';
import {
editPackageJson,
generateCommitLintConfig,
getCommitHookInitTask,
} from './index';

const collectionPath = path.join(__dirname, '..', '..', '..', '..', 'collection.json');

describe('getCommitHookInitTask', () => {
let context: any;

beforeEach(() => {
context = {
addTask: jest.fn().mockReturnValue({ id: 123 })
};
});

test('should correctly register the tasks', () => {
const runAfter = [{ id: 111 }];
getCommitHookInitTask(context)(runAfter);

expect(context.addTask).toHaveBeenNthCalledWith(1, expect.objectContaining({ script: 'husky init' }), runAfter);
expect(context.addTask).toHaveBeenNthCalledWith(2, expect.objectContaining({ script: expect.stringMatching(/\.husky\/pre-commit/) }), [{ id: 123 }]);
expect(context.addTask).toHaveBeenNthCalledWith(2, expect.objectContaining({ script: expect.stringMatching(/exec lint-stage/) }), [{ id: 123 }]);
});
});

describe('generateCommitLintConfig', () => {
const initialTree = new UnitTestTree(Tree.empty());
const apply = jest.fn();
jest.mock('@angular-devkit/schematics', () => ({
apply,
getTemplateFolder: jest.fn(),
template: jest.fn(),
renameTemplateFiles: jest.fn(),
url: jest.fn(),
mergeWith: jest.fn().mockReturnValue(initialTree)
}));

test('should generate template', () => {
expect(() => generateCommitLintConfig()(initialTree, {} as any)).not.toThrow();
expect(apply).not.toHaveBeenCalled();
});
});

describe('editPackageJson', () => {
let initialTree: UnitTestTree;

beforeEach(() => {
initialTree = new UnitTestTree(Tree.empty());
initialTree.create('/package.json', '{}');
});

test('should add stage-lint if not present', async () => {
const runner = new SchematicTestRunner(
'@o3r/workspace',
collectionPath
);
const tree = await firstValueFrom(runner.callRule(editPackageJson, initialTree));
expect((tree.readJson('/package.json') as any)['lint-staged']).toBeDefined();
});

test('should not touche stage-lint if present', async () => {
initialTree.overwrite('/package.json', '{"lint-staged": "test"}');
const runner = new SchematicTestRunner(
'@o3r/workspace',
collectionPath
);
const tree = await firstValueFrom(runner.callRule(editPackageJson, initialTree));
expect((tree.readJson('/package.json') as any)['lint-staged']).toBe('test');
});
});
Loading
Loading