Skip to content

fix(create): added missing deps and added test for workspace generator #97

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

Open
wants to merge 8 commits into
base: master
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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brainly-gene",
"version": "0.2.0-alpha.20",
"version": "0.7.4-alpha.7",
"license": "Apache-2.0",
"scripts": {
"build": "pnpm nx run-many --target=build --all",
Expand Down Expand Up @@ -70,6 +70,8 @@
},
"devDependencies": {
"@actions/core": "1.10.1",
"ajv": "8.8.2",
"ajv-keywords": "5.1.0",
"@babel/core": "7.16.7",
"@babel/eslint-parser": "7.16.5",
"@babel/plugin-proposal-object-rest-spread": "7.16.7",
Expand All @@ -95,6 +97,7 @@
"@nx/react": "21.1.2",
"@nx/web": "21.1.2",
"@nx/webpack": "21.1.2",
"@nx/linter": "19.8.4",
"@paperist/types-remark": "0.1.3",
"@radix-ui/react-slot": "1.1.0",
"@storybook/addon-actions": "7.6.20",
Expand Down Expand Up @@ -167,7 +170,7 @@
"jsonc-eslint-parser": "2.1.0",
"lint-staged": "9.5.0",
"lucide-react": "0.453.0",
"mini-css-extract-plugin": "2.2.0",
"mini-css-extract-plugin": "2.9.2",
"msw": "0.49.2",
"msw-storybook-addon": "1.6.3",
"prettier-package-json": "2.8.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/create/bin/create-gene-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ async function runCommands() {
'--nxCloud=skip',
]);

