diff --git a/README.md b/README.md index d6b776d..18e61ee 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ JavaScript module (or make requests to an API service that renders them for you) ```javascript var slim = exports.slimjs || require("slimjs"); function render(contentstr /*, desi*/) { - return PromiseA.resolve(slim(contentstr)); + return Promise.resolve(slim(contentstr)); } Desirae.registerRenderer(".slim", render); diff --git a/lib/browser-adapters.js b/lib/browser-adapters.js index 2af4666..e7d6127 100644 --- a/lib/browser-adapters.js +++ b/lib/browser-adapters.js @@ -5,7 +5,7 @@ function create(Desi) { // Chrome, Firefox, and even MSIE11+ all support crypto var crypto = window.crypto || window.msCrypto, - PromiseA = window.Promise, + Promise = window.Promise, algos; // convenience mappings for common digest algorithms @@ -111,7 +111,7 @@ function request() {} request.get = function (url /*, query*/) { // Return a new promise. - return new PromiseA(function (resolve, reject) { + return new Promise(function (resolve, reject) { // Do the usual XHR stuff var req = new XMLHttpRequest(); req.onload = function () { @@ -139,7 +139,7 @@ }; request.post = function (url /*, query*/, body) { // Return a new promise. - return new PromiseA(function (resolve, reject) { + return new Promise(function (resolve, reject) { // Do the usual XHR stuff var req = new XMLHttpRequest(); req.onload = function () { diff --git a/lib/node-adapters/fsapi-real.js b/lib/node-adapters/fsapi-real.js index 6c7c468..1b600ed 100644 --- a/lib/node-adapters/fsapi-real.js +++ b/lib/node-adapters/fsapi-real.js @@ -1,7 +1,7 @@ "use strict"; -var PromiseA = require("bluebird").Promise, - fs = PromiseA.promisifyAll(require("fs")); +var fs = require('fs').promises; + function create(Desi, options) { var fsapi = Desi.fsapi; options.blogdir = options.blogdir || options.working_path; @@ -35,7 +35,7 @@ function create(Desi, options) { fsapi.getCache = function () { return fs - .readFileAsync(options.blogdir, "/cache.json") + .readFile(options.blogdir, "/cache.json") .catch(function (/*e*/) { return {}; }) diff --git a/lib/node-adapters/fsapi.js b/lib/node-adapters/fsapi.js index 1de621b..8643a46 100644 --- a/lib/node-adapters/fsapi.js +++ b/lib/node-adapters/fsapi.js @@ -10,7 +10,7 @@ var safeResolve = require("../utils").safeResolve; var sha1sum = function (str) { return require("secret-utils").hashsum("sha1", str); }; -var fsExtra = PromiseA.promisifyAll(require("fs.extra")); +var copyAll = require("util").promisify(require("fs.extra").copy); //, tmpdir = require('os').tmpdir() function strip(prefix, pathname) { @@ -48,7 +48,7 @@ function walkDir(parent, sub, opts) { return true; } - return new PromiseA(function (resolve) { + return new Promise(function (resolve) { var walker = walk.walk(trueRoot); walker.on("nodeError", function (filepath, stat, next) { //stats.forEach(function (stat) { @@ -76,7 +76,7 @@ function walkDir(parent, sub, opts) { var file; if (!filter(stat.name)) { - return PromiseA.resolve(); + return Promise.resolve(); } file = { @@ -93,12 +93,12 @@ function walkDir(parent, sub, opts) { files.push(file); if (!(opts.sha1sum || opts.content)) { - return PromiseA.resolve(); + return Promise.resolve(); } // TODO stream sha1 (for assets) return fs - .readFileAsync(path.join(root, stat.name), null) + .readFile(path.join(root, stat.name), null) .then(function (buffer) { var contents = buffer.toString("utf8"); file.sha1 = sha1sum(contents); @@ -144,7 +144,7 @@ function getfs(blogdir, filepaths) { return forEachAsync(filepaths, function (filepath) { var pathname = safeResolve(blogdir, filepath); return fs - .lstatAsync(pathname) + .lstat(pathname) .then(function (stat) { return fs.readFile(pathname, null).then(function (buffer) { files.push({ @@ -208,7 +208,7 @@ function copyfs(blogdir, files) { //, filename = path.basename(dest) dirpaths[pathname] = true; - return PromiseA.resolve(); + return Promise.resolve(); }) .then(function () { // TODO is it better to do this lazy-like or as a batch? @@ -223,8 +223,7 @@ function copyfs(blogdir, files) { .then(function () { // TODO allow delete? return forEachAsync(sources, function (source) { - return fsExtra - .copyAsync( + return copyAll( safeResolve(blogdir, source), safeResolve(blogdir, files[source]), { replace: true } @@ -276,7 +275,7 @@ function putfs(blogdir, files, options) { dirpaths[pathname] = true; - return PromiseA.resolve(); + return Promise.resolve(); }) .then(function () { // TODO is it better to do this lazy-like or as a batch? @@ -304,13 +303,9 @@ function putfs(blogdir, files, options) { return forEachAsync(files, function (file) { // TODO use lastModifiedDate as per client request? // TODO compare sha1 sums for integrity - // NOTE existsAsync is backwards return fs - .existsAsync(file.realPath) + .access(file.realPath) .then(function () { - return fs.writeFile(file.realPath, file.contents, "utf8"); - }) - .catch(function (/*exists*/) { if (file.delete || !file.contents) { return fs.unlink(file.realPath); } @@ -321,6 +316,9 @@ function putfs(blogdir, files, options) { return fs.writeFile(file.realPath, file.contents, "utf8"); }) + .catch(function () { + return fs.writeFile(file.realPath, file.contents, "utf8"); + }) .catch(function (e) { putfsResults.errors.push({ type: "file", diff --git a/lib/render-core.js b/lib/render-core.js index f29a9bb..c8dc6d0 100644 --- a/lib/render-core.js +++ b/lib/render-core.js @@ -2,13 +2,12 @@ (function (exports) { "use strict"; - var PromiseA = exports.Promise || require("bluebird").Promise; function renderMd(contentstr /*, desi*/) { var markitdown = (exports.markdownit || require("markdown-it"))({ html: true, linkify: true, }); - return PromiseA.resolve( + return Promise.resolve( markitdown.render(contentstr) //.replace('"', '"') //.replace(''', "'") @@ -18,7 +17,7 @@ function renderNoop(contentstr /*, desi*/) { // hmmm... that was easy - return PromiseA.resolve(contentstr); + return Promise.resolve(contentstr); } function renderJade(contentstr, desi, options) { @@ -30,7 +29,7 @@ var jade = exports.jade || require("jade"), fn = jade.compile(contentstr, options), html = fn(desi); - return PromiseA.resolve(html); + return Promise.resolve(html); } exports.DesiraeRenderMarkdown = renderMd.DesiraeRenderMarkdown = renderMd; diff --git a/package-lock.json b/package-lock.json index ee9d3c5..fffc2b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "desirae", - "version": "0.12.0", + "version": "0.12.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1c33299..5572410 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "desirae", - "version": "0.12.0", + "version": "0.12.3", "description": "An in-browser static blog library and static site generator. Similar to Jekyll, Octopress, Nanoc, etc", "main": "desirae.js", "scripts": {