Skip to content

Commit 4a2b1ad

Browse files
author
Matt Karl
committed
Work in progress Template modules
1 parent 8d1e98c commit 4a2b1ad

File tree

10 files changed

+328
-46
lines changed

10 files changed

+328
-46
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"template": {
3+
"version": "_templateVersion_",
4+
"id": "_templateId_"
5+
}
6+
}

deploy/assets/templates/default/springroll-template.json

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,124 @@
44
"version" : "1.2.0",
55
"rename" : {
66
"gitignore" : ".gitignore",
7-
"bowerrc" : ".bowerrc"
7+
"bowerrc" : ".bowerrc",
8+
"springroll": ".springroll"
9+
},
10+
"modules": {
11+
"springroll.Core": {
12+
"name": "SpringRoll Core",
13+
"required": true,
14+
"bower": {
15+
"springroll": "*"
16+
},
17+
"libraries": [
18+
"components/preloadjs/lib/preload.min.js",
19+
"components/springroll/core.min.js"
20+
],
21+
"librariesDebug": [
22+
"components/preloadjs/lib/preload.combined.js",
23+
"components/springroll/core.js"
24+
]
25+
},
26+
"springroll.CreateJSDisplay": {
27+
"name": "CreateJS Display Module",
28+
"bower": {
29+
"easeljs": "https://github.com/SpringRoll/EaselJS.git",
30+
"tweenjs": "https://github.com/SpringRoll/TweenJS.git"
31+
},
32+
"libraries": [
33+
"components/tweenjs/lib/tweenjs.min.js",
34+
"components/easeljs/lib/easeljs.min.js",
35+
"components/easeljs/lib/movieclip.min.js",
36+
"components/springroll/dist/modules/display-createjs.min.js"
37+
],
38+
"librariesDebug": [
39+
"components/tweenjs/lib/tweenjs.combined.js",
40+
"components/easeljs/lib/easeljs.combined.js",
41+
"components/easeljs/lib/movieclip.combined.js",
42+
"components/springroll/dist/modules/display-createjs.js"
43+
],
44+
"depends": "springroll.Core"
45+
},
46+
"springroll.PixiDisplay": {
47+
"name": "Pixi.js Display Module",
48+
"bower": {
49+
"pixi.js":"https://github.com/SpringRoll/pixi.js.git"
50+
},
51+
"libraries": [
52+
"components/pixi.js/bin/pixi.js",
53+
"components/springroll/dist/modules/display-pixi.min.js"
54+
],
55+
"librariesDebug": [
56+
"components/pixi.js/bin/pixi.dev.js",
57+
"components/springroll/dist/modules/display-pixi.js"
58+
],
59+
"depends": "springroll.Core"
60+
},
61+
"springroll.NativeDisplay": {
62+
"name": "Native Display Module",
63+
"libraries": "components/springroll/dist/modules/display-native.min.js",
64+
"librariesDebug": "components/springroll/dist/modules/display-native.js",
65+
"depends": "springroll.Core"
66+
},
67+
"springroll.Sound": {
68+
"name": "Sound Module",
69+
"bower": {
70+
"soundjs": "https://github.com/SpringRoll/SoundJS.git"
71+
},
72+
"libraries": [
73+
"components/soundjs/lib/soundjs.min.js",
74+
"components/soundjs/lib/flashaudioplugin.min.js",
75+
"components/springroll/dist/modules/sound.min.js"
76+
],
77+
"librariesDebug": [
78+
"components/soundjs/lib/soundjs.min.js",
79+
"components/soundjs/lib/flashaudioplugin.combined.js",
80+
"components/springroll/dist/modules/sound.js"
81+
],
82+
"depends": "springroll.Core"
83+
},
84+
"springroll.Interface": {
85+
"name": "Interface Module",
86+
"libraries": "components/springroll/dist/modules/interface.min.js",
87+
"librariesDebug": "components/springroll/dist/modules/interface.js",
88+
"depends": [
89+
"springroll.Core",
90+
"springroll.CreateJSDisplay|springroll.PixiDisplay"
91+
]
92+
},
93+
"springroll.Captions": {
94+
"name": "Captions Module",
95+
"libraries": "components/springroll/dist/modules/captions.min.js",
96+
"librariesDebug": "components/springroll/dist/modules/captions.js",
97+
"depends": "springroll.Core"
98+
},
99+
"springroll.Game": {
100+
"name": "Game Module",
101+
"libraries": "components/springroll/dist/modules/game.min.js",
102+
"librariesDebug": "components/springroll/dist/modules/game.js",
103+
"depends": [
104+
"springroll.Sound",
105+
"springroll.Core",
106+
"springroll.CreateJSDisplay|springroll.PixiDisplay"
107+
]
108+
},
109+
"springroll.Tasks": {
110+
"name": "Tasks Module",
111+
"libraries": "components/springroll/dist/modules/tasks.min.js",
112+
"librariesDebug": "components/springroll/dist/modules/tasks.js",
113+
"depends": "springroll.Core"
114+
},
115+
"springroll.Translate": {
116+
"name": "Translate Module",
117+
"libraries": "components/springroll/dist/modules/translate.min.js",
118+
"librariesDebug": "components/springroll/dist/modules/translate.js",
119+
"depends": "springroll.Core"
120+
},
121+
"springroll.Worker": {
122+
"name": "Worker Module",
123+
"libraries": "components/springroll/dist/modules/worker.min.js",
124+
"librariesDebug": "components/springroll/dist/modules/worker.js"
125+
}
8126
}
9127
}

