Skip to content

Commit 3ebc6e1

Browse files
authored
Create __buildScripts.js
1 parent ded7657 commit 3ebc6e1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { Workspace } = require('../index.js');
2+
const Soup = require('@stews/soup');
3+
const fs = require('fs');
4+
5+
6+
Workspace.newF("__buildScripts", function() { // function for building the workspace.script property
7+
8+
// a list of the script's raw code excluding meta files bc those will be used later
9+
let scriptFiles = fs.readdirSync(this.scriptsDir).filter( file => !file.endsWith(".meta"));
10+
11+
12+
scriptFiles.forEach( file => {
13+
let name = file.replace(".unity", ""); // name of the script
14+
const script = new this.Script(name); // creates a new script typing
15+
16+
let data = fs.readFileSync(`${this.scriptDir}/${file}`, 'utf8'); // script data
17+
let meta = fs.readFileSync(`${this.scriptDir}/${file}.meta`, 'utf8'); // script metadata
18+
19+
script.translate(data, meta); // translates the scripts's metadata and data into usable JSON data
20+
this.scripts.push(name, script); // pushes the new script into the script group
21+
});
22+
});

0 commit comments

Comments
 (0)