使用 electron-updater 和 Sinopia 的节点注册路径
Node registry path with electron-updater and Sinopia
我目前正在 Electron(以前的 atom-shell)上开发一个应用程序 运行,并尝试设计一种在有新更新可用时提醒用户的方法。为此,我使用 electron-updater in the way described in electron-updater-sample. I also configured Sinopia 来监听 http://localhost:4873/
(默认行为)和 运行 此命令行:
npm config set registry "http://localhost:4873"
我检查了 .npmrc
文件,注册表已正确设置为新值。
我遇到的问题是当我尝试检查更新时,我在控制台中收到此错误消息:
{ [HTTPError: Response code 404 (Not Found)]
message: 'Response code 404 (Not Found)',
code: undefined,
host: 'registry.npmjs.org',
hostname: 'registry.npmjs.org',
method: 'GET',
path: '/hacker-keyboard-electron',
statusCode: 404,
statusMessage: 'Not Found' }
所以我相信我在 npm 配置中忘记了一些东西,使应用程序监听 npm 的常规路径而不是 Sinopia 服务器。问题是什么?
请在下面找到我正在使用的代码:
foobar 生成器
├── app
├── 凉亭组件
├── bower.json
├── index.html
├── 指数。 js
├──主要。 js
├── nbproject
├── 节点模块
├── npm-debug.log
├── package.json
├── 自述文件。 MD
└── sinopia
package.json
{
"name": "foobar-generator",
"version": "0.0.1",
"description": "A generator for foobar",
"main": "main.js",
"dependencies": {
"angular": "^1.4.7",
"bootstrap": "^3.3.5",
"chokidar": "^1.2.0",
"electron-debug": "^0.2.1",
"electron-packager": "^5.1.0",
"electron-plugins": "^0.0.4",
"electron-prebuilt": "^0.33.6",
"electron-rebuild": "^1.0.2",
"electron-updater": "^0.2.0",
"grunt": "^0.4.5",
"jquery": "^2.1.4"
},
"devDependencies": {},
"publishConfig": {
"registry": "http://localhost:4873/"
},
"registry": "http://localhost:4873/"
}
main.js
var appli = require('app');
var BrowserWindow = require('browser-window');
var updater = require('electron-updater');
var util = require('util');
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
var loaded = false;
// Quit when all windows are closed.
appli.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
appli.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
appli.on('ready', function () {
updater.on('ready', function () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.openDevTools({detach: true});
mainWindow.on('closed', function () {
mainWindow = null;
});
});
updater.on('updateRequired', function () {
appli.quit();
});
updater.on('updateAvailable', function () {
if (mainWindow) {
mainWindow.webContents.send('update-available');
}
});
updater.start();
updater.check(function (err, results) {
if (err) {
return console.error(util.inspect(err));
}
console.log(results);
});
});
你们看到我有什么地方可以 forgotten/done 错了吗?
通过阅读 npmrc (npm help npmrc
) 的手册,我发现 .npmrc
文件不是唯一的。通过按照我的方式配置注册表,我只更改了每个用户 .npmrc
。但是你的项目根目录下也应该有这样一个文件!您应该在其中配置要使用的注册表。在项目根目录中添加此文件解决了我面临的问题。
您应该收听错误事件。
试试这个
updater.on('error', function (err) {
console.log(err);
});
我目前正在 Electron(以前的 atom-shell)上开发一个应用程序 运行,并尝试设计一种在有新更新可用时提醒用户的方法。为此,我使用 electron-updater in the way described in electron-updater-sample. I also configured Sinopia 来监听 http://localhost:4873/
(默认行为)和 运行 此命令行:
npm config set registry "http://localhost:4873"
我检查了 .npmrc
文件,注册表已正确设置为新值。
我遇到的问题是当我尝试检查更新时,我在控制台中收到此错误消息:
{ [HTTPError: Response code 404 (Not Found)]
message: 'Response code 404 (Not Found)',
code: undefined,
host: 'registry.npmjs.org',
hostname: 'registry.npmjs.org',
method: 'GET',
path: '/hacker-keyboard-electron',
statusCode: 404,
statusMessage: 'Not Found' }
所以我相信我在 npm 配置中忘记了一些东西,使应用程序监听 npm 的常规路径而不是 Sinopia 服务器。问题是什么?
请在下面找到我正在使用的代码:
foobar 生成器
├── app
├── 凉亭组件
├── bower.json
├── index.html
├── 指数。 js
├──主要。 js
├── nbproject
├── 节点模块
├── npm-debug.log
├── package.json
├── 自述文件。 MD
└── sinopia
package.json
{
"name": "foobar-generator",
"version": "0.0.1",
"description": "A generator for foobar",
"main": "main.js",
"dependencies": {
"angular": "^1.4.7",
"bootstrap": "^3.3.5",
"chokidar": "^1.2.0",
"electron-debug": "^0.2.1",
"electron-packager": "^5.1.0",
"electron-plugins": "^0.0.4",
"electron-prebuilt": "^0.33.6",
"electron-rebuild": "^1.0.2",
"electron-updater": "^0.2.0",
"grunt": "^0.4.5",
"jquery": "^2.1.4"
},
"devDependencies": {},
"publishConfig": {
"registry": "http://localhost:4873/"
},
"registry": "http://localhost:4873/"
}
main.js
var appli = require('app');
var BrowserWindow = require('browser-window');
var updater = require('electron-updater');
var util = require('util');
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
var loaded = false;
// Quit when all windows are closed.
appli.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
appli.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
appli.on('ready', function () {
updater.on('ready', function () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.openDevTools({detach: true});
mainWindow.on('closed', function () {
mainWindow = null;
});
});
updater.on('updateRequired', function () {
appli.quit();
});
updater.on('updateAvailable', function () {
if (mainWindow) {
mainWindow.webContents.send('update-available');
}
});
updater.start();
updater.check(function (err, results) {
if (err) {
return console.error(util.inspect(err));
}
console.log(results);
});
});
你们看到我有什么地方可以 forgotten/done 错了吗?
通过阅读 npmrc (npm help npmrc
) 的手册,我发现 .npmrc
文件不是唯一的。通过按照我的方式配置注册表,我只更改了每个用户 .npmrc
。但是你的项目根目录下也应该有这样一个文件!您应该在其中配置要使用的注册表。在项目根目录中添加此文件解决了我面临的问题。
您应该收听错误事件。 试试这个
updater.on('error', function (err) {
console.log(err);
});