<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — Loading collections from any /collections subdirectory]]></title>
		<link>https://forexsb.com/forum/topic/9885/loading-collections-from-any-collections-subdirectory/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/9885/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Loading collections from any /collections subdirectory.]]></description>
		<lastBuildDate>Tue, 19 Nov 2024 23:45:00 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Loading collections from any /collections subdirectory]]></title>
			<link>https://forexsb.com/forum/post/81913/#p81913</link>
			<description><![CDATA[<p>Thank you :-)</p>]]></description>
			<author><![CDATA[null@example.com (geektrader)]]></author>
			<pubDate>Tue, 19 Nov 2024 23:45:00 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/81913/#p81913</guid>
		</item>
		<item>
			<title><![CDATA[Re: Loading collections from any /collections subdirectory]]></title>
			<link>https://forexsb.com/forum/post/81883/#p81883</link>
			<description><![CDATA[<p>&gt; It&#039;s super helpful for organizing strategies across different projects. <br />It is a good idea!</p><p>This can be better implemented with additional options.</p><p>Something like: <br /> <strong>--input-dir</strong> /path/to/my/collections<br /> <strong>--input-pattern</strong> [SERVER]-[SYMBOL]<br /> <strong>--input-recursive</strong> true</p><p>I may think of it.</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Sun, 17 Nov 2024 10:07:21 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/81883/#p81883</guid>
		</item>
		<item>
			<title><![CDATA[Loading collections from any /collections subdirectory]]></title>
			<link>https://forexsb.com/forum/post/81872/#p81872</link>
			<description><![CDATA[<p>Hi again Mr. Popov,</p><p>another quick suggestion for the next EG release regarding collection file handling.</p><p>As I´ve mentioned a while ago, I&#039;ve been patching collection.js to allow loading collections from any /collections subdirectory relative to the working directory. It&#039;s super helpful for organizing strategies across different projects. Here are the exact changes needed:</p><p>1. Add &#039;resolve&#039; to the path imports:</p><div class="codebox"><pre><code>const {join, parse, isAbsolute, resolve} = require(&quot;path&quot;);</code></pre></div><p>2. Modify the loadCollection function to handle paths relative to the current working directory:</p><div class="codebox"><pre><code>function loadCollection(inputPath, inputKeys, dataId, dataEndTime, suppressInputError) {
    if (typeof inputPath === &quot;string&quot; &amp;&amp; inputPath.length &gt; 0) {
        try {
            let collectionPath = replacePlaceholders(inputPath, dataId, dataEndTime);

            // If path is not absolute, prepend the collections directory
            if (!isAbsolute(collectionPath) &amp;&amp; 
                (parse(collectionPath).dir === &quot;&quot; || !collectionPath.includes(&quot;collections&quot;))) {
                collectionPath = join(&quot;.&quot;, &quot;collections&quot;, collectionPath);
            }

            // Resolve the path relative to the current working directory
            collectionPath = resolve(process.cwd(), collectionPath);

            // Check if the path exists and is a directory or file
            if (existsSync(collectionPath)) {
                const stat = statSync(collectionPath);
                if (stat.isDirectory()) {
                    return readCollectionDir(collectionPath, inputKeys);
                } else if (stat.isFile()) {
                    return readCollectionFile(collectionPath, inputKeys);
                }
            }

            // If we reach here, try adding .json extension if missing
            if (!collectionPath.toLowerCase().endsWith(&quot;.json&quot;)) {
                collectionPath += &quot;.json&quot;;
                if (existsSync(collectionPath)) {
                    return readCollectionFile(collectionPath, inputKeys);
                }
            }

            if (!suppressInputError) {
                console.error(`${color.Red}Cannot open input file: ${color.Bright}${collectionPath}${color.Reset}`);
            }
            return [];
        } catch (e) {
            console.error(`${color.Red}${color.Bright}${e.message}${color.Reset}`);
            return [];
        }
    } else if (Array.isArray(inputPath) &amp;&amp; inputPath.length &gt; 0) {
        return inputPath.flatMap(file =&gt; 
            loadCollection(file, inputKeys, dataId, dataEndTime, suppressInputError)
        );
    }

    return [];
}</code></pre></div><p>This replaces the current path resolution logic in loadCollection and makes it much more flexible. The changes maintain backward compatibility while allowing users to organize their collections in subdirectories.</p><p>Would you consider adding this to the next release? Would save me from patching after each update :-)</p><p>Thanks as always!</p>]]></description>
			<author><![CDATA[null@example.com (geektrader)]]></author>
			<pubDate>Fri, 15 Nov 2024 11:57:05 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/81872/#p81872</guid>
		</item>
	</channel>
</rss>
