Skip to content

Commit 1040ced

Browse files
committed
Merge pull request #2 from fastack/0.1.2
release 0.1.2
2 parents 4abf4d5 + c05cafa commit 1040ced

23 files changed

+565
-252
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Fastack is a zero-configuration development tool that makes developing client-si
1313
- SASS
1414
- CoffeeScript
1515

16+
### Auto reload on file changes
17+
Hot module replacement implementation coming soon. See below.
18+
19+
![Package management](docs/img/auto-reload.gif)
1620

1721
## Quickstart
1822
```

docs/img/auto-reload.gif

299 KB
Loading

lib/autocomplete.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const Path = require('path')
2+
, fs = require('fs')
3+
, walkSync = require('walk-sync')
4+
, _ = require('lodash')
5+
;
6+
7+
module.exports = function(FASTACK, COMMAND) {
8+
return function (text, iteration, cb) {
9+
var opts = {directories: true, globs: ["**"]};
10+
11+
switch (COMMAND) {
12+
case 'cd':
13+
//opts.globs = ["(**/*.*)"];
14+
opts.dot = false;
15+
break;
16+
case 'cat':
17+
opts.directories = false;
18+
break;
19+
}
20+
21+
var list = walkSync(FASTACK.dir, opts);
22+
23+
if (iteration > 1) {
24+
cb(void 0, list);
25+
} else {
26+
var match = this.match(text, list);
27+
if (match) {
28+
cb(void 0, COMMAND + " " + match);
29+
} else {
30+
cb(void 0, void 0);
31+
}
32+
}
33+
}
34+
};

lib/builder.js

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
const clui = require('clui')
2-
, Spinner = clui.Spinner
3-
, Path = require('path')
4-
, fs = require('fs')
1+
const Path = require('path')
2+
, fs = require('fs-extra')
53
, crypto = require('crypto')
64
, Promise = require('bluebird')
75
, jspm = require('jspm')
6+
, _ = require('lodash')
87
;
98

109
module.exports = function(FASTACK) {
1110

1211
FASTACK.getLocalDeps = function() {
12+
var installedDeps = fs.readJsonSync(Path.resolve(FASTACK.localDir, 'package.json'))['jspm']['dependencies'];
13+
installedDeps = _.keys(installedDeps);
14+
1315
return new Promise(function(resolve, reject) {
1416
var allowable = [
1517
'css',
1618
'coffee',
1719
'sass',
18-
'scss'
20+
'scss',
21+
'less',
22+
'js'
1923
];
2024

2125
function getSuffix(ext) {
2226
switch(ext) {
23-
case ".css": return "plugin-css";
24-
case ".sass": return "plugin-sass";
25-
case ".scss": return "plugin-sass";
26-
default: return "";
27+
case ".css": return "!plugin-css";
28+
case ".sass": return "!plugin-sass";
29+
case ".scss": return "!plugin-sass";
30+
case ".js": return "";
31+
default: return "!";
2732
}
2833
}
2934

35+
//var out = installedDeps;
3036
var out = [];
3137

3238
FASTACK.traverse(FASTACK.cwd, allowable, function(file) {
33-
out.push(file.path + '!' + getSuffix(Path.extname(file.path)));
34-
}).then(function(files) {
35-
var str = '* + fastack:dev/live-reload';
36-
for (var i in files) {
37-
var file = files[i];
38-
str += ' + ./' + Path.relative(FASTACK.cwd, file.path) + '!' + getSuffix(Path.extname(file.path))
39-
}
39+
out.push(file.path + getSuffix(Path.extname(file.path)));
40+
}).then(function() {
4041
resolve(out);
4142
});
4243
});
4344
};
4445

4546

46-
4747
FASTACK.build = function(production) {
48-
production = !!production
48+
production = !!production;
4949
FASTACK.hash = crypto.createHash('md5').update((new Date()).toString()).digest('hex');
5050

5151
jspm.setPackagePath(FASTACK.localDir);
@@ -54,28 +54,42 @@ module.exports = function(FASTACK) {
5454
builder.loadConfigSync(configFile, true, true);
5555
builder.config({
5656
buildCSS: true,
57-
separateCSS: true,
58-
paths: {
59-
'fastack:*': Path.resolve(FASTACK.localDir, 'fastack-packages/*')
60-
}
57+
separateCSS: true
6158
});
6259

60+
if (!production) {
61+
builder.config({
62+
paths: {
63+
'fastack:*': Path.resolve(FASTACK.localDir, 'fastack-packages/*')
64+
}
65+
})
66+
}
67+
6368
return new Promise(function(resolve, reject) {
64-
resolve();
65-
//_buildString()
66-
//.then(function (str) {
67-
// builder.buildStatic(str, Path.join(FASTACK.localDir, 'builds/fastack.js'), {
68-
// minify: production,
69-
// sourceMaps: true,
70-
// mangle: production,
71-
// lowResSourceMaps: !production
72-
// })
73-
// .then(function (data) {
74-
// resolve();
75-
// }).catch(function (e) {
76-
// reject(e);
77-
// })
78-
//});
69+
if (!production) resolve();
70+
else {
71+
var hash = FASTACK.hash;
72+
FASTACK.getLocalDeps()
73+
.then((str) => {
74+
str = str.map((path) => Path.relative(FASTACK.cwd, path));
75+
str = str.join(' + ');
76+
fs.ensureDirSync(Path.join(FASTACK.localDir, 'builds/'+hash+'/'));
77+
builder.buildStatic(str, Path.join(FASTACK.localDir, 'builds/'+hash+'/'+hash+'.js'), {
78+
minify: false,
79+
sourceMaps: true,
80+
//mangle: production,
81+
//lowResSourceMaps: !production
82+
format: 'global'
83+
})
84+
.then(function () {
85+
//FASTACK.logger.info(hash);
86+
resolve(FASTACK.hash);
87+
}).catch(function (e) {
88+
console.log(e);
89+
reject(e);
90+
})
91+
})
92+
}
7993
});
8094
};
8195

lib/commands/add_host.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require('fs')
2+
, Syncano = require('syncano')
3+
, validator = require('validator')
4+
, request = require('request')
5+
, clui = require('clui')
6+
, Spinner = clui.Spinner
7+
, jspm = require('jspm')
8+
, chalk = require('chalk')
9+
, Promise = require('bluebird')
10+
;
11+
12+
module.exports = function(FASTACK) {
13+
14+
return function(args, callback){
15+
16+
var hostName = args["host-name"];
17+
18+
function addHost(url, info) {
19+
return new Promise(function(resolve, reject) {
20+
request.post(url, {json:{info}} , function (err, res) {
21+
if (err) {
22+
reject(err);
23+
return;
24+
}
25+
resolve( res.body.result.stdout );
26+
});
27+
});
28+
}
29+
30+
var url = "https://api.syncano.io/v1/instances/fastack/webhooks/p/0acce994a35c9512e9c0a4960853d00483f95209/create_host/";
31+
var spinner = new Spinner('Adding host');
32+
var info = { hostName: hostName, apiKey: FASTACK.apiKey, userKey: FASTACK.userKey };
33+
spinner.start();
34+
addHost(url, info).then( (result) => {
35+
spinner.stop();
36+
FASTACK.logger.log(result);
37+
callback();
38+
}).catch((e) => {
39+
spinner.stop();
40+
FASTACK.logger.error(e);
41+
callback();
42+
});
43+
44+
}
45+
};

lib/commands/cat.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
const child_process = require('child_process')
1+
const Path = require('path')
2+
, fs = require('fs')
23
;
34

4-
// could add options if we wanted (e.g. a '-l')
55
module.exports = function(FASTACK) {
66
return function(args, callback) {
7-
// child_process.exec(command[, options], callback)
8-
var command = "cat " + args["file-name"];
9-
child_process.exec(command, function(error, stdout, stderr){
10-
if(error) FASTACK.logger.error(stderr);
11-
FASTACK.logger.log(stdout);
12-
});
7+
8+
try {
9+
var file = fs.readFileSync(Path.resolve(FASTACK.dir, args["file"]), 'utf8');
10+
console.log(file);
11+
} catch(e) {
12+
if (e.code == 'ENOENT') FASTACK.logger.error('File not found!');
13+
else if (e.code == 'EISDIR') FASTACK.logger.error('That\'s a directory!');
14+
else {
15+
FASTACK.logger.error(e);
16+
}
17+
}
1318
callback();
1419
}
1520
};

lib/commands/cd.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
const child_process = require('child_process')
1+
const Path = require('path')
2+
, fs = require('fs')
23
;
34

45
module.exports = function(FASTACK) {
56
return function(args, callback) {
6-
// child_process.exec(command[, options], callback)
7-
var command = "cd " + args["dir-name"];
8-
child_process.exec(command, function(error, stdout, stderr){
9-
if(error) FASTACK.logger.error(stderr);
10-
FASTACK.logger.log(stdout);
11-
});
12-
callback();
7+
var newDir = Path.resolve(FASTACK.dir, args["dir-name"]);
8+
9+
try {
10+
var newDirStat = fs.statSync(newDir);
11+
if (!newDirStat.isDirectory()) {
12+
FASTACK.logger.error(FASTACK.logger.error('That\'s not a directory!'));
13+
callback();
14+
}
15+
else if (Path.relative(FASTACK.cwd, newDir).indexOf('..') != -1) {
16+
FASTACK.logger.error('Cannot leave your application directory!');
17+
callback();
18+
}
19+
else {
20+
FASTACK.dir = newDir;
21+
FASTACK.updateDelimiter();
22+
callback();
23+
}
24+
} catch(e) {
25+
if (e.code == 'ENOENT') FASTACK.logger.error(FASTACK.logger.error('Directory does not exist!'));
26+
27+
callback();
28+
}
1329
}
1430
};

lib/commands/cp.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
const child_process = require('child_process')
22
, fs = require('fs-extra')
3+
, Path = require('path')
34
;
45

56
// could add options if we wanted (e.g. a '-l')
67
module.exports = function(FASTACK) {
78
return function(args, callback) {
89

10+
// if a file already exists, this command will just overwrite it right now
11+
912
var src = args["src"];
1013
var dst = args["dst"];
1114

12-
fs.copy(src, dst, function (err) {
13-
if (err) return console.error(err)
14-
console.log("success!")
15-
}) // copies file
15+
var dataToCopy = fs.readFile(src, function(err, data){
16+
if (err){
17+
FASTACK.logger.log(err);
18+
}
19+
});
20+
21+
var fileName = Path.basename(src);
22+
if( fs.existsSync(dst) && fs.lstatSync(dst).isDirectory() ){
23+
var fileName = Path.basename(src);
24+
dst = dst + "/" + fileName;
25+
}
26+
var fd = fs.openSync(dst, 'w');
27+
28+
fs.write(fd, dataToCopy, function(err) {
29+
if(err) {
30+
FASTACK.logger.log(err);
31+
}
32+
FASTACK.logger.log("File copied.");
33+
});
1634

17-
// child_process.exec(command[, options], callback)
18-
// var command = "cp " + args["src"] + " " + args["dst"];
19-
// child_process.exec(command, function(error, stdout, stderr){
20-
// if(error) FASTACK.logger.error(stderr);
21-
// FASTACK.logger.log(stdout);
22-
// });
23-
// callback();
35+
callback();
2436
}
2537
};

0 commit comments

Comments
 (0)