syntaxseed / terminalfaker

Terminal Faker - A client-side Linux-like cli terminal simulation written in Javascript. Originally forked from AVGP/terminal.js.
MIT License
51 stars 20 forks source link

Refactor Initial FileSystem to load from a json file. #14

Open syntaxseed opened 5 years ago

syntaxseed commented 5 years ago

After the merge of PR #13, we have a problem. The Initial Filesystem definition is not in a format that can be easily customized.

Need to read initial state from a Json file or similar.

Could be done by adding toPlain/restore methods in FileSystem class.

The raw, customizable definition should be found in js/filesystem.js.

syntaxseed commented 5 years ago

Original Filesystem definition:

var originalFilesystem="<d name='/' path='/'>\
            <c>\
            <d name='docs' path='/docs/'>\
                <c>\
                    <d name='private' path='/docs/private/'>\
                        <c>\
                            <f name='secret.txt' path='/docs/private/'>\
                                <contents>PxNmGkl6M+jDP4AYAKZET18SEnWD5qw5LIP9174lONWslF144K9VHFIk1JA=</contents>\
                            </f>\
                        </c>\
                    </d>\
                    <f name='shoplist.txt' path='/docs/'>\
                        <contents>-Apples\n-Bananas\n-Cookies</contents>\
                    </f>\
                    <f name='ok.txt' path='/docs/'>\
                        <contents>I am ok.</contents>\
                    </f>\
                    <f name='moretodo.txt' path='/docs/'>\
                        <contents>A, B, C.</contents>\
                    </f>\
                </c>\
            </d>\
            <d name='more' path='/more/'>\
                <c>\
                    <f name='moretodo.txt' path='/more/'>\
                        <contents>Don't forget this other stuff.</contents>\
                    </f>\
                </c>\
            </d>\
            <d name='stuff' path='/stuff/'>\
                <c>\
                </c>\
            </d>\
            <f name='cool.txt' path='/'>\
                <contents>There is a hidden command in this terminal called 'secret'.</contents>\
            </f>\
            </c>\
        </d>";