// modify package.json to add storybook preset to have name of the workspace, currently name is wrongly set so make sure that it will be "name": name <- passed by user
const packageJsonPath = path.resolve(name, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
packageJson.name = name;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

//update nx.json to add workspaceLayout to have libsDir: "libs"
const nxJsonPath = path.resolve(name, 'nx.json');
const nxJson = JSON.parse(fs.readFileSync(nxJsonPath, 'utf8'));
nxJson.workspaceLayout = {
libsDir: 'libs',
appsDir: 'apps',
};
fs.writeFileSync(nxJsonPath, JSON.stringify(nxJson, null, 2));

console.log(
`Workspace ${name} created successfully with NX version ${nxVersion}!`,
);
Expand Down Expand Up @@ -101,6 +116,9 @@ async function runCommands() {
console.log('Generating gene-workspace with nx');
await execCommand('nx', ['g', '@brainly-gene/tools:gene-workspace']);

console.log('Initializing storybook config');
await execCommand('nx', ['g', '@brainly-gene/tools:storybook-init']);

console.log('Generating e2e testing providers');
await execCommand('nx', ['g', '@brainly-gene/tools:e2e-providers']);
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions packages/create/bin/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"@nx/react",
"@nx/web",
"@nx/workspace",
"@nx/linter",
"ajv",
"ajv-keywords",
"@storybook/addon-actions",
"@storybook/addon-backgrounds",
"@storybook/addon-knobs",
Expand Down Expand Up @@ -89,6 +92,7 @@
"eslint-plugin-react",
"eslint-plugin-react-hooks",
"eslint-plugin-regexp",
"mini-css-extract-plugin",
"inquirer-search-checkbox",
"inquirer-search-list",
"jest",
Expand Down
14 changes: 9 additions & 5 deletions packages/create/bin/versions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"@brainly-gene/core": "0.2.0-alpha.20",
"@brainly-gene/next": "0.2.0-alpha.20",
"@brainly-gene/core": "0.7.4-alpha.7",
"@brainly-gene/next": "0.7.4-alpha.7",
"@nx/next": "21.1.2",
"@sentry/react": "7.77.0",
"@tanstack/react-query": "5.55.4",
Expand Down Expand Up @@ -47,18 +47,21 @@
"zen-observable": "0.8.15",
"zen-observable-ts": "1.1.0",
"find-up": "5.0.0",
"mini-css-extract-plugin": "2.2.0"
"mini-css-extract-plugin": "2.9.2"
},
"devDependencies": {
"@brainly-gene/eslint-plugin": "0.2.0-alpha.20",
"@brainly-gene/tools": "0.2.0-alpha.20",
"@brainly-gene/eslint-plugin": "0.7.4-alpha.7",
"@brainly-gene/tools": "0.7.4-alpha.7",
"@nx/cypress": "21.1.2",
"@nx/devkit": "21.1.2",
"@nx/eslint-plugin": "21.1.2",
"@nx/jest": "21.1.2",
"@nx/react": "21.1.2",
"@nx/web": "21.1.2",
"@nx/workspace": "21.1.2",
"@nx/linter": "19.8.4",
"ajv": "8.8.2",
"ajv-keywords": "5.1.0",
"@storybook/addon-actions": "7.6.20",
"@storybook/addon-backgrounds": "7.6.20",
"@storybook/addon-knobs": "7.1.1",
Expand Down Expand Up @@ -89,6 +92,7 @@
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-regexp": "2.6.0",
"mini-css-extract-plugin": "2.9.2",
"inquirer-search-checkbox": "1.0.0",
"inquirer-search-list": "1.2.6",
"jest": "29.4.3",
Expand Down
7 changes: 3 additions & 4 deletions packages/gene-tools/src/executors/storybook/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ export interface SecureServeExecutorOptions {

export async function storybookExecutor(
options: SecureServeExecutorOptions,
context: ExecutorContext,
context: ExecutorContext
) {
if (!context.projectName) {
return {
success: false,
};
}

const target =
options.command === 'build' ? 'build-nrwl-storybook' : 'nrwl-storybook';
const target = options.command === 'build' ? 'build-storybook' : 'storybook';

const packageManager = detectPackageManager();

Expand All @@ -29,7 +28,7 @@ export async function storybookExecutor(
{
env: { ...process.env, NODE_OPTIONS: '--openssl-legacy-provider' },
shell: true,
},
}
);

let success = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Tree } from '@nx/devkit';
import {
formatFiles,
generateFiles,
getWorkspaceLayout,
installPackagesTask,
joinPathFragments,
readJson,
Expand All @@ -12,18 +13,21 @@ import type { AssetsLibraryGenerator } from './schema';
import libraryGenerator from '../library-generator';

export default async function (tree: Tree, schema: AssetsLibraryGenerator) {
const { libsDir } = getWorkspaceLayout(tree);
const directory = joinPathFragments(libsDir, 'assets');

const currentPackageJson = readJson(tree, 'package.json');

await libraryGenerator(tree, {
name: 'assets',
directory: 'libs/assets',
directory,
tags: 'type:utility',
});

generateFiles(
tree,
joinPathFragments(__dirname, './files'),
'libs/assets/src',
joinPathFragments(directory, 'src'),
{
...schema,
tmpl: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Tree } from '@nx/devkit';
import {
formatFiles,
generateFiles,
getWorkspaceLayout,
installPackagesTask,
joinPathFragments,
readJson,
Expand All @@ -10,18 +11,21 @@ import {
import libraryGenerator from '../library-generator';

export default async function (tree: Tree) {
const { libsDir } = getWorkspaceLayout(tree);
const directory = joinPathFragments(libsDir, 'e2e-testing-providers');

const currentPackageJson = readJson(tree, 'package.json');

await libraryGenerator(tree, {
name: 'e2e-testing-providers',
directory: 'libs/e2e-testing-providers',
directory,
tags: 'type:utility',
});

generateFiles(
tree,
joinPathFragments(__dirname, './files'),
'libs/e2e-testing-providers/src',
joinPathFragments(directory, 'src'),
{
tmpl: '',
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import geneWorkspaceGenerator from './index';

describe('gene-workspace generator', () => {
it('should generate files without double slash issues', async () => {
const tree = createTreeWithEmptyWorkspace();

// Add basic files that the generator expects
tree.write(
'package.json',
JSON.stringify({
name: 'test-workspace',
version: '1.0.0',
})
);

tree.write(
'nx.json',
JSON.stringify({
npmScope: 'test',
})
);

console.log('🔍 Before running generator:');
console.log('Tree changes:', tree.listChanges());

await geneWorkspaceGenerator(tree);

console.log('🔍 After running generator:');
console.log('Tree changes:', tree.listChanges());

// Check if the problematic file exists
const eslintPath = 'libs/assets/.eslintrc.json';
const hasEslintFile = tree.exists(eslintPath);
console.log(
`\n🔍 Checking for ${eslintPath}: ${
hasEslintFile ? '✅ EXISTS' : '❌ MISSING'
}`
);

if (hasEslintFile) {
console.log('📄 ESLint file content:');
console.log(tree.read(eslintPath, 'utf-8'));
}

// List all files in libs/assets
console.log('\n📂 Files in libs/assets:');
if (tree.exists('libs/assets')) {
// Use the correct method to list directory contents
const changes = tree.listChanges();
const assetsFiles = changes
.filter((change) => change.path.startsWith('libs/assets/'))
.map((change) => change.path);
console.log(assetsFiles);
} else {
console.log('❌ libs/assets directory does not exist');
}

// The test should pass if no double slash issues
expect(hasEslintFile).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ export default async function (tree: Tree) {
tree.write('apps/.gitkeep', '');
tree.write('libs/.gitkeep', '');

await assetsLibraryGenerator(tree, {
withStyleGuide: true,
});
try {
await assetsLibraryGenerator(tree, {
withStyleGuide: true,
});

await translationsLibraryGenerator(tree);
await translationsLibraryGenerator(tree);

generateFiles(tree, joinPathFragments(__dirname, './files'), './', {});
generateFiles(tree, joinPathFragments(__dirname, './files'), './', {});
} catch (error) {
console.error('Error creating assets library:', error);
}

// Update .eslintrc.json
const updatedEslintJson = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function (tree: Tree, schema: GeneLibraryGenerator) {
const currentPackageJson = readJson(tree, 'package.json');
const npmScope = getNpmScope(tree);

const baseDirectory = schema.directory ? `${schema.directory}/` : '';
const baseDirectory = schema.directory || '';

await libraryGenerator(tree, {
name: schema.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from '@storybook/react';
import {<%= pascalCaseFileName %>} from './<%= pascalCaseFileName %>';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {StorybookProviders} from '@<%= npmScope %>/e2e-testing-providers';
import {StorybookProviders} from '@<%= e2eTestingProvidersPath %>';

const meta: Meta = {
title: '<%= pascalCaseFileName %>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from '@storybook/react';
import {<%= pascalCaseFileName %>} from './<%= pascalCaseFileName %>';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {StorybookProviders} from '@<%= npmScope %>/e2e-testing-providers';
import {StorybookProviders} from '@<%= e2eTestingProvidersPath %>';

const meta: Meta = {
title: '<%= pascalCaseFileName %>',
Expand Down
8 changes: 8 additions & 0 deletions packages/gene-tools/src/generators/module-generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getProjects,
readJson,
writeJson,
getWorkspaceLayout,
} from '@nx/devkit';
import libraryGenerator from '../library-generator';
import { cypressProjectGenerator } from '@nx/storybook';
Expand Down Expand Up @@ -51,6 +52,11 @@ export default async function (tree: Tree, schema: BrainlyModuleGenerator) {
})
.map(([projectName]) => projectName);

const { libsDir } = getWorkspaceLayout(tree);
const e2eTestingProvidersPath = libsDir
? `${npmScope}/${libsDir}/e2e-testing-providers`
: `${npmScope}/e2e-testing-providers`;

const appName =
schema.appName ||
(await promptSelectAppName(
Expand Down Expand Up @@ -131,6 +137,7 @@ Learn more about modules naming on: https://brainly.github.io/gene/gene/modules/
tmpl: '',
errorBoundary,
npmScope,
e2eTestingProvidersPath,
}
);

Expand Down Expand Up @@ -286,6 +293,7 @@ Learn more about modules naming on: https://brainly.github.io/gene/gene/modules/
tmpl: '',
errorBoundary,
npmScope,
e2eTestingProvidersPath,
}
);

Expand Down
Loading
Loading