Skip to content

Commit

Permalink
Modern codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Sep 24, 2023
1 parent 5e83194 commit b3fbac7
Show file tree
Hide file tree
Showing 27 changed files with 4,435 additions and 2,900 deletions.
16 changes: 0 additions & 16 deletions .babelrc

This file was deleted.

5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/lib
/module.mjs
/dts
/esm
/cjs
/spec/encodes
23 changes: 22 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ rules:
MethodDefinition: true
checkGetters: true
checkSetters: true
jsdoc/tag-lines:
- warn
- never
- startLines: 1

# TypeScript Simple:
'@typescript-eslint/array-type': error
Expand Down Expand Up @@ -445,29 +449,45 @@ overrides:
rules:
'@typescript-eslint/no-unsafe-assignment': off
'@typescript-eslint/no-unsafe-member-access': off
'@typescript-eslint/no-unsafe-call': off
'@typescript-eslint/no-unsafe-return': off
- files:
- '*.ts'
- '*.tsx'
rules:
jsdoc/no-types: warn
- files:
- '*.test.js'
- '*.test.jsx'
- '*.test.mjs'
- '*.test.mjsx'
- '*.test.ts'
- '*.test.tsx'
- '*.spec.js'
- '*.spec.jsx'
- '*.spec.mjs'
- '*.spec.mjsx'
- '*.spec.ts'
- '*.spec.tsx'
rules:
no-void: off
jsdoc/require-jsdoc: off
'@typescript-eslint/no-floating-promises':
- error
- ignoreVoid: true
- files:
- 'gulpfile.babel.ts'
- 'babel.config.js'
rules:
import/no-extraneous-dependencies:
- error
- devDependencies: true
optionalDependencies: false
peerDependencies: false
jsdoc/require-jsdoc: off
'@typescript-eslint/no-require-imports': off
'@typescript-eslint/no-var-requires': off
parserOptions:
sourceType: script
- files:
- 'bin/*.js'
rules:
Expand All @@ -476,6 +496,7 @@ overrides:
jsdoc/require-jsdoc: off
'@typescript-eslint/naming-convention': off
'@typescript-eslint/no-require-imports': off
'@typescript-eslint/no-var-requires': off
'@typescript-eslint/no-unsafe-argument': off
'@typescript-eslint/no-unsafe-call': off
'@typescript-eslint/no-unsafe-return': off
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ jobs:
strategy:
matrix:
config:
- node-version: '14.15.0' # LTS
NO_FORMATTED: 1
NO_LINT: 1
- runs-on: ubuntu-latest
node-version: '18.12.0' # LTS

- node-version: '16.13.0' # LTS
NO_FORMATTED: 1
NO_LINT: 1
- runs-on: ubuntu-latest
node-version: '18.18.0' # LTS (current)
CODE_CHECK: 1

- node-version: '18.12.0' # LTS (current)
- runs-on: ubuntu-latest
node-version: '20.7.0'

- node-version: '19.0.0' # Latest

runs-on: ubuntu-20.04
runs-on: ${{ matrix.config.runs-on }}

steps:
- name: Checkout
Expand All @@ -44,17 +42,17 @@ jobs:

- name: Lint
run: npm run lint
if: matrix.config.NO_LINT != 1
if: matrix.config.CODE_CHECK == 1

- name: Formatted
run: npm run formatted
if: matrix.config.NO_FORMATTED != 1
if: matrix.config.CODE_CHECK == 1

publish:
if: startsWith(github.ref, 'refs/tags/')
needs: build

runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Checkout
Expand All @@ -63,7 +61,7 @@ jobs:
- name: Node
uses: actions/setup-node@v3
with:
node-version: '16.16.0'
node-version: '18.18.0'
registry-url: https://registry.npmjs.org/

- name: Dependencies
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ yarn.lock
.vscode

