@@ -6,7 +6,9 @@ import _traverse from "@babel/traverse";
66import * as t from "@babel/types" ;
77import { promisify } from "util" ;
88import { Preprocessor } from "content-tag" ;
9+ import "dotenv/config" ;
910
11+ const discourseDir = process . env . DISCOURSE_CORE ;
1012const traverse = _traverse . default ;
1113const readdir = promisify ( fs . readdir ) ;
1214const readFile = promisify ( fs . readFile ) ;
@@ -25,7 +27,6 @@ const EXCLUDED_DIR_PATTERNS = [
2527 "/discourse/plugins/discourse-deprecation-collector/" ,
2628] ;
2729const filesToDebug = [ ] ;
28- let pathToRemove ;
2930
3031async function isExcludedDir ( filePath ) {
3132 return EXCLUDED_DIR_PATTERNS . some ( ( pattern ) => filePath . includes ( pattern ) ) ;
@@ -34,7 +35,7 @@ async function isExcludedDir(filePath) {
3435async function parseFile ( filePath ) {
3536 let hasAppEventsTrigger = { result : false } ;
3637 let code = await readFile ( filePath , "utf8" ) ;
37- const relativeFilePath = filePath . replace ( pathToRemove , "" ) ;
38+ const relativeFilePath = filePath . replace ( discourseDir , "" ) ;
3839
3940 try {
4041 if ( filePath . endsWith ( ".gjs" ) ) {
@@ -270,14 +271,14 @@ async function parseDirectory(directoryPath) {
270271
271272// Main script
272273( async ( ) => {
273- if ( process . argv . length < 3 ) {
274- console . log ( "Usage: node extract_app_events.mjs <CODEBASE_DIR>" ) ;
274+ if ( process . argv . length != 2 ) {
275+ console . log (
276+ "Usage: node extract_app_events.mjs, Remember to define DISCOURSE_CORE in an .env file"
277+ ) ;
275278 process . exit ( 1 ) ;
276279 }
277280
278- const directoryPath = process . argv [ 2 ] ;
279- pathToRemove = directoryPath ;
280- const eventTriggers = await parseDirectory ( directoryPath ) ;
281+ const eventTriggers = await parseDirectory ( discourseDir ) ;
281282
282283 if ( filesToDebug . length > 0 ) {
283284 const filesToDebugFilePath = path . join (
0 commit comments