Skip to content

Commit

Permalink
v2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rehhouari committed Feb 22, 2024
1 parent 217da7f commit 8a84456
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [2.4.2] - 2024-02-22

### Changed

- Change build script and include README in NPM package.

## Added

- Minified ESM module file `dist/module.esm.min.js`.

## [2.4.1] - 2023-12-28

### Fixed
Expand Down Expand Up @@ -113,3 +123,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[2.3.0]: https://github.com/pinecone-router/router/compare/2.2.1...2.3.0
[2.4.0]: https://github.com/pinecone-router/router/compare/2.3.0...2.4.0
[2.4.1]: https://github.com/pinecone-router/router/compare/2.4.0...2.4.1
[2.4.2]: https://github.com/pinecone-router/router/compare/2.4.1...2.4.2
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Internationalization (i18n) support for Alpine.js (unofficial)

[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/rehhouari/alpinejs-i18n)](https://github.com/rehhouari/alpinejs-i18n/tree/2.4.1)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/alpinejs-i18n)](https://bundlephobia.com/[email protected].1)
[![Downloads from Jsdelivr NPM](https://img.shields.io/jsdelivr/npm/hm/alpinejs-i18n)](https://www.jsdelivr.com/package/npm/alpinejs-i18n?version=2.4.1)
[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/rehhouari/alpinejs-i18n)](https://github.com/rehhouari/alpinejs-i18n/tree/2.4.2)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/alpinejs-i18n)](https://bundlephobia.com/[email protected].2)
[![Downloads from Jsdelivr NPM](https://img.shields.io/jsdelivr/npm/hm/alpinejs-i18n)](https://www.jsdelivr.com/package/npm/alpinejs-i18n?version=2.4.2)
[![npm](https://img.shields.io/npm/dm/alpinejs-i18n)](https://npmjs.com/package/alpinejs-i18n)
[![Changelog](https://img.shields.io/badge/change-log-log)](/CHANGELOG.md)
[![Donate](https://img.shields.io/badge/Support-%E2%99%A5-pink)](https://ko-fi.com/rehhouari)
Expand Down Expand Up @@ -65,7 +65,7 @@ Add the following `<script>` to the `<head>` of your document **before** includi

```html
<script type="module">
import AlpineI18n from "https://cdn.jsdelivr.net/npm/[email protected]/dist/module.esm.js";
import AlpineI18n from "https://cdn.jsdelivr.net/npm/[email protected]/dist/module.esm.min.js";
document.addEventListener("alpine-i18n:ready", function () {
// ... scroll to Usage to see where locale and messages came from
window.AlpineI18n.create(locale, messages);
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/main/dist/cdn.js → dist/cdn.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(() => {
// packages/main/src/index.ts
// src/index.ts
var localeChange = new Event("alpine-i18n:locale-change");
var i18nReady = new Event("alpine-i18n:ready");
var AlpineI18n = {
version: "2.4.1",
version: "2.4.2",
set locale(name) {
this.checkLocale(name);
this.currentLocale = name;
Expand Down Expand Up @@ -67,7 +67,7 @@
});
}

// packages/main/builds/cdn.js
// builds/cdn.js
document.addEventListener("alpine:initializing", () => {
src_default(window.Alpine);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/main/dist/cdn.min.js → dist/cdn.min.js
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/main/dist/module.cjs.js → dist/module.cjs.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ var __export = (target, all) => {
__defProp(target, name, {get: all[name], enumerable: true});
};

// packages/main/builds/module.js
// builds/module.js
__markAsModule(exports);
__export(exports, {
default: () => module_default
});

// packages/main/src/index.ts
// src/index.ts
var localeChange = new Event("alpine-i18n:locale-change");
var i18nReady = new Event("alpine-i18n:ready");
var AlpineI18n = {
version: "2.4.1",
version: "2.4.2",
set locale(name) {
this.checkLocale(name);
this.currentLocale = name;
Expand Down Expand Up @@ -80,5 +80,5 @@ function src_default(Alpine) {
});
}

// packages/main/builds/module.js
// builds/module.js
var module_default = src_default;
6 changes: 3 additions & 3 deletions packages/main/dist/module.esm.js → dist/module.esm.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// packages/main/src/index.ts
// src/index.ts
var localeChange = new Event("alpine-i18n:locale-change");
var i18nReady = new Event("alpine-i18n:ready");
var AlpineI18n = {
version: "2.4.1",
version: "2.4.2",
set locale(name) {
this.checkLocale(name);
this.currentLocale = name;
Expand Down Expand Up @@ -66,7 +66,7 @@ function src_default(Alpine) {
});
}

// packages/main/builds/module.js
// builds/module.js
var module_default = src_default;
export {
module_default as default
Expand Down
1 change: 1 addition & 0 deletions dist/module.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"workspaces": [
"packages/*"
],
"name": "alpinejs-i18n",
"description": "Internationalization (i18n) support for Alpine.js",
"license": "MIT",
"author": "Rafik El Hadi Houari",
"version": "2.4.2",
"repository": {
"type": "git",
"url": "https://github.com/rehhouari/alpinejs-i18n"
},
"main": "dist/module.cjs.js",
"module": "dist/module.esm.min.js",
"devDependencies": {
"brotli-size": "^4.0.0",
"esbuild": "^0.8.39",
Expand All @@ -19,4 +27,4 @@
"lint": "eslint .",
"lint-fix": "eslint . --fix"
}
}
}
Empty file removed packages/.gitkeep
Empty file.
13 changes: 0 additions & 13 deletions packages/main/package.json

This file was deleted.

60 changes: 35 additions & 25 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
const fs = require('fs')
const brotliSize = require('brotli-size');
const brotliSize = require('brotli-size')

([
'main',
]).forEach(packageName => {
if (!fs.existsSync(`./packages/${packageName}/dist`)) {
fs.mkdirSync(`./packages/${packageName}/dist`, '0744')
}
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist', '0744')
}

// Go through each file in the packageName's "build" directory
// and use the appropriate bundling strategy based on its name.
fs.readdirSync(`./packages/${packageName}/builds`).forEach(file => {
bundleFile(packageName, file)
})
// Go through each file in the src's "build" directory
// and use the appropriate bundling strategy based on its name.
fs.readdirSync('./builds').forEach(file => {
bundleFile(file)
})

function bundleFile(packageName, file) {
function bundleFile(file) {
// Based on the filename, give esbuild a specific configuration to build.
({
// This output file is meant to be loaded in a browser's <script> tag.
'cdn.js': () => {
build({
entryPoints: [`packages/${packageName}/builds/${file}`],
outfile: `packages/${packageName}/dist/${file}`,
entryPoints: [`builds/${file}`],
outfile: `dist/${file}`,
bundle: true,
platform: 'browser',
define: { CDN: true },
})

// Build a minified version.
build({
entryPoints: [`packages/${packageName}/builds/${file}`],
outfile: `packages/${packageName}/dist/${file.replace('.js', '.min.js')}`,
entryPoints: [`builds/${file}`],
outfile: `dist/${file.replace('.js', '.min.js')}`,
bundle: true,
minify: true,
platform: 'browser',
define: { CDN: true },
}).then(() => {
outputSize(packageName, `packages/${packageName}/dist/${file.replace('.js', '.min.js')}`)
outputSize(
`dist/${file.replace('.js', '.min.js')}`)
})
},
// This file outputs two files: an esm module and a cjs module.
// The ESM one is meant for "import" statements (bundlers and new browsers)
// and the cjs one is meant for "require" statements (node).
'module.js': () => {
build({
entryPoints: [`packages/${packageName}/builds/${file}`],
outfile: `packages/${packageName}/dist/${file.replace('.js', '.esm.js')}`,
entryPoints: [`builds/${file}`],
outfile: `dist/${file.replace('.js', '.esm.js')}`,
bundle: true,
platform: 'neutral',
mainFields: ['main', 'module'],
})

// Minified ESM file
build({
entryPoints: [`builds/${file}`],
outfile: `dist/${file.replace('.js', '.esm.min.js')}`,
bundle: true,
minify: true,
platform: 'neutral',
mainFields: ['main', 'module'],
}).then(() => {
outputSize(
`dist/${file.replace('.js', '.esm.min.js')}`)
})

build({
entryPoints: [`packages/${packageName}/builds/${file}`],
outfile: `packages/${packageName}/dist/${file.replace('.js', '.cjs.js')}`,
entryPoints: [`builds/${file}`],
outfile: `dist/${file.replace('.js', '.cjs.js')}`,
bundle: true,
target: ['node10.4'],
platform: 'node',
Expand All @@ -73,16 +83,16 @@ function build(options) {
}).catch(() => process.exit(1))
}

function outputSize(packageName, file) {
function outputSize(file) {
const size = bytesToSize(brotliSize.sync(fs.readFileSync(file)))

console.log('\x1b[32m', `${packageName}: ${size}`)
console.log('\x1b[32m', file + ' : ' + size)
}

function bytesToSize(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
if (bytes === 0) return 'n/a'
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
if (i === 0) return `${bytes} ${sizes[i]}`
return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`
return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]} `
}
2 changes: 1 addition & 1 deletion packages/main/src/index.ts → src/index.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const localeChange = new Event("alpine-i18n:locale-change");
const i18nReady = new Event("alpine-i18n:ready");

const AlpineI18n = {
version: "2.4.1",
version: "2.4.2",

/**
* setter for the current locale
Expand Down

0 comments on commit 8a84456

Please sign in to comment.