Skip to content

Commit eb18399

Browse files
committed
got some good deploy stuff working
1 parent 58b25ea commit eb18399

File tree

5 files changed

+54
-75
lines changed

5 files changed

+54
-75
lines changed

lib/builder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const clui = require('clui')
22
, Spinner = clui.Spinner
33
, Path = require('path')
4-
, fs = require('fs')
4+
, fs = require('fs-extra')
55
, crypto = require('crypto')
66
, Promise = require('bluebird')
77
, jspm = require('jspm')
@@ -70,14 +70,15 @@ module.exports = function(FASTACK) {
7070
.then((str) => {
7171
str = str.map((path) => Path.relative(FASTACK.cwd, path));
7272
str = str.join(' + ');
73+
fs.ensureDirSync(Path.join(FASTACK.localDir, 'builds/'+hash+'/'));
7374
builder.buildStatic(str, Path.join(FASTACK.localDir, 'builds/'+hash+'/'+hash+'.js'), {
7475
minify: false,
7576
sourceMaps: true,
7677
//mangle: production,
7778
//lowResSourceMaps: !production
7879
format: 'global'
7980
})
80-
.then(function (data) {
81+
.then(function () {
8182
//FASTACK.logger.info(hash);
8283
resolve(FASTACK.hash);
8384
}).catch(function (e) {

lib/commands/deploy.js

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Syncano = require('syncano')
22
, Path = require('path')
33
, fs = require('fs-extra')
44
, Promise = require('bluebird')
5+
, walkSync = require('walk-sync')
56
;
67

78
module.exports = function(FASTACK) {
@@ -59,64 +60,38 @@ module.exports = function(FASTACK) {
5960
}
6061

6162
fs.emptyDirSync(Path.resolve(FASTACK.localDir, 'deploy/'));
62-
var appId, files, filesToClean;
63+
64+
var appId, dir, filesToClean;
6365
FASTACK.export('.fastack/deploy')
64-
.then((f) => new Promise((resolve) => {files = f; resolve()}))
65-
.then(() => getAppId(args["app-name"]))
66-
.then((id) => new Promise((resolve) => {appId = id; resolve()}))
67-
.then(() => fetchFilesToClean(appId))
66+
.then((d) => {dir = d; return getAppId(args["app-name"])})
67+
.then((id) => {appId = id; return fetchFilesToClean(appId)})
6868
.then((ids) => {filesToClean = ids;})
6969
.then(() => {
7070
var promises = [];
71+
var files = walkSync(dir, {directories: false});
7172
for (var f in files) {
72-
var file = files[f];
73-
var path = file.path;
74-
var isDir = fs.lstatSync(path).isDirectory();
75-
if (!isDir) {
76-
var fileObject = {
77-
path: Path.relative(FASTACK.cwd, file.path),
78-
app: appId,
79-
contents: {
80-
filename: Path.basename(file.path),
81-
data: fs.readFileSync(file.path, 'utf8')
82-
},
83-
owner_permissions: "full"
84-
};
85-
promises.push(deployFile(fileObject));
86-
}
73+
var file = Path.resolve(dir, files[f]);
74+
var fileObject = {
75+
path: Path.relative(dir, file),
76+
app: appId,
77+
contents: {
78+
filename: Path.basename(file),
79+
data: fs.readFileSync(file, 'utf8')
80+
},
81+
owner_permissions: "full"
82+
};
83+
promises.push(deployFile(fileObject));
8784
}
8885
return Promise.all(promises);
8986
})
90-
.then(() => cleanFiles(filesToClean))
91-
.then(() => {
92-
fastack.class('files').dataobject().list().then(function(data) {
93-
console.log(data.length);
94-
callback();
95-
})
87+
.then((deployed) => {
88+
FASTACK.logger.confirm(deployed.length + ' files deployed.');
9689
})
9790
.catch((e) => {
98-
console.log(e);
91+
FASTACK.logger.error(e);
9992
callback();
100-
});
101-
102-
// var dirName = Path.basename(FASTACK.cwd);
103-
// var filter = {
104-
// "query" : { id: {"_eq":202} }
105-
// "query" : {"name" : Path.basename(FASTACK.cwd) }
106-
// "query" : {"objects": [
107-
// {"name" : "test-app" }
108-
// ]
109-
// }
110-
// "fields": {include: ["app"]}
111-
// "query" : {"objects":[
112-
// { "name": "null" }
113-
// ]
114-
// }
115-
// };
116-
117-
// fastack.class('apps').dataobject().list(filter, function(data){
118-
// console.log(data);
119-
// });
120-
93+
})
94+
.then(() => cleanFiles(filesToClean))
95+
.finally(callback);
12196
}
12297
};

lib/fastack.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ require('./directory.js')(FASTACK)
2626
.then(() => {
2727
spinner.message('Fetching Fastack API keys...');
2828
return require('./keys.js')(FASTACK)})
29-
.then(() => {
30-
spinner.message('Loading builder...');
31-
return require('./builder.js')(FASTACK)})
3229
.then(() => {
3330
spinner.message('Loading helpers...');
3431
return require('./helpers.js')(FASTACK)})
32+
.then(() => {
33+
spinner.message('Loading builder...');
34+
return require('./builder.js')(FASTACK)})
3535
.then(() => {
3636
spinner.message('Starting local server...');
3737
return require('./localServer.js')(FASTACK)
@@ -124,7 +124,7 @@ vorpal
124124
var spinner = new Spinner('Building application...');
125125
spinner.start();
126126
var start = new Date();
127-
FASTACK.build().then(function() {
127+
FASTACK.build(true).then(function() {
128128
spinner.stop();
129129
var t = new Date() - start;
130130
FASTACK.logger.info('Build time: ' + t + ' ms.');

lib/helpers.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const shell = require('shelljs')
33
, Promise = require('bluebird')
44
, Path = require('path')
55
, fs = require('fs-extra')
6+
, walkSync = require('walk-sync')
67
;
78

89
shell.log = function() {
@@ -24,6 +25,7 @@ module.exports = function(FASTACK) {
2425
},
2526
error: function(msg) {
2627
if (typeof msg === 'string') msg = msg.replace(/\n+$/, "");
28+
if (typeof msg === 'object') msg = msg.toString();
2729
console2.error(msg);
2830
},
2931
warn: function(msg) {
@@ -67,29 +69,29 @@ module.exports = function(FASTACK) {
6769
.then((hash) => {
6870
var dest = Path.resolve(FASTACK.localDir, 'builds/', hash);
6971
var ultDest = Path.relative(FASTACK.cwd, dir);
70-
FASTACK.traverse(FASTACK.cwd, true).then((files) => {
71-
for (var f in files) {
72-
var path = files[f].path;
73-
var isDir = fs.lstatSync(path).isDirectory();
7472

75-
if (path.indexOf('/.fastack/') == -1 && !isDir) {
76-
fs.copySync(path, Path.resolve(dest, Path.relative(FASTACK.cwd, path)))
77-
}
78-
}
73+
var appFiles = walkSync(FASTACK.cwd, {
74+
globs: ["**"],
75+
directories: false
76+
});
77+
78+
for (var f in appFiles) {
79+
var file = appFiles[f];
80+
fs.copySync(file, Path.resolve(dest, Path.relative(FASTACK.cwd, file)));
81+
}
82+
fs.copySync(dest, ultDest);
7983

80-
fs.copySync(dest, ultDest);
84+
var files = walkSync(ultDest, {directories: false});
85+
86+
for (var f in files) {
87+
var file = Path.resolve(ultDest, files[f]);
88+
if (Path.extname(file) == '.html') {
89+
var newHtml = require('./htmlBuild')(FASTACK).prod(fs.readFileSync(file, 'utf8'), hash);
90+
fs.outputFileSync(file, newHtml, 'utf8');
91+
}
92+
}
8193

82-
FASTACK.traverse(ultDest, ['html']).then((htmlFiles) => {
83-
for (var f in htmlFiles) {
84-
var path = htmlFiles[f].path;
85-
if (Path.extname(path) == '.html') {
86-
var newHtml = require('./htmlBuild')(FASTACK).prod(fs.readFileSync(path, 'utf8'), hash);
87-
fs.outputFileSync(path, newHtml, 'utf8')
88-
}
89-
}
90-
resolve(files);
91-
})
92-
})
94+
resolve(ultDest);
9395
})
9496
})
9597
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"systemjs": "^0.19.9",
4444
"through2": "^2.0.0",
4545
"validator": "*",
46-
"vorpal": "^1.4.1"
46+
"vorpal": "^1.4.1",
47+
"walk-sync": "^0.2.6"
4748
},
4849
"bin": {
4950
"fastack": "./bin/fastack"

0 commit comments

Comments
 (0)