mirror of
				https://github.com/lingble/twenty.git
				synced 2025-11-04 06:37:56 +00:00 
			
		
		
		
	#### Description This PR resolves issue #7903 regarding the Storybook configuration for Windows development environments. Previously, the configuration script generated forward slashes instead of backslashes, leading to errors when running the command `npx nx run twenty-front:storybook:serve:dev --configuration=modules` on Windows systems. #### Changes Made - Updated the Storybook configuration to ensure that backslashes are used in file paths for Windows environments, preventing command execution errors. #### How to Test 1. **Run Storybook Command**: - On a Windows machine, execute the command: ``` npx nx run twenty-front:storybook:serve:dev --configuration=modules ``` - Ensure that the command runs successfully without any path-related errors. 2. **Verify Configuration**: - Check the Storybook configuration files to confirm that paths are using backslashes where applicable. - Test the same command on non-Windows environments to verify that there are no regressions. #### Related Issue - Fixes #7903
		
			
				
	
	
		
			106 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import * as fs from 'fs';
 | 
						|
import path from 'path';
 | 
						|
import slash from 'slash';
 | 
						|
 | 
						|
const extensions = ['.ts', '.tsx'];
 | 
						|
const excludedExtensions = [
 | 
						|
  '.test.ts',
 | 
						|
  '.test.tsx',
 | 
						|
  '.spec.ts',
 | 
						|
  '.spec.tsx',
 | 
						|
  '.stories.ts',
 | 
						|
  '.stories.tsx',
 | 
						|
];
 | 
						|
const excludedDirectories = [
 | 
						|
  '__tests__',
 | 
						|
  '__mocks__',
 | 
						|
  '__stories__',
 | 
						|
  'internal',
 | 
						|
];
 | 
						|
const srcPath = path.resolve('packages/twenty-ui/src');
 | 
						|
 | 
						|
/**
 | 
						|
 * @param {string} directoryPath
 | 
						|
 * @returns {string[]}
 | 
						|
 */
 | 
						|
const getSubDirectoryPaths = (directoryPath) =>
 | 
						|
  fs
 | 
						|
    .readdirSync(directoryPath)
 | 
						|
    .filter(
 | 
						|
      (fileOrDirectoryName) =>
 | 
						|
        !excludedDirectories.includes(fileOrDirectoryName) &&
 | 
						|
        fs
 | 
						|
          .statSync(path.join(directoryPath, fileOrDirectoryName))
 | 
						|
          .isDirectory(),
 | 
						|
    )
 | 
						|
    .map((subDirectoryName) => path.join(directoryPath, subDirectoryName));
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @param {string} directoryPath
 | 
						|
 * @returns {string[]}
 | 
						|
 */
 | 
						|
const getDirectoryPathsRecursive = (directoryPath) => [
 | 
						|
  directoryPath,
 | 
						|
  ...getSubDirectoryPaths(directoryPath).flatMap(getDirectoryPathsRecursive),
 | 
						|
];
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @param {string} directoryPath
 | 
						|
 * @returns {string[]}
 | 
						|
 */
 | 
						|
const getFilesPaths = (directoryPath) =>
 | 
						|
  fs
 | 
						|
    .readdirSync(directoryPath)
 | 
						|
    .filter(
 | 
						|
      (filePath) =>
 | 
						|
        fs.statSync(path.join(directoryPath, filePath)).isFile() &&
 | 
						|
        !filePath.startsWith('index.') &&
 | 
						|
        extensions.some((extension) => filePath.endsWith(extension)) &&
 | 
						|
        excludedExtensions.every(
 | 
						|
          (excludedExtension) => !filePath.endsWith(excludedExtension),
 | 
						|
        ),
 | 
						|
    );
 | 
						|
 | 
						|
const moduleDirectories = getSubDirectoryPaths(srcPath);
 | 
						|
 | 
						|
moduleDirectories.forEach((moduleDirectoryPath) => {
 | 
						|
  const directoryPaths = getDirectoryPathsRecursive(moduleDirectoryPath);
 | 
						|
 | 
						|
  const moduleExports = directoryPaths
 | 
						|
    .flatMap((directoryPath) => {
 | 
						|
      const directFilesPaths = getFilesPaths(directoryPath);
 | 
						|
 | 
						|
      return directFilesPaths.map((filePath) => {
 | 
						|
        const fileName = filePath.split('.').slice(0, -1).join('.');
 | 
						|
        return `export * from './${slash(path.relative(
 | 
						|
          moduleDirectoryPath,
 | 
						|
          path.join(directoryPath, fileName),
 | 
						|
        ))}';`;
 | 
						|
      });
 | 
						|
    })
 | 
						|
    .sort((a, b) => a.localeCompare(b))
 | 
						|
    .join('\n');
 | 
						|
 | 
						|
  fs.writeFileSync(
 | 
						|
    path.join(moduleDirectoryPath, 'index.ts'),
 | 
						|
    `${moduleExports}\n`,
 | 
						|
    'utf-8',
 | 
						|
  );
 | 
						|
});
 | 
						|
 | 
						|
const mainBarrelExports = moduleDirectories
 | 
						|
  .map(
 | 
						|
    (moduleDirectoryPath) =>
 | 
						|
      `export * from './${slash(path.relative(srcPath, moduleDirectoryPath))}';`,
 | 
						|
  )
 | 
						|
  .sort((a, b) => a.localeCompare(b))
 | 
						|
  .join('\n');
 | 
						|
 | 
						|
fs.writeFileSync(
 | 
						|
  path.join(srcPath, 'index.ts'),
 | 
						|
  `${mainBarrelExports}\n`,
 | 
						|
  'utf-8',
 | 
						|
);
 |