# Build files
/lib
/dts
/esm
/cjs
19 changes: 12 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ yarn.lock
/.gitattributes
/.gitignore
/.github
/.babelrc
/.editorconfig
/.eslintignore
/.eslintrc.yaml
/.prettierrc.yaml
/.prettierignore
/babel.config.js
/tsconfig.json
/tsconfig.eslint.json
/gulpfile.babel.ts
/spec
/src

/lib/**/*.spec.d.ts
/lib/**/*.spec.js
/lib/**/*.spec.js.map
/lib/**/*.spec.mjs
/lib/**/*.spec.mjs.map
/dts/**/*.test.d.ts
/esm/**/*.test.mjs
/esm/**/*.test.mjs.map
/cjs/**/*.test.js
/cjs/**/*.test.js.map

/dts/**/*.spec.d.ts
/esm/**/*.spec.mjs
/esm/**/*.spec.mjs.map
/cjs/**/*.spec.js
/cjs/**/*.spec.js.map
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.12.0
18.18.0
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/package-lock.json
/lib
/dts
/esm
/cjs
/spec/encodes
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Usage: shockpkg-icon-encoder [options...] (icon.ico | icon.icns) pngs...
### Windows ICO

```js
import fs from 'fs';
import {readFile, writeFile} from 'node:fs/promises';
import {IconIco} from '@shockpkg/icon-encoder';

// Default null automatically compresses icons for backwards compatibility.
Expand All @@ -53,19 +53,19 @@ const png = null;
const raw = false;

const ico = new IconIco();
ico.addFromPng(fs.readFileSync('icon/256x256.png'), png, raw);
ico.addFromPng(fs.readFileSync('icon/128x128.png'), png, raw);
ico.addFromPng(fs.readFileSync('icon/64x64.png'), png, raw);
ico.addFromPng(fs.readFileSync('icon/48x48.png'), png, raw);
ico.addFromPng(fs.readFileSync('icon/32x32.png'), png, raw);
ico.addFromPng(fs.readFileSync('icon/16x16.png'), png, raw);
fs.writeFileSync('icon.ico', ico.encode());
ico.addFromPng(await readFile('icon/256x256.png'), png, raw);
ico.addFromPng(await readFile('icon/128x128.png'), png, raw);
ico.addFromPng(await readFile('icon/64x64.png'), png, raw);
ico.addFromPng(await readFile('icon/48x48.png'), png, raw);
ico.addFromPng(await readFile('icon/32x32.png'), png, raw);
ico.addFromPng(await readFile('icon/16x16.png'), png, raw);
await writeFile('icon.ico', ico.encode());
```

### macOS ICNS (current formats)

```js
import fs from 'fs';
import {readFile, writeFile} from 'node:fs/promises';
import {IconIcns} from '@shockpkg/icon-encoder';

const icns = new IconIcns();
Expand All @@ -80,31 +80,31 @@ const raw = false;

// This order matches that of iconutil with the same image set in macOS 10.14.
// Images with @2x are just 2x the size their file name suggests.
icns.addFromPng(fs.readFileSync('icon/[email protected]'), ['ic12'], raw);
icns.addFromPng(fs.readFileSync('icon/128x128.png'), ['ic07'], raw);
icns.addFromPng(fs.readFileSync('icon/[email protected]'), ['ic13'], raw);
icns.addFromPng(fs.readFileSync('icon/256x256.png'), ['ic08'], raw);
icns.addFromPng(fs.readFileSync('icon/16x16.png'), ['ic04'], raw);
icns.addFromPng(fs.readFileSync('icon/[email protected]'), ['ic14'], raw);
icns.addFromPng(fs.readFileSync('icon/512x512.png'), ['ic09'], raw);
icns.addFromPng(fs.readFileSync('icon/32x32.png'), ['ic05'], raw);
icns.addFromPng(fs.readFileSync('icon/[email protected]'), ['ic10'], raw);
icns.addFromPng(fs.readFileSync('icon/[email protected]'), ['ic11'], raw);
fs.writeFileSync('icon.icns', icns.encode());
icns.addFromPng(await readFile('icon/[email protected]'), ['ic12'], raw);
icns.addFromPng(await readFile('icon/128x128.png'), ['ic07'], raw);
icns.addFromPng(await readFile('icon/[email protected]'), ['ic13'], raw);
icns.addFromPng(await readFile('icon/256x256.png'), ['ic08'], raw);
icns.addFromPng(await readFile('icon/16x16.png'), ['ic04'], raw);
icns.addFromPng(await readFile('icon/[email protected]'), ['ic14'], raw);
icns.addFromPng(await readFile('icon/512x512.png'), ['ic09'], raw);
icns.addFromPng(await readFile('icon/32x32.png'), ['ic05'], raw);
icns.addFromPng(await readFile('icon/[email protected]'), ['ic10'], raw);
icns.addFromPng(await readFile('icon/[email protected]'), ['ic11'], raw);
await writeFile('icon.icns', icns.encode());
```

