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: Improved API for v1 & set up base release #206

Merged
merged 4 commits into from
Sep 9, 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
File renamed without changes.
80 changes: 80 additions & 0 deletions .github/workflows/pkg-npm-publish-prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: 'pkg: Publish to npm'
run-name: 'Publish prerelease to npm Registry (${{ inputs.version }})'

on:
workflow_dispatch:
inputs:
version:
description: 'Semantic Version'
required: true
type: choice
options:
- alpha
- beta

jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
steps:
- name: '🛒 Checkout Code'
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_BOT_TOKEN }}

- name: '🟢 Use Node.js'
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'

- name: '🔁 Sync GitHub Linguist'
run: 'yarn sync:linguist'

- name: '🔁 Sync GitHub Emoji'
run: 'yarn sync:emoji'

- name: '🏗️ Build'
run: yarn build

- name: '🔼 Increment Version'
run: yarn version prerelease --preid=${{ inputs.version }}

- name: '#️⃣ Get Version'
uses: actions/github-script@v7
id: version
with:
result-encoding: string
retries: 3
script: |
const fs = require('fs');
const pj = JSON.parse(fs.readFileSync('${{ github.workspace }}/package.json'));
return pj.version;

- name: '💾 Commit Incremented Version'
run: |
git config --local user.email "${{ secrets.GH_BOT_EMAIL }}"
git config --local user.name "${{ secrets.GH_BOT_NAME }}"
git add package.json
git commit -am "[🤖 release]: ${{ steps.version.outputs.result }} (${{ inputs.version }})"
git push origin HEAD --force

- name: '📝 Generate Release Notes (user-input)'
uses: toolmantim/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: v${{ steps.version.outputs.result }}
publish: true

- name: Setup .yarnrc.yml
run: |
yarn config set npmScopes.joggr.npmRegistryServer "https://registry.npmjs.org"
yarn config set npmScopes.joggr.npmAlwaysAuth true
yarn config set npmScopes.joggr.npmAuthToken $NPM_AUTH_TOKEN
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH }}

- name: '🚢 Publish'
run: yarn npm publish --access public
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'

- name: '🔁 Sync GitHub Linguist'
run: 'yarn sync:linguist'

- name: '🔁 Sync GitHub Emoji'
run: 'yarn sync:emoji'

- name: '🏗️ Build'
run: yarn build

Expand Down
46 changes: 46 additions & 0 deletions .vscode/typescript.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 🚨 DO NOT EDIT, auto-generated by @pkg/blueprints 🚨

{
"Comment: Header": {
"scope": "typescript",
"prefix": "cmt-head",
"description": "The top level file within a file or module.",
"body": [
"/*",
"|==========================================================================",
"| ${TM_FILENAME_BASE}",
"|==========================================================================",
"|",
"| $0",
"|",
"*/"
]
},
"Comment: Section": {
"scope": "typescript",
"prefix": "cmt-section",
"description": "A section within a file or module.",
"body": [
"/*",
"|----------------------------------",
"| ${TM_FILENAME_BASE}",
"|----------------------------------",
"|",
"| $2$0",
"|",
"*/"
]
},
"Comment: Subsection": {
"scope": "typescript",
"prefix": "cmt-subsection",
"description": "A subsection within a file or module.",
"body": [
"/*",
"|------------------",
"| $0",
"|------------------",
"*/"
]
}
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@joggr/tempo",
"version": "0.9.2",
"version": "1.0.0",
"description": "Library used to programmatically build markdown documents, with a heavy tilt toward GitHub Flavored Markdown (GFM).",
"exports": {
".": {
Expand All @@ -27,7 +27,9 @@
"analyze": "biome check",
"analyze:ci": "biome ci --diagnostic-level=error",
"analyze:types": "tsc --noEmit",
"fix": "biome check --fix"
"fix": "biome check --fix",
"sync:linguist": "node ./scripts/sync-github-linguist.js",
"sync:emoji": "node ./scripts/sync-github-emoji.js"
},
"repository": {
"type": "git",
Expand All @@ -45,9 +47,11 @@
"@swc/core": "^1.7.24",
"@types/node": "^22.5.4",
"@vitest/coverage-istanbul": "^2.0.5",
"axios": "^1.7.7",
"type-fest": "^4.26.1",
"typescript": "^5.6.2",
"vitest": "^2.0.5"
"vitest": "^2.0.5",
"yaml": "^2.5.1"
},
"packageManager": "yarn@4.4.1"
}
45 changes: 45 additions & 0 deletions scripts/sync-github-emoji.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require('node:fs');
const path = require('node:path');
const axios = require('axios');

const URL =
'https://raw.githubusercontent.com/ricealexander/emoji-list/main/emojis.json';

const FILE_NAME = 'emojis.ts';

const DIR_ROOT = path.join(__dirname, '..');

const FILE_PATH = path.join(DIR_ROOT, 'src', '@generated', FILE_NAME);

const warning = `
/* 🚨🚨🚨 DO NOT EDIT 🚨🚨🚨 */
/* This file is automatically generated. */
`;

axios
.get(URL)
.then((response) => {
const data = response.data.map(({ alias, ...emoji }) => {
if (Array.isArray(alias)) {
return {
...emoji,
aliases: alias,
};
}

return {
...emoji,
aliases: [alias],
};
});

const content = `export default ${JSON.stringify(data, null, 2)} as const;`;
fs.writeFileSync(FILE_PATH, [warning, content].join('\n\n').trimStart());

console.log(
`✅ Synced ${data.length} emojis to "src/@generated/${FILE_NAME}"`
);
})
.catch((error) => {
console.error('Error fetching the JSON file:', error);
});
48 changes: 48 additions & 0 deletions scripts/sync-github-linguist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('node:fs');
const path = require('node:path');
const axios = require('axios');
const yaml = require('yaml');

const URL =
'https://raw.githubusercontent.com/github-linguist/linguist/master/lib/linguist/languages.yml';

const FILE_NAME = 'languages.ts';

const DIR_ROOT = path.join(__dirname, '..');

const FILE_PATH = path.join(DIR_ROOT, 'src', '@generated', FILE_NAME);

const warning = `
/* 🚨🚨🚨 DO NOT EDIT 🚨🚨🚨 */
/* This file is automatically generated. */
`;

axios
.get(URL)
.then((response) => {
const data = yaml.parse(response.data);
const langs = [];

function extractCodemirrorModes(obj) {
for (const key in obj) {
if (key === 'codemirror_mode') {
langs.push(obj[key]);
} else if (typeof obj[key] === 'object') {
extractCodemirrorModes(obj[key]);
}
}
}

extractCodemirrorModes(data);

const content = `export default ${JSON.stringify(langs, null, 2)} as const;`;

fs.writeFileSync(FILE_PATH, [warning, content].join('\n\n').trimStart());

console.log(
`✅ Synced ${langs.length} CodeMirror modes from GitHub Linguist to "src/@generated/${FILE_NAME}"`
);
})
.catch((error) => {
console.error('Error fetching the YAML file:', error);
});
Loading