Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESLint #105

Closed
wants to merge 13 commits into from
20 changes: 10 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: ".github/"
schedule:
interval: "daily"
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
- package-ecosystem: 'github-actions'
directory: '.github/'
schedule:
interval: 'daily'
14 changes: 14 additions & 0 deletions .github/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
ayushmanchhabra marked this conversation as resolved.
Show resolved Hide resolved
parserOptions: {
ecmaVersion: 2023,
sourceType: 'module',
},
env: {
node: true,
},
ignorePatterns: ['node_modules', 'package.json', 'package-lock.json'],
extends: ['eslint:recommended'],
rules: {
quotes: ['error', 'single'],
},
Copy link
Member

@TheJaredWilcurt TheJaredWilcurt Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of stylistic rules that could be applied to make the code more consistent.

Here is my ruleset for reference:

Ones that come to mind when looking over this PR:

  • Sometimes we add an extra comma at the end, sometimes we don't. Should probably add the comma-dangle rule to enforce that one way or the other.
  • Sometimes there is a space after a function name during a declaration, other times there is not. space-before-function-paren can enforce this, and the best rule would be to always have a space, so that the parenthesis only touch the name when the code is being executed to make a clear visual distinction.

Feel free to look through that ruleset and read the comments that explain what each rule does and port over whatever parts you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

};
ayushmanchhabra marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 26 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
name: ci

on:
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
- name: Get Node version from Node manifest
run: |
echo "NODE_VER=$(jq -r '.engines.node' package.json | sed 's/v//' )" >> $GITHUB_ENV
- uses: actions/[email protected]
with:
node-version: ${{ env.NODE_VER }}
cache: "npm"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: npm ci
- name: Run test
run: npm test
name: ci