### macOS ICNS (legacy formats)

```js
import fs from 'fs';
import {readFile, writeFile} from 'node:fs/promises';
import {IconIcns} from '@shockpkg/icon-encoder';

const icns = new IconIcns();
icns.addFromPng(fs.readFileSync('icon/16x16.png'), ['is32', 's8mk']);
icns.addFromPng(fs.readFileSync('icon/32x32.png'), ['il32', 'l8mk']);
icns.addFromPng(fs.readFileSync('icon/48x48.png'), ['ih32', 'h8mk']);
icns.addFromPng(fs.readFileSync('icon/128x128.png'), ['it32', 't8mk']);
fs.writeFileSync('icon.icns', icns.encode());
icns.addFromPng(await readFile('icon/16x16.png'), ['is32', 's8mk']);
icns.addFromPng(await readFile('icon/32x32.png'), ['il32', 'l8mk']);
icns.addFromPng(await readFile('icon/48x48.png'), ['ih32', 'h8mk']);
icns.addFromPng(await readFile('icon/128x128.png'), ['it32', 't8mk']);
await writeFile('icon.icns', icns.encode());
```

# Bugs
Expand All @@ -113,7 +113,7 @@ If you find a bug or have compatibility issues, please open a ticket under issue

# License

Copyright (c) 2019-2022 JrMasterModelBuilder
Copyright (c) 2019-2023 JrMasterModelBuilder

Licensed under the Mozilla Public License, v. 2.0.

Expand Down
69 changes: 69 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

const {name, version, engines} = require('./package.json');

const node = engines.node
.split(/[^\d.]+/)
.filter(s => s.length)
.map(s => [...s.split('.').map(s => +s || 0), 0, 0].slice(0, 3))
.sort((a, b) => a[2] - b[2])
.sort((a, b) => a[1] - b[1])
.sort((a, b) => a[0] - b[0])[0]
.join('.');

module.exports = api => {
const env = api.env();
api.cache(() => env);
const modules = env === 'esm' ? false : 'commonjs';
const ext = modules ? '.js' : '.mjs';
const presets = [];
const plugins = [];
presets.push([
'@babel/preset-env',
{
modules,
exclude: ['proposal-dynamic-import'],
targets: {
node
}
}
]);
presets.push(['@babel/preset-typescript']);
if (modules === 'commonjs') {
plugins.push([
'@babel/plugin-transform-modules-commonjs',
{
importInterop: 'node'
}
]);
}
plugins.push([
'esm-resolver',
{
source: {
extensions: [
[['.js', '.mjs', '.jsx', '.mjsx', '.ts', '.tsx'], ext]
]
}
}
]);
plugins.push([
'search-and-replace',
{
rules: [
{
search: '#{NAME}',
replace: name
},
{
search: '#{VERSION}',
replace: version
}
]
}
]);
return {
presets,
plugins
};
};
Loading

0 comments on commit b3fbac7

Please sign in to comment.