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')
|
||||
, 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')
|
||||
, cli = require('cli')
|
||||
, UUID = require('node-uuid')
|
||||
, Desi
|
||||
, zlib = require('zlib')
|
||||
;
|
||||
|
||||
cli.parse({
|
||||
|
@ -31,6 +38,18 @@ function serve(displayDir, blogdir) {
|
|||
server = http.createServer(app).listen(65080, function () {
|
||||
console.info("Listening from " + displayDir);
|
||||
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);
|
||||
}
|
||||
|
@ -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) {
|
||||
init();
|
||||
|
@ -173,6 +264,7 @@ cli.main(function (args, options) {
|
|||
var command = args[0]
|
||||
, blogdir = options.blogdir
|
||||
, originalDir = blogdir
|
||||
, displayPath
|
||||
;
|
||||
|
||||
if (!blogdir) {
|
||||
|
@ -180,16 +272,20 @@ cli.main(function (args, options) {
|
|||
originalDir = './';
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path.join(options.blogdir, 'site.yml'))) {
|
||||
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);
|
||||
displayPath = path.resolve(originalDir)
|
||||
.replace(/^\/(Users|home)\/[^\/]+\//, '~/')
|
||||
.replace(/ /g, '\\ ')
|
||||
;
|
||||
|
||||
if ('init' === command) {
|
||||
initialize(displayPath, blogdir);
|
||||
return;
|
||||
}
|
||||
|
||||
if ('init' === command) {
|
||||
console.error("`init' not yet implemented");
|
||||
if (!fs.existsSync(path.join(blogdir, 'site.yml'))) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -202,9 +298,6 @@ cli.main(function (args, options) {
|
|||
return;
|
||||
}
|
||||
else if ('serve' === command) {
|
||||
var displayPath = path.resolve(originalDir).replace(/^\/(Users|home)\/[^\/]+\//, '~/').replace(/ /g, '\\ ')
|
||||
;
|
||||
|
||||
serve(displayPath, blogdir);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,12 @@
|
|||
"connect-send-json": "^1.0.0",
|
||||
"desirae": "^0.10.0",
|
||||
"desirae-datamap-ruhoh": "^1.0.0",
|
||||
"foreachasync": "^5.0.5",
|
||||
"fs.extra": "^1.3.0",
|
||||
"node-uuid": "^1.4.2",
|
||||
"request": "^2.51.0",
|
||||
"require-yaml": "0.0.1",
|
||||
"serve-static": "^1.8.0"
|
||||
"serve-static": "^1.8.0",
|
||||
"tar": "^1.0.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,23 +19,16 @@
|
|||
<br/>
|
||||
<!--iframe width="560" height="315" src="//www.youtube.com/embed/YZzhIIJmlE0" frameborder="0" allowfullscreen></iframe-->
|
||||
<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 \
|
||||
https://github.com/DearDesi/desirae-blog-template.git \
|
||||
blog
|
||||
open ~/my-blog
|
||||
|
||||
pushd blog
|
||||
|
||||
git submodule add \
|
||||
https://github.com/DearDesi/ruhoh-twitter.git \
|
||||
themes/ruhoh-twitter
|
||||
|
||||
desi serve</code>
|
||||
desi serve -d ~/my-blog</code>
|
||||
</pre>
|
||||
<br/>
|
||||
<p>The open <a href="http://local.dear.desi:65080">http://local.dear.desi:65080</a></p> in your browser.
|
||||
</div>
|
||||
<div class="col-lg-5">
|
||||
<h2>Why Desi?</h2>
|
||||
|
|
Loading…
Reference in New Issue