implemented init
This commit is contained in:
parent
a25281aa2a
commit
8f8f7085e4
113
bin/deardesi.js
113
bin/deardesi.js
|
@ -3,10 +3,17 @@
|
||||||
|
|
||||||
var PromiseA = require('bluebird')
|
var PromiseA = require('bluebird')
|
||||||
, fs = PromiseA.promisifyAll(require('fs'))
|
, fs = PromiseA.promisifyAll(require('fs'))
|
||||||
|
, fsx = PromiseA.promisifyAll(require('fs.extra'))
|
||||||
|
, tar = require('tar')
|
||||||
|
//, requestAsync = PromiseA.promisify(require('request'))
|
||||||
|
, request = PromiseA.promisifyAll(require('request'))
|
||||||
|
, forEachAsync = require('foreachasync').forEachAsync
|
||||||
|
//, spawn = require('child_process').spawn
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, cli = require('cli')
|
, cli = require('cli')
|
||||||
, UUID = require('node-uuid')
|
, UUID = require('node-uuid')
|
||||||
, Desi
|
, Desi
|
||||||
|
, zlib = require('zlib')
|
||||||
;
|
;
|
||||||
|
|
||||||
cli.parse({
|
cli.parse({
|
||||||
|
@ -31,6 +38,18 @@ function serve(displayDir, blogdir) {
|
||||||
server = http.createServer(app).listen(65080, function () {
|
server = http.createServer(app).listen(65080, function () {
|
||||||
console.info("Listening from " + displayDir);
|
console.info("Listening from " + displayDir);
|
||||||
console.info("Listening on http://local.dear.desi:" + server.address().port);
|
console.info("Listening on http://local.dear.desi:" + server.address().port);
|
||||||
|
}).on('error', function (err) {
|
||||||
|
if (/EADDRINUSE/.test(err.message)) {
|
||||||
|
console.error("");
|
||||||
|
console.error("You're already running desi in another tab.");
|
||||||
|
console.error("");
|
||||||
|
console.error("Go to the other tab and press <control> + c to stop her. Then you can come back here to try again.");
|
||||||
|
console.error("");
|
||||||
|
console.error("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
//secureServer = https.createServer(app).listen(65043);
|
//secureServer = https.createServer(app).listen(65043);
|
||||||
}
|
}
|
||||||
|
@ -166,6 +185,78 @@ function createPost(originalDir, blogdir, title, extra) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initialize(displayPath, blogdir) {
|
||||||
|
console.info("\nCreating new blog", displayPath);
|
||||||
|
|
||||||
|
return fs.readdirAsync(blogdir).then(function (nodes) {
|
||||||
|
// ignore dotfiles (.DS_Store, etc)
|
||||||
|
nodes = nodes.filter(function (node) {
|
||||||
|
return !/^\./.test(node);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (nodes.length) {
|
||||||
|
console.error("\n\tOops! It looks like that directory is already being used");
|
||||||
|
console.error("\nIf you want you can DELETE it and start from scratch:");
|
||||||
|
console.error("\n\trm -r '" + blogdir.replace("'", "'\"'\"'") + "'");
|
||||||
|
console.error("\nOr you can specify a different directory.");
|
||||||
|
console.error("\n");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}).catch(function (/*err*/) {
|
||||||
|
// doesn't exist? No problamo (all the better, actually)
|
||||||
|
return;
|
||||||
|
}).then(function () {
|
||||||
|
return fsx.mkdirp(blogdir);
|
||||||
|
}).then(function () {
|
||||||
|
return new PromiseA(function (resolve, reject) {
|
||||||
|
var t = tar.Extract({ path: blogdir, strip: 1 })
|
||||||
|
, gunzip = zlib.createGunzip()
|
||||||
|
;
|
||||||
|
|
||||||
|
console.info("Downloading blog template...", displayPath);
|
||||||
|
request.get("https://github.com/DearDesi/desirae-blog-template/archive/v1.0.0.tar.gz")
|
||||||
|
.pipe(gunzip)
|
||||||
|
.pipe(t)
|
||||||
|
.on('end', resolve)
|
||||||
|
.on('error', reject)
|
||||||
|
;
|
||||||
|
});
|
||||||
|
}).then(function () {
|
||||||
|
var themes
|
||||||
|
;
|
||||||
|
|
||||||
|
themes = [
|
||||||
|
{ name: 'ruhoh-twitter'
|
||||||
|
, url: "https://github.com/DearDesi/ruhoh-twitter/archive/v1.0.0.tar.gz"
|
||||||
|
}
|
||||||
|
, { name: 'ruhoh-bootstrap-2'
|
||||||
|
, url: "https://github.com/DearDesi/ruhoh-bootstrap-2/archive/v1.0.0.tar.gz"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return forEachAsync(themes, function (theme) {
|
||||||
|
return new PromiseA(function (resolve, reject) {
|
||||||
|
var t = tar.Extract({ path: path.join(blogdir, 'themes', theme.name), strip: 1 })
|
||||||
|
, gunzip = zlib.createGunzip()
|
||||||
|
;
|
||||||
|
|
||||||
|
console.info("Downloading theme '" + theme.name + "'");
|
||||||
|
request.get(theme.url)
|
||||||
|
.pipe(gunzip)
|
||||||
|
.pipe(t)
|
||||||
|
.on('end', resolve)
|
||||||
|
.on('error', reject)
|
||||||
|
;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).then(function () {
|
||||||
|
console.info("Done.");
|
||||||
|
console.info("\nTo start the web editor run this:");
|
||||||
|
console.info("\n\tdesi serve -d '" + blogdir.replace("'", "'\"'\"'") + "'");
|
||||||
|
})
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cli.main(function (args, options) {
|
cli.main(function (args, options) {
|
||||||
init();
|
init();
|
||||||
|
@ -173,6 +264,7 @@ cli.main(function (args, options) {
|
||||||
var command = args[0]
|
var command = args[0]
|
||||||
, blogdir = options.blogdir
|
, blogdir = options.blogdir
|
||||||
, originalDir = blogdir
|
, originalDir = blogdir
|
||||||
|
, displayPath
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!blogdir) {
|
if (!blogdir) {
|
||||||
|
@ -180,16 +272,20 @@ cli.main(function (args, options) {
|
||||||
originalDir = './';
|
originalDir = './';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(path.join(options.blogdir, 'site.yml'))) {
|
displayPath = path.resolve(originalDir)
|
||||||
console.error("Usage: desi [serve|init|post] -d ~/path/to/blog");
|
.replace(/^\/(Users|home)\/[^\/]+\//, '~/')
|
||||||
console.error("(if ~/path/to/blog doesn't yet exist or doesn't have config.yml, site.yml, etc, "
|
.replace(/ /g, '\\ ')
|
||||||
+ "try `deardesi init -d ~/path/to/blog'");
|
;
|
||||||
process.exit(1);
|
|
||||||
|
if ('init' === command) {
|
||||||
|
initialize(displayPath, blogdir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('init' === command) {
|
if (!fs.existsSync(path.join(blogdir, 'site.yml'))) {
|
||||||
console.error("`init' not yet implemented");
|
console.error("Usage: desi [serve|init|post] -d ~/path/to/blog");
|
||||||
|
console.error("(if ~/path/to/blog doesn't yet exist or doesn't have config.yml, site.yml, etc, "
|
||||||
|
+ "try `deardesi init -d ~/path/to/blog'");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -202,9 +298,6 @@ cli.main(function (args, options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ('serve' === command) {
|
else if ('serve' === command) {
|
||||||
var displayPath = path.resolve(originalDir).replace(/^\/(Users|home)\/[^\/]+\//, '~/').replace(/ /g, '\\ ')
|
|
||||||
;
|
|
||||||
|
|
||||||
serve(displayPath, blogdir);
|
serve(displayPath, blogdir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,12 @@
|
||||||
"connect-send-json": "^1.0.0",
|
"connect-send-json": "^1.0.0",
|
||||||
"desirae": "^0.10.0",
|
"desirae": "^0.10.0",
|
||||||
"desirae-datamap-ruhoh": "^1.0.0",
|
"desirae-datamap-ruhoh": "^1.0.0",
|
||||||
|
"foreachasync": "^5.0.5",
|
||||||
"fs.extra": "^1.3.0",
|
"fs.extra": "^1.3.0",
|
||||||
"node-uuid": "^1.4.2",
|
"node-uuid": "^1.4.2",
|
||||||
|
"request": "^2.51.0",
|
||||||
"require-yaml": "0.0.1",
|
"require-yaml": "0.0.1",
|
||||||
"serve-static": "^1.8.0"
|
"serve-static": "^1.8.0",
|
||||||
|
"tar": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,23 +19,16 @@
|
||||||
<br/>
|
<br/>
|
||||||
<!--iframe width="560" height="315" src="//www.youtube.com/embed/YZzhIIJmlE0" frameborder="0" allowfullscreen></iframe-->
|
<!--iframe width="560" height="315" src="//www.youtube.com/embed/YZzhIIJmlE0" frameborder="0" allowfullscreen></iframe-->
|
||||||
<pre>
|
<pre>
|
||||||
<code>curl -fsSL bit.ly/easy-install-iojs | bash
|
<code>curl -fsSL bit.ly/install-deardesi | bash
|
||||||
|
|
||||||
npm install -g desi
|
desi init -d ~/my-blog
|
||||||
|
|
||||||
git clone \
|
open ~/my-blog
|
||||||
https://github.com/DearDesi/desirae-blog-template.git \
|
|
||||||
blog
|
|
||||||
|
|
||||||
pushd blog
|
desi serve -d ~/my-blog</code>
|
||||||
|
|
||||||
git submodule add \
|
|
||||||
https://github.com/DearDesi/ruhoh-twitter.git \
|
|
||||||
themes/ruhoh-twitter
|
|
||||||
|
|
||||||
desi serve</code>
|
|
||||||
</pre>
|
</pre>
|
||||||
<br/>
|
<br/>
|
||||||
|
<p>The open <a href="http://local.dear.desi:65080">http://local.dear.desi:65080</a></p> in your browser.
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-5">
|
<div class="col-lg-5">
|
||||||
<h2>Why Desi?</h2>
|
<h2>Why Desi?</h2>
|
||||||
|
|
Loading…
Reference in New Issue