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

feature: v1 #1

Merged
merged 13 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
16 changes: 16 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "wethegit/masher"
}
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/wise-berries-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wethegit/masher": major
---

v1
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.changeset/
.github/
.husky/
.vscode/
dist/
node_modules/
tsup.config.ts
55 changes: 55 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module.exports = {
extends: ["plugin:import/recommended", "prettier"],
plugins: ["import"],
ignorePatterns: ["node_modules/", "dist/", ".eslintrc.*"],
rules: {
"import/no-default-export": "off",
"import/no-named-as-default": "off",
"import/named": "off",
"import/namespace": "off",
"import/default": "off",
"import/no-named-as-default-member": "off",
"import/order": [
"error",
{
"newlines-between": "always",
pathGroups: [
{
pattern: "@local/**",
group: "external",
position: "after",
},
],
distinctGroup: true,
},
],
},
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
env: {
node: true,
},
overrides: [
{
files: ["*.ts"],
extends: ["plugin:@typescript-eslint/recommended", "plugin:import/typescript"],
plugins: ["@typescript-eslint"],
parser: "@typescript-eslint/parser",
settings: {
"import/resolver": {
typescript: {
root: ["."],
project: "./tsconfig.json",
},
},
},
rules: {
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/indent": "off",
},
},
],
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@wethegit/reviewers
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- use this as template for your PR title -->

# fix/release/feature/patch: title

## Description

A **brief** description of the feature or bug, just to make the developer reviewing your work more familiar.

## Solution

A **brief** summary of why you fixed/created something the way you did and any known limitations because of this (i.e. browser support).

## Additional Notes

Any additional notes or information that should be made or highlighted.

## Screenshots

Screenshots/videos showcasing your updates - if applicable.
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
pull_request:
types: [opened, edited, reopened, synchronize]

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 20.10.x
uses: actions/setup-node@v3
with:
node-version: 20.10

- name: Install Dependencies
run: npm install

- name: Lint
run: npm run lint
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
permissions:
contents: write # to create release (changesets/action)
issues: write # to post issue comments (changesets/action)
pull-requests: write # to create pull request (changesets/action)
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 20.10.x
uses: actions/setup-node@v3
with:
node-version: 20.10

- name: Install Dependencies
run: npm install

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: npm run version
publish: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.changeset/
.github/
.husky/
.vscode/
src/
.eslintignore
.eslintrc.cjs
.prettierignore
.prettierrc
tsconfig.json
tsup.config.ts
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.10.0
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.changeset/
.github/
.husky/
.vscode/
node_modules/
dist/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"endOfLine": "lf",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 90
}
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"eslint.format.enable": true,
"eslint.nodePath": "",
"files.associations": {
"*.js": "javascriptreact",
"*.jsx": "javascriptreact",
"*.json": "json"
},
"javascript.updateImportsOnFileMove.enabled": "always"
}
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 We The Collective Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
101 changes: 99 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,99 @@
# masher
Image optimization tool and React component.
# @wethegit/masher

> A simple CLI tool to compress images.

## Requirements

Node 20.10.0 or higher.

## Install

```bash
npm install @wethegit/masher
```

## Usage

By default the masher will look for images in a `src/images` directory and output them to a `public/_images` directory.

You can change that by adding a `masher.config.json` file to your project root.

```json file=masher.config.json
{
"outputPath": "public/_images/",
"inputPath": "src/images/"
}
```

This file will also be generate for you the first time you run the masher.

If you add images to the `inputPath` that have the `-2x` suffix on their filenames, for example, `/src/images/banner-logo-2x.png`, `masher` will not only compress these images but it will also automatically generate a `1x` version of them.

After adding your images to the `inputPath` you can run the masher by running:

```bash
npx @wethegit/masher
```

Folloing the example if you have the following directory structure:

```
src/
└── images/
└── banner-logo-2x.png
```

The masher will generate PNGs and WEBPs for both `banner-logo-2x.png` and `banner-logo.png` in the `public/_images` directory:

```
public/
└── _images/
├── banner-logo-2x.png
├── banner-logo-2x.webp
├── banner-logo.png
└── banner-logo.webp
```

Apart form the config file, the masher will create two more files in your project root, one called `mash.cache.json` and another called `images_register.json`.

`mash.cache.json` should be added to your `.gitignore` file as it will be used to keep track of the images that have already been compressed and will be used to skip them on subsequent runs.

`images_register.json` is a file that will be used to keep track of the images that have been compressed and will be used to generate a `1x` version of the images that have a `-2x` suffix on their filenames. **Note for Corgi users:** this file will be used by the `<Picture />` component to generate the `srcSet` attribute of images.

### Accepted image formats

The masher will only compress images that have the following extensions:

- png
- webp
- jpg
- jpeg

## Options

`--watch`
This will start the masher in watch mode, meaning that it will keep running and will compress any new images that are added to the `inputPath`.

```bash
npx @wethegit/masher --watch
```

`--clean`
This will delete the `outputPath` directory before running the masher.

```bash
npx @wethegit/masher --clean
```

`--force`
This will force the masher to compress all images, even if they have already been compressed.

```bash
npx @wethegit/masher --force
```

To see all available options run:

```bash
npx @wethegit/masher --help
```
Loading