on:
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
- name: Get Node version from Node manifest
run: |
echo "NODE_VER=$(jq -r '.engines.node' package.json | sed 's/v//' )" >> $GITHUB_ENV
- uses: actions/[email protected]
with:
node-version: ${{ env.NODE_VER }}
cache: 'npm'
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: npm ci
- name: Check for linting errors
run: npm run lint:check
- name: Run test
run: npm test
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ An installer for [NW.js](https://nwjs.io).
[![npm](https://img.shields.io/npm/v/nw.svg?style=flat)](https://www.npmjs.com/package/nw)

## usage

Install locally to your project with: `npm install nw` and then in your `package.json` add a script:

```json
Expand All @@ -24,9 +25,11 @@ If your project is in another folder, add the path to the project `"start": "nw
You could also call `nw` directly from `node_modules/.bin/nw` instead of adding to your `package.json`.

### global

You can also install globally with `npm install nw -g` and then in any project type `nw` to run the project. Installing locally is recommended though as each project can have its own dependent version of nw.js.

## example

If you want a really quick example try this:

1. `git clone https://github.com/zcbenz/nw-sample-apps && cd nw-sample-apps`
Expand All @@ -37,35 +40,36 @@ If you want a really quick example try this:
and now you should see a file explorer demo app.

## command line options

There are a few (platform-specific) arguments you can pass to the `nw` executable to
customize your nw.js application:

* `--mac_plist <path-to-plist-file>`: (OS X only) Copies the given file to Info.plist in the app
- `--mac_plist <path-to-plist-file>`: (OS X only) Copies the given file to Info.plist in the app
bundle. This lets you do things like change your app's name and point to a different icon.

* `--mac_icon <path-to-icns-file>`: (OS X only) Copies the given .icns file to the Resources/ dir
- `--mac_icon <path-to-icns-file>`: (OS X only) Copies the given .icns file to the Resources/ dir
in the app bundle. You will need to point to the file with a custom plist file as well (see
`--mac_list`)

**NOTE**: These options will keep the copied files in the app bundle for as long as the bundle is
on the filesystem (they're not deleted between app invocations). As a result, they're not
recommended if you installed nw globally using `-g`. Also note that
recommended if you installed nw globally using `-g`. Also note that
[OS X caches these files](http://proteo.me.uk/2011/08/mac-application-bundle-caching/),
so you may need to manually clear these cached files during development.

## install a specific version of nw.js

To install a specific version of nw.js use npm with the specific version: `npm install [email protected]`

> *Please note:* This npm package version tracks the version of nw.js that will be installed, with an additional build number that is used for revisions to the installer. As such `0.12.0-1` and `0.12.0-2` will both install `[email protected]` but the latter has newer changes to the installer.
> _Please note:_ This npm package version tracks the version of nw.js that will be installed, with an additional build number that is used for revisions to the installer. As such `0.12.0-1` and `0.12.0-2` will both install `[email protected]` but the latter has newer changes to the installer.

You may use `npm view nw versions` to view the list of available versions.

## install a specific build type of nw.js

nw.js has three build types: `normal`, `sdk` and `nacl`. To install a specific build type you may set npm config property `nwjs_build_type`, environment variable `NWJS_BUILD_TYPE` or pass command line option `--nwjs_build_type`:

``` shell
```shell
npm install nw --nwjs_build_type=sdk
```

Expand All @@ -77,13 +81,13 @@ nwjs_build_type=sdk

Setting environment variable `NWJS_BUILD_TYPE`:

``` shell
```shell
export NWJS_BUILD_TYPE=sdk
```

You can alternatively install `sdk` build by specifying `-sdk` suffix in version:

``` shell
```shell
npm install [email protected]
```

Expand All @@ -97,31 +101,29 @@ You may use the environment variable `npm_config_nwjs_process_arch` to override

If you would like to programmatically retrieve the path to the nw.js binary use:

``` js
var findpath = require('nw').findpath;
```js
var findpath = require("nw").findpath;
var nwpath = findpath();
// nwpath will equal the path to the binary depending on your environment
```

Then you can use that path to run NW.js programmatically. For example, to run in the current script's directory:

```js
require('child_process').spawn(
require('nw').findpath(),
['.'].concat( process.argv.slice(2) ),
{
cwd: __dirname,
detached: true,
stdio: 'ignore'
}
).unref();
require("child_process")
.spawn(require("nw").findpath(), ["."].concat(process.argv.slice(2)), {
cwd: __dirname,
detached: true,
stdio: "ignore",
})
.unref();
```

## retrieve binaries from custom download location or file path

The installer attempts to download binaries from the default location of `https://dl.nwjs.io/v`. You can override this by setting the npm config property `nwjs_urlbase` on the command line by passing the `--nwjs_urlbase` option:

``` shell
```shell
npm install nw --nwjs_urlbase=http://my.own.location/somewhere
```

Expand All @@ -133,13 +135,13 @@ nwjs_urlbase=http://my.own.location/somewhere

You can alternatively set an environment variable `NWJS_URLBASE`:

``` shell
```shell
export NWJS_URLBASE=http://my.own.location/somewhere
```

The installer supports `file://` URLs to retrieve files from the local filesystem:

``` shell
```shell
export NWJS_URLBASE=file:///home/bilbo/my/own/mirror
```

Expand All @@ -160,4 +162,5 @@ export http_proxy="http://myproxy.com:8080"
(However, if the environment variable `https_proxy` is set, then it will be preferred, as [programmed](https://github.com/kevva/get-proxy/blob/master/index.js) in the `get-proxy` package.)

## license

[nw.js](https://github.com/nwjs/nw.js)'s code and this installer use the MIT license.
34 changes: 20 additions & 14 deletions bin/autobump
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ var pkgpath = path.join(__dirname, '..', 'package.json');
// Download README file
var readme = request(url);
var data = '';
readme.on('data', function(buf) { data += buf; });
readme.on('end', function() {
readme.on('data', function (buf) {
data += buf;
});
readme.on('end', function () {
var version = semver.clean(/\[v([^\s]+)\s+release notes\]/i.exec(data)[1]);
// Version invalid so quit
if (!semver.valid(version)) {
Expand All @@ -35,17 +37,21 @@ readme.on('end', function() {
'git push origin master',
'npm publish',
].join(' && ');
exec(cmd, { cwd: path.resolve(__dirname, '..') }, function(err, stdout, stderr) {
if (err || stderr) {
// Revert package.json change and try again next time
console.error('FAILED');
console.error(err || stderr);
pkg.version = currentversion;
fs.writeFileSync(pkgpath, JSON.stringify(pkg, null, 2));
// TODO: Should revert commit here as well
} else {
console.log('SUCCESS');
}
});
exec(
cmd,
{ cwd: path.resolve(__dirname, '..') },
function (err, stdout, stderr) {
if (err || stderr) {
// Revert package.json change and try again next time
console.error('FAILED');
console.error(err || stderr);
pkg.version = currentversion;
fs.writeFileSync(pkgpath, JSON.stringify(pkg, null, 2));
// TODO: Should revert commit here as well
} else {
console.log('SUCCESS');
}
},
);
}
});
22 changes: 15 additions & 7 deletions bin/nw
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function run() {

// Normalize cli args
var args = process.argv.slice(2);
var cwd = (args.length < 1) ? '.' : args[0];
var cwd = args.length < 1 ? '.' : args[0];
if (!fs.existsSync(path.resolve(cwd))) {
args = ['.'].concat(args);
} else {
Expand All @@ -29,25 +29,33 @@ function run() {

// Spawn node-webkit
var nw = spawn(bin, args, { stdio: 'inherit' });
nw.on('close', function() {
process.nextTick(function() {
nw.on('close', function () {
process.nextTick(function () {
process.exit(0);
});
});

// Restore package.json shortly after nw is spawned
setTimeout(function() {
setTimeout(function () {
try {
if (fs.existsSync(packagejsonBackup)) {
fs.renameSync(packagejsonBackup, packagejson);
}
} catch (err) {}
} catch (err) {
console.error(err);
}
}, 1000);
}

if (!fs.existsSync(bin)) {
console.log('nw.js appears to have failed to download and extract. Attempting to download and extract again...');
var child = spawn(process.execPath, [path.resolve(__dirname, '..', 'scripts', 'install.js')], { stdio: 'inherit' });
console.log(
'nw.js appears to have failed to download and extract. Attempting to download and extract again...',
);
ayushmanchhabra marked this conversation as resolved.
Show resolved Hide resolved
var child = spawn(
process.execPath,
[path.resolve(__dirname, '..', 'scripts', 'install.js')],
{ stdio: 'inherit' },
);
child.on('close', run);
} else {
run();
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Export `findpath` function to get the platform dependant path of the `nodewebkit` binary
*/
module.exports.findpath = require('./lib/findpath.js');
module.exports.findpath = require('./lib/findpath.js');
2 changes: 1 addition & 1 deletion lib/app_assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.copyAssets = function copyAssets(platform, binPath) {
// Note that for the icon to work properly you need to point to
// it with a custom plist file.
if (argv.mac_icon && platform === 'darwin') {
var iconName = path.basename(argv.mac_icon); // Preserve the file's name
var iconName = path.basename(argv.mac_icon); // Preserve the file's name
var iconPath = path.join(binPath, '..', '..', 'Resources', iconName);
copyFileSync(argv.mac_icon, iconPath);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/findpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs');
var path = require('path');
var bindir = path.resolve(__dirname, '..', 'nwjs');

module.exports = function() {
module.exports = function () {
var bin = bindir;
var platform = process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform;
if (platform === 'darwin') {
Expand All @@ -17,4 +17,4 @@ module.exports = function() {
bin = path.join(bin, 'nw');
}
return bin;
}
};
Loading