Skip to content

Commit

Permalink
feat: working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
duddu committed Apr 20, 2024
1 parent 062834f commit c68bb23
Show file tree
Hide file tree
Showing 35 changed files with 10,882 additions and 1,950 deletions.
3 changes: 3 additions & 0 deletions .czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "./node_modules/cz-conventional-changelog"
}
8 changes: 4 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended" // uses the recommended rules from the @typescript-eslint/eslint-plugin
],
"plugins": ["eslint-plugin-unicorn/expiring-todo-comments"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"ignorePatterns": [
"dist"
],
"ignorePatterns": ["dist"],
"rules": {
"quotes": ["warn", "single"],
"indent": ["warn", 2, { "SwitchCase": 1 }],
Expand All @@ -33,6 +32,7 @@
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/semi": ["warn"],
"@typescript-eslint/member-delimiter-style": ["warn"]
"@typescript-eslint/member-delimiter-style": "warn",
"eslint-plugin-unicorn/expiring-todo-comments": "off"
}
}
Binary file added .github/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
strategy:
fail-fast: false
matrix:
# the Node.js versions to build on
node-version: [18.x, 20.x]

steps:
Expand Down
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:
- latest
repository_dispatch:
types: [semantic-release]

permissions:
contents: read

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Install dependencies
run: npm clean-install
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ web_modules/
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

# dev-only local executables
bin/
14 changes: 14 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"branches": ["latest"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"assets": ["dist/**"]
}
]
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"editor.rulers": [100],
"files.autoSave": "onFocusChange",
"files.eol": "\n",
"vs-code-prettier-eslint.prettierLast": false
"vs-code-prettier-eslint.prettierLast": false,
"typescript.tsdk": "node_modules/typescript/lib",
"sarif-viewer.connectToGithubCodeScanning": "off"
}
169 changes: 169 additions & 0 deletions bin/schema2ts.js

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

10 changes: 10 additions & 0 deletions bin/schema2ts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

CWD=$(dirname $(readlink -f "$0"))

rm -f "$CWD"/*.js
tsc -p "$CWD"
chmod 744 "$CWD/schema2ts.js"
node "$CWD/schema2ts.js"
83 changes: 83 additions & 0 deletions bin/schema2ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { join } from 'path';
import { exit, stdout } from 'process';
import { writeFile, readFile } from 'fs/promises';
import { compile, Options } from 'json-schema-to-typescript';

import { schema } from '../config.schema.json';

const configInterfaceName = 'ShortcutsButtonsUserConfig';
const moduleName = 'SchemaForm2Ts';
const outputRootPath = '/src/config.ts';
const outputRelativePath = join(__dirname, '../', outputRootPath);
const prettierrcPath = join(__dirname, '../.prettierrc');

async function main(): Promise<void> {
const config = await compile(
schema as never,
configInterfaceName,
await getCompileOptions(),
);

await writeConfig(config);

stdout.write(
`🚀 ${moduleName}: Plugin configuration interface generated at ${outputRootPath}\n\n`,
);

exit(0);
}

async function getCompileOptions(): Promise<Partial<Options>> {
let style: Options['style'];
try {
const prettierConfig = await readFile(prettierrcPath);
style = await JSON.parse(prettierConfig.toString());
} catch (e) {
throw new SchemaForm2TsError(
`Unable to read Prettier configuration from ${prettierrcPath}`,
e,
);
}

return {
additionalProperties: false,
bannerComment:
'/**\n* DO NOT EDIT MANUALLY.\n' +
'* This file was automatically generated from `/config.schema.json`.\n' +
'* Update the source schema file and run `schema2ts` to regenerate this file.\n*/',
ignoreMinAndMaxItems: true,
strictIndexSignatures: true,
style,
};
}

async function writeConfig(config: string): Promise<void> {
try {
return await writeFile(outputRelativePath, config, {
flag: 'w+',
mode: 0o644,
});
} catch (e) {
throw new SchemaForm2TsError(
`Unable to write output at ${outputRootPath}`,
e,
);
}
}

@frozen
class SchemaForm2TsError extends Error {
constructor(message: string, exception: unknown) {
require('source-map-support').install();
super(`${message}\n\n ${exception}\n`);
Error.captureStackTrace(this, this.constructor);
this.name = `💥 ${moduleName}`;
}
}

function frozen(constructor: Function) {
Object.freeze(constructor);
Object.freeze(constructor.prototype);
}

(async (): Promise<void> => main()).call(null);
16 changes: 16 additions & 0 deletions bin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSourceMap": true,
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true
},
"include": ["**/*.ts"],
"exclude": ["**/*.spec.ts"]
}
Loading

0 comments on commit c68bb23

Please sign in to comment.