deploy/new.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ <h1>Create New Project</h1>
139139
</div>
140140
</div>
141141
<div class="col-sm-5 col-xs-4">
142-
<!-- <div class="checkbox optional no-native">
143-
<label><input type="checkbox" class="module" value="components/springroll/dist/modules/states" checked="checked"> States Module</label>
144-
</div> -->
145142
<div class="checkbox optional">
146143
<label><input type="checkbox" class="module" value="components/springroll/dist/modules/tasks" checked="checked"> Tasks Module</label>
147144
</div>

project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"new": [
8383
"components/node-webkit-app/src/utils/Browser.js",
8484
"src/springroll/Module.js",
85+
"src/springroll/new/Module.js",
8586
"src/springroll/new/Template.js",
8687
"src/springroll/new/TemplateManager.js",
8788
"src/springroll/new/Installer.js",

src/springroll/SpringRollStudio.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
var project = localStorage.getItem('project');
9090
if (project)
9191
{
92-
this.openProject(project);
92+
this.openProject(project, false);
9393
}
9494
else
9595
{
@@ -128,14 +128,17 @@
128128
* Open a project file
129129
* @method openProject
130130
* @param {string} project Path to the folder
131+
* @param {boolean} [alertError=true] If an alert should show on error
131132
*/
132-
p.openProject = function(project)
133+
p.openProject = function(project, alertError)
133134
{
135+
alertError = alertError === undefined ? true : !!alertError;
134136
this.requiresProject.removeClass('disabled');
135137

136138
if (!fs.existsSync(path.join(project, 'springroll.json')))
137139
{
138-
alert("Folder is not a valid SpringRoll project");
140+
if (alertError)
141+
alert("Folder is not a valid SpringRoll project");
139142
this.closeProject();
140143
return;
141144
}

src/springroll/new/Installer.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,44 @@
6565
console.log("Copy " + template + " to " + dest);
6666
}
6767

68-
// loop through the templates from back to front
69-
for (var i = templates.length - 1; i >= 0; i--)
68+
// loop through the templates from back to front,
69+
// that is from parent (general) to child (specific)
70+
var template, file, j, i;
71+
for (i = templates.length - 1; i >= 0; i--)
7072
{
71-
var template = templates[i];
73+
template = templates[i];
7274

7375
// Copy the files from the template to the destination
7476
fs.copySync(template.path, dest);
7577

7678
// Add subsitution options for the version and name
7779
options.templateVersion = template.version;
7880
options.templateName = template.name;
81+
options.templateId = template.id;
7982

8083
// Rename any local files that should actually
8184
// be hidden
8285
if (template.rename)
8386
{
84-
for(var file in template.rename)
87+
for(file in template.rename)
8588
{
8689
fs.renameSync(
8790
path.join(dest, file),
8891
path.join(dest, template.rename[file])
8992
);
9093
}
9194
}
95+
96+
// Any files to remove, this can be if we're overriding
97+
// another template, we can delete things in the parent
98+
if (template.remove)
99+
{
100+
for (j = 0; j < template.remove.length; i++)
101+
{
102+
fs.unlinkSync(path.join(dest, template.remove[i]));
103+
}
104+
}
105+
92106
// Remove the template file
93107
fs.unlinkSync(path.join(dest, TemplateManager.FILE));
94108
}

src/springroll/new/JSONUtils.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(function(){
2+
3+
/**
4+
* JSON utiltities for interacting with JSON objects
5+
* @class JSONUtils
6+
* @namespace springroll.new
7+
*/
8+
var JSONUtils = {};
9+
10+
/**
11+
* Read a JSON file
12+
* @method read
13+
* @static
14+
* @param {string} filePath The file name
15+
* @return {obj} The JSON object
16+
*/
17+
JSONUtils.readJSON = function(filePath)
18+
{
19+
return JSON.parse(fs.readFileSync(filePath));
20+
};
21+
22+
/**
23+
* Write a JSON file
24+
* @method write
25+
* @static
26+
* @param {string} file The file name
27+
* @param {object} obj The object to update
28+
*/
29+
JSONUtils.writeJSON = function(filePath, obj)
30+
{
31+
fs.writeFileSync(filePath, JSON.stringify(obj, null, "\t"));
32+
};
33+
34+
// Assign to namespace
35+
namespace('springroll.new').JSONUtils = JSONUtils;
36+
37+
}());

src/springroll/new/Module.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
(function(){
2+
3+
/**
4+
* A module attached to a template
5+
* @class Module
6+
* @namespace springroll.new
7+
* @constructor
8+
* @param {string} id The unique module ID
9+
* @param {object} json JSON data to construct
10+
*/
11+
var Module = function(id, json)
12+
{
13+
/**
14+
* The bundle id for this template
15+
* @property {string} id
16+
*/
17+
this.id = id;
18+
19+
/**
20+
* The human-readable name
21+
* @property {string} name
22+
*/
23+
this.name = null;
24+
25+
/**
26+
* The list of release library files
27+
* @property {array} libraries
28+
*/
29+
this.libraries = null;
30+
31+
/**
32+
* The list of debug library files
33+
* @property {array} librariesDebug
34+
*/
35+
this.librariesDebug = null;
36+
37+
/**
38+
* The Bower dependencies
39+
* @property {object} bower
40+
*/
41+
this.bower = null;
42+
43+
/**
44+
* The other modules this depends on
45+
* @property {Array} depends
46+
*/
47+
this.depends = null;
48+
49+
this.fromJSON(json);
50+
};
51+
52+
// reference to the prototype
53+
var p = Module.prototype;
54+
55+
/**
56+
* Convert from JSON
57+
* @method fromJSON
58+
* @param {object} data The raw JSON data
59+
*/
60+
p.fromJSON = function(data)
61+
{
62+
this.name = data.name;
63+
this.libraries = toArray(data.libraries);
64+
this.librariesDebug = toArray(data.librariesDebug) || this.libraries;
65+
this.depends = toArray(data.depends);
66+
this.bower = data.bower;
67+
};
68+
69+
/**
70+
* Convert to an array
71+
* @method toArray
72+
* @private
73+
* @param {string|array} obj The object to convert
74+
* @return {array} The array
75+
*/
76+
var toArray = function(obj)
77+
{
78+
if (!obj) return;
79+
return !Array.isArray(obj) ? [obj] : obj;
80+
};
81+
82+
// Assign to namespace
83+
namespace('springroll.new').Module = Module;
84+
85+
}());

0 commit comments

Comments
 (0)