dceky 1.0.0-beta-auto-import.2 → 1.0.0-beta-auto-import.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
1
  /**
2
- * Generate a file containing paths to all command files in cypress/commands
2
+ * Generate an index.ts file that imports and runs all command files in cypress/commands
3
3
  * This should be called from cypress.config.js (Node.js context)
4
- * @param projectRoot - The root directory of the Cypress project (optional, defaults to process.cwd())
5
4
  * @returns The path to the generated file
6
- * @author Gabe Abrams
5
+ * @author Yuen Ler Chow
7
6
  */
8
7
  declare const genCommandPaths: () => string;
9
8
  export default genCommandPaths;
@@ -36,35 +36,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  var fs = __importStar(require("fs"));
37
37
  var path = __importStar(require("path"));
38
38
  /**
39
- * Generate a file containing paths to all command files in cypress/commands
39
+ * Generate an index.ts file that imports and runs all command files in cypress/commands
40
40
  * This should be called from cypress.config.js (Node.js context)
41
- * @param projectRoot - The root directory of the Cypress project (optional, defaults to process.cwd())
42
41
  * @returns The path to the generated file
43
- * @author Gabe Abrams
42
+ * @author Yuen Ler Chow
44
43
  */
45
44
  var genCommandPaths = function () {
46
45
  var root = process.cwd();
47
- var cypressCommandsDir = path.resolve(root, 'cypress', 'commands');
48
- var outputFile = path.resolve(cypressCommandsDir, '.dceky-paths.js');
46
+ var cypressCommandsDir = path.resolve(root, 'cypress/commands');
47
+ var outputFile = path.resolve(cypressCommandsDir, 'index.ts');
49
48
  // Check if the directory exists
50
49
  if (!fs.existsSync(cypressCommandsDir)) {
51
50
  // eslint-disable-next-line no-console
52
51
  console.warn("Cypress commands directory not found at: ".concat(cypressCommandsDir));
53
52
  // Create an empty file so init doesn't fail
54
- fs.writeFileSync(outputFile, 'module.exports = [];\n');
53
+ fs.writeFileSync(outputFile, '// Auto-generated by dceky - do not edit manually\n');
55
54
  return outputFile;
56
55
  }
57
56
  // Get all files in the directory
58
57
  var files = fs.readdirSync(cypressCommandsDir);
59
- var commandPaths = [];
58
+ var commandFiles = [];
60
59
  // Filter out non-JS/TS files and process each file
61
60
  files.forEach(function (file) {
62
- // Skip non-JS files (like .d.ts, .map, etc.)
61
+ // Skip non-JS/TS files (like .d.ts, .map, etc.)
63
62
  if (!file.endsWith('.js') && !file.endsWith('.ts')) {
64
63
  return;
65
64
  }
66
- // Skip index files and the generated paths file
67
- if (file === 'index.js' || file === 'index.ts' || file === '.dceky-paths.js') {
65
+ // Skip index files
66
+ if (file === 'index.js' || file === 'index.ts') {
68
67
  return;
69
68
  }
70
69
  var filePath = path.join(cypressCommandsDir, file);
@@ -73,13 +72,24 @@ var genCommandPaths = function () {
73
72
  if (!stats.isFile()) {
74
73
  return;
75
74
  }
76
- // Store the relative path from cypress/commands
77
- commandPaths.push(file);
75
+ // Store the file name
76
+ commandFiles.push(file);
78
77
  });
79
- var content = "// Auto-generated by dceky - do not edit manually\nmodule.exports = ".concat(JSON.stringify(commandPaths, null, 2), ";\n");
78
+ // Generate require statements and function calls
79
+ var requires = [];
80
+ var calls = [];
81
+ commandFiles.forEach(function (file) {
82
+ var requirePath = "./".concat(file);
83
+ // Create a safe variable name (replace non-alphanumeric with underscore)
84
+ var importName = file.replace(/\.(js|ts)$/, '');
85
+ var varName = importName.replace(/[^a-zA-Z0-9]/g, '_');
86
+ requires.push("const ".concat(varName, " = require('").concat(requirePath, "');"));
87
+ calls.push("".concat(varName, ".default();"));
88
+ });
89
+ var content = "// Auto-generated by dceky - do not edit manually\n".concat(requires.join('\n'), "\n\n").concat(calls.join('\n'), "\n");
80
90
  fs.writeFileSync(outputFile, content);
81
91
  // eslint-disable-next-line no-console
82
- console.log("Generated command paths file: ".concat(outputFile, " (").concat(commandPaths.length, " commands)"));
92
+ console.log("Generated command index file: ".concat(outputFile, " (").concat(commandFiles.length, " commands)"));
83
93
  return outputFile;
84
94
  };
85
95
  exports.default = genCommandPaths;
@@ -1 +1 @@
1
- {"version":3,"file":"genCommandPaths.js","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AAG,OAAO,gBAAa,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,IAAM,OAAO,GAAG,6DAChB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,iBAEnB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OACjB,CAAC;IAEA,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAEtC,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,wCAAiC,UAAU,eAAK,YAAY,CAAC,MAAM,eAAY,CAAC,CAAC;IAE7F,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,kBAAe,eAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dceky",
3
- "version": "1.0.0-beta-auto-import.2",
3
+ "version": "1.0.0-beta-auto-import.3",
4
4
  "description": "Cypress toolkit for Harvard DCE",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -2,39 +2,38 @@ import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
 
4
4
  /**
5
- * Generate a file containing paths to all command files in cypress/commands
5
+ * Generate an index.ts file that imports and runs all command files in cypress/commands
6
6
  * This should be called from cypress.config.js (Node.js context)
7
- * @param projectRoot - The root directory of the Cypress project (optional, defaults to process.cwd())
8
7
  * @returns The path to the generated file
9
- * @author Gabe Abrams
8
+ * @author Yuen Ler Chow
10
9
  */
11
10
  const genCommandPaths = (): string => {
12
11
  const root = process.cwd();
13
- const cypressCommandsDir = path.resolve(root, 'cypress', 'commands');
14
- const outputFile = path.resolve(cypressCommandsDir, '.dceky-paths.js');
12
+ const cypressCommandsDir = path.resolve(root, 'cypress/commands');
13
+ const outputFile = path.resolve(cypressCommandsDir, 'index.ts');
15
14
 
16
15
  // Check if the directory exists
17
16
  if (!fs.existsSync(cypressCommandsDir)) {
18
17
  // eslint-disable-next-line no-console
19
18
  console.warn(`Cypress commands directory not found at: ${cypressCommandsDir}`);
20
19
  // Create an empty file so init doesn't fail
21
- fs.writeFileSync(outputFile, 'module.exports = [];\n');
20
+ fs.writeFileSync(outputFile, '// Auto-generated by dceky - do not edit manually\n');
22
21
  return outputFile;
23
22
  }
24
23
 
25
24
  // Get all files in the directory
26
25
  const files = fs.readdirSync(cypressCommandsDir);
27
- const commandPaths: string[] = [];
26
+ const commandFiles: string[] = [];
28
27
 
29
28
  // Filter out non-JS/TS files and process each file
30
29
  files.forEach((file) => {
31
- // Skip non-JS files (like .d.ts, .map, etc.)
30
+ // Skip non-JS/TS files (like .d.ts, .map, etc.)
32
31
  if (!file.endsWith('.js') && !file.endsWith('.ts')) {
33
32
  return;
34
33
  }
35
34
 
36
- // Skip index files and the generated paths file
37
- if (file === 'index.js' || file === 'index.ts' || file === '.dceky-paths.js') {
35
+ // Skip index files
36
+ if (file === 'index.js' || file === 'index.ts') {
38
37
  return;
39
38
  }
40
39
 
@@ -46,18 +45,34 @@ const genCommandPaths = (): string => {
46
45
  return;
47
46
  }
48
47
 
49
- // Store the relative path from cypress/commands
50
- commandPaths.push(file);
48
+ // Store the file name
49
+ commandFiles.push(file);
50
+ });
51
+
52
+ // Generate require statements and function calls
53
+ const requires: string[] = [];
54
+ const calls: string[] = [];
55
+
56
+ commandFiles.forEach((file) => {
57
+ const requirePath = `./${file}`;
58
+ // Create a safe variable name (replace non-alphanumeric with underscore)
59
+ const importName = file.replace(/\.(js|ts)$/, '');
60
+ const varName = importName.replace(/[^a-zA-Z0-9]/g, '_');
61
+
62
+ requires.push(`const ${varName} = require('${requirePath}');`);
63
+ calls.push(`${varName}.default();`);
51
64
  });
52
65
 
53
66
  const content = `// Auto-generated by dceky - do not edit manually
54
- module.exports = ${JSON.stringify(commandPaths, null, 2)};
67
+ ${requires.join('\n')}
68
+
69
+ ${calls.join('\n')}
55
70
  `;
56
71
 
57
72
  fs.writeFileSync(outputFile, content);
58
73
 
59
74
  // eslint-disable-next-line no-console
60
- console.log(`Generated command paths file: ${outputFile} (${commandPaths.length} commands)`);
75
+ console.log(`Generated command index file: ${outputFile} (${commandFiles.length} commands)`);
61
76
 
62
77
  return outputFile;
63
78
  };