После перезагрузки скрипт bg.js выводит в консоль ошибку:
Uncaught Error: Cannot find module './lib/wn_.js'
at Function.Module._resolveFilename (module.js:494:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:522:17)
at require (internal/module.js:20:19)
at self.require (:11:26)
at self.require (:11:26)
at chrome-extension://icbbpfpgimfaggfemjancddfhmipjkjm/bg.js:5:10
при первом запуске скрипта все ок.
bg.js:
var fs = require('fs'),
wn = require('./lib/wn_.js').wn,
fl = require('./lib/fl_.js').fl,
path_ = nw.App.dataPath + '\\user_';
Promise.resolve(fl.checkPath(path_))
.catch((ans) => {
if (ans.code === 'ENOENT') {
return Promise.resolve(fl.greatePath(path_));
} else {
return Promise.reject(ans);
}
})
.then(() => {
return Promise.resolve(
wn.winOpen('./html/index.html', {
id: "1",
title: "PostUP",
show: true
})
);
})
.then((w) => {
console.dir(w);
})
.catch((ans) => {
console.dir(ans);
});
fl_.js
exports.fl = {
checkPath: (path) => {
return new Promise((resolve, reject) => {
fs.stat(path_, (err, data) => {
if (data) {
resolve(data);
} else {
reject(err);
}
});
});
},
//создаем папку
greatePath: (path) => {
return new Promise((resolve, reject) => {
fs.mkdir(path_, (data) => {
if (data) {
reject(err);
} else {
resolve();
}
});
});
}
};
wn_.js:
exports.wn = {
winOpen: (url, setings) => {
return new Promise((resolve, reject) => {
nw.Window.open(url, setings, function(w) {
if (w) resolve(w);
else reject();
});
});
}
};