From a66dcab598aa23c706cabd48b690f2b81d645af2 Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Tue, 8 Aug 2023 05:16:25 +0300 Subject: [PATCH] Initial commit --- .github/dependabot.yml | 12 ++++ .github/workflows/Dependabot.yml | 43 +++++++++++++ .github/workflows/NPM.yml | 41 ++++++++++++ .github/workflows/Node.yml | 93 ++++++++++++++++++++++++++++ .github/workflows/codeql.yml | 64 +++++++++++++++++++ .gitignore | 1 + .npmignore | 3 + CHANGELOG.md | 7 +++ Source/Bin.ts | 3 + Source/Command/Build.ts | 43 +++++++++++++ Source/Configuration/TypeScript.json | 50 +++++++++++++++ Source/Configuration/esbuild.ts | 39 ++++++++++++ Source/Index.ts | 18 ++++++ Source/Library/JSON.ts | 13 ++++ Target/Bin.d.ts | 2 + Target/Bin.js | 2 + Target/Command/Build.d.ts | 6 ++ Target/Command/Build.js | 1 + Target/Configuration/TypeScript.json | 50 +++++++++++++++ Target/Configuration/esbuild.d.ts | 10 +++ Target/Configuration/esbuild.js | 1 + Target/Index.d.ts | 1 + Target/Index.js | 1 + Target/Library/JSON.d.ts | 2 + Target/Library/JSON.js | 1 + package.json | 25 ++++++++ tsconfig.json | 7 +++ 27 files changed, 539 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/Dependabot.yml create mode 100644 .github/workflows/NPM.yml create mode 100644 .github/workflows/Node.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 CHANGELOG.md create mode 100644 Source/Bin.ts create mode 100644 Source/Command/Build.ts create mode 100644 Source/Configuration/TypeScript.json create mode 100644 Source/Configuration/esbuild.ts create mode 100644 Source/Index.ts create mode 100644 Source/Library/JSON.ts create mode 100644 Target/Bin.d.ts create mode 100644 Target/Bin.js create mode 100644 Target/Command/Build.d.ts create mode 100644 Target/Command/Build.js create mode 100644 Target/Configuration/TypeScript.json create mode 100644 Target/Configuration/esbuild.d.ts create mode 100644 Target/Configuration/esbuild.js create mode 100644 Target/Index.d.ts create mode 100644 Target/Index.js create mode 100644 Target/Library/JSON.d.ts create mode 100644 Target/Library/JSON.js create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..4d4096fb --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" + versioning-strategy: increase diff --git a/.github/workflows/Dependabot.yml b/.github/workflows/Dependabot.yml new file mode 100644 index 00000000..43dcedd1 --- /dev/null +++ b/.github/workflows/Dependabot.yml @@ -0,0 +1,43 @@ +name: Dependabot + +concurrency: + group: Dependabot-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + pull-requests: write + +on: + workflow_dispatch: + pull_request: + +jobs: + Approve: + runs-on: ubuntu-latest + + if: ${{ github.actor == 'dependabot[bot]' }} + + steps: + - uses: dependabot/fetch-metadata@v1.6.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + Merge: + runs-on: ubuntu-latest + + if: ${{ github.actor == 'dependabot[bot]' }} + + steps: + - uses: dependabot/fetch-metadata@v1.6.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/NPM.yml b/.github/workflows/NPM.yml new file mode 100644 index 00000000..f8d70f3c --- /dev/null +++ b/.github/workflows/NPM.yml @@ -0,0 +1,41 @@ +name: NPM + +concurrency: + group: NPM-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + security-events: write + contents: write + pull-requests: write + +on: + workflow_dispatch: + release: + types: [created] + workflow_call: + +jobs: + Publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3.5.3 + + - uses: actions/setup-node@v3.7.0 + with: + node-version: "18" + registry-url: "https://registry.npmjs.org" + + - run: npm install -g npm + + - name: Publish . + continue-on-error: true + working-directory: . + run: | + npm install --legacy-peer-deps + npm publish --legacy-peer-deps --provenance + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/Node.yml b/.github/workflows/Node.yml new file mode 100644 index 00000000..9eff0814 --- /dev/null +++ b/.github/workflows/Node.yml @@ -0,0 +1,93 @@ +name: Node + +concurrency: + group: Node-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + security-events: write + contents: write + pull-requests: write + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + workflow_call: + +jobs: + Pre-Publish: + runs-on: ubuntu-latest + + env: + ADBLOCK: true + TELEMETRY_DISABLED: 1 + ASTRO_TELEMETRY_DISABLED: 1 + AUTOMATEDLAB_TELEMETRY_OPTOUT: 1 + AZURE_CORE_COLLECT_TELEMETRY: 0 + CHOOSENIM_NO_ANALYTICS: 1 + DIEZ_DO_NOT_TRACK: 1 + DO_NOT_TRACK: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_INTERACTIVE_CLI_TELEMETRY_OPTOUT: 1 + ET_NO_TELEMETRY: 1 + GATSBY_TELEMETRY_DISABLED: 1 + GATSBY_TELEMETRY_OPT_OUT: 1 + GATSBY_TELEMETRY_OPTOUT: 1 + HASURA_GRAPHQL_ENABLE_TELEMETRY: false + HINT_TELEMETRY: off + HOMEBREW_NO_ANALYTICS: 1 + INFLUXD_REPORTING_DISABLED: true + ITERATIVE_DO_NOT_TRACK: 1 + NEXT_TELEMETRY_DEBUG: 1 + NEXT_TELEMETRY_DISABLED: 1 + NG_CLI_ANALYTICS: false + NUXT_TELEMETRY_DISABLED: 1 + PIN_DO_NOT_TRACK: 1 + POWERSHELL_TELEMETRY_OPTOUT: 1 + SAM_CLI_TELEMETRY: 0 + STNOUPGRADE: 1 + STRIPE_CLI_TELEMETRY_OPTOUT: 1 + + strategy: + matrix: + node-version: [16, 18, 19] + + steps: + - uses: actions/checkout@v3.5.3 + + - uses: pnpm/action-setup@v2.4.0 + with: + version: 8.6.12 + run_install: | + - recursive: true + args: [ + --child-concurrency=9999, + --link-workspace-packages=true, + --lockfile-only, + --network-concurrency=9999, + --prefer-frozen-lockfile=false, + --shamefully-hoist=false, + --shared-workspace-lockfile=true, + --strict-peer-dependencies=false, + --unsafe-perm=true + ] + + - uses: actions/setup-node@v3.7.0 + with: + node-version: ${{ matrix.node-version }} + cache: "pnpm" + cache-dependency-path: ./pnpm-lock.yaml + + - run: pnpm install + working-directory: . + + - run: pnpm run prepublishOnly + working-directory: . + + - uses: actions/upload-artifact@v3.1.2 + with: + name: .-Node-${{ matrix.node-version }}-Target + path: ./Target diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..83feba61 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,64 @@ +name: "CodeQL" + +concurrency: + group: CodeQL-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + security-events: write + contents: write + pull-requests: write + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + workflow_call: + +jobs: + CodeQL: + runs-on: ubuntu-latest + + env: + ADBLOCK: true + TELEMETRY_DISABLED: 1 + ASTRO_TELEMETRY_DISABLED: 1 + AUTOMATEDLAB_TELEMETRY_OPTOUT: 1 + AZURE_CORE_COLLECT_TELEMETRY: 0 + CHOOSENIM_NO_ANALYTICS: 1 + DIEZ_DO_NOT_TRACK: 1 + DO_NOT_TRACK: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_INTERACTIVE_CLI_TELEMETRY_OPTOUT: 1 + ET_NO_TELEMETRY: 1 + GATSBY_TELEMETRY_DISABLED: 1 + GATSBY_TELEMETRY_OPT_OUT: 1 + GATSBY_TELEMETRY_OPTOUT: 1 + HASURA_GRAPHQL_ENABLE_TELEMETRY: false + HINT_TELEMETRY: off + HOMEBREW_NO_ANALYTICS: 1 + INFLUXD_REPORTING_DISABLED: true + ITERATIVE_DO_NOT_TRACK: 1 + NEXT_TELEMETRY_DEBUG: 1 + NEXT_TELEMETRY_DISABLED: 1 + NG_CLI_ANALYTICS: false + NUXT_TELEMETRY_DISABLED: 1 + PIN_DO_NOT_TRACK: 1 + POWERSHELL_TELEMETRY_OPTOUT: 1 + SAM_CLI_TELEMETRY: 0 + STNOUPGRADE: 1 + STRIPE_CLI_TELEMETRY_OPTOUT: 1 + + steps: + - uses: actions/checkout@v3.5.3 + + - uses: github/codeql-action/init@v2.21.2 + with: + languages: javascript + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2.21.2 + with: + category: "/language:javascript" diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c72a4fc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.turbo diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..1244cda2 --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.github/ +.turbo/ +Source/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..84fcad91 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +## 0.0.2 + +- Cleanup + +## 0.0.1 + +- Initial version diff --git a/Source/Bin.ts b/Source/Bin.ts new file mode 100644 index 00000000..f401b045 --- /dev/null +++ b/Source/Bin.ts @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +import "./Index.js"; diff --git a/Source/Command/Build.ts b/Source/Command/Build.ts new file mode 100644 index 00000000..6b6852d8 --- /dev/null +++ b/Source/Command/Build.ts @@ -0,0 +1,43 @@ +import { exec as Exec } from "child_process"; +import { deepmerge as Merge } from "deepmerge-ts"; +import type { BuildOptions } from "esbuild"; +import { build as Build } from "esbuild"; +import type { Pattern } from "fast-glob"; +import Glob from "fast-glob"; +import esbuild from "../Configuration/esbuild.js"; + +export type Pipe = string[]; + +export default async (Files: Pattern[], Options?: { TypeScript?: string }) => { + const Pipe: Pipe = []; + + for (const File of Files) { + for (const _File of await Glob( + File.replaceAll("'", "").replaceAll('"', "") + )) { + Pipe.push(_File); + } + } + + Pipe.reverse(); + + await Build( + Merge(esbuild, { + entryPoints: Object.fromEntries( + Pipe.map((File) => [ + File.replace("Source/", "") + .split(".") + .slice(0, -1.0) + .join("."), + File, + ]) + ), + } satisfies BuildOptions) + ); + + if (Options?.TypeScript) { + Exec(`tsc -p ${Options?.TypeScript}`); + } else { + Exec("tsc"); + } +}; diff --git a/Source/Configuration/TypeScript.json b/Source/Configuration/TypeScript.json new file mode 100644 index 00000000..358d9833 --- /dev/null +++ b/Source/Configuration/TypeScript.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "allowArbitraryExtensions": true, + "allowImportingTsExtensions": true, + "allowJs": true, + "allowSyntheticDefaultImports": true, + "allowUmdGlobalAccess": false, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "alwaysStrict": true, + "assumeChangesOnlyAffectDirectDependencies": true, + "baseUrl": "./", + "checkJs": true, + "declaration": true, + "disableReferencedProjectLoad": false, + "emitDeclarationOnly": true, + "esModuleInterop": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "jsx": "preserve", + "lib": [ + "ESNext" + ], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "strictBindCallApply": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "target": "ESNext", + "types": [ + "node" + ], + "verbatimModuleSyntax": true + }, + "ts-node": { + "esm": true + } +} diff --git a/Source/Configuration/esbuild.ts b/Source/Configuration/esbuild.ts new file mode 100644 index 00000000..b1481607 --- /dev/null +++ b/Source/Configuration/esbuild.ts @@ -0,0 +1,39 @@ +import type { BuildOptions, PluginBuild } from "esbuild"; +import { rm as Remove } from "fs/promises"; +import { copy as Copy } from "esbuild-plugin-copy"; + +const Out = "Target"; + +export default { + format: "esm", + minify: true, + outdir: Out, + platform: "node", + target: "esnext", + write: true, + plugins: [ + { + name: "Target", + setup(build: PluginBuild) { + build.onStart(async () => { + try { + await Remove(Out, { + recursive: true, + }); + } catch (_Error) { + console.log(_Error); + } + }); + }, + }, + Copy({ + resolveFrom: "out", + assets: [ + { + from: "./Source/Configuration/TypeScript.json", + to: "./Configuration/", + }, + ], + }), + ], +} satisfies BuildOptions; diff --git a/Source/Index.ts b/Source/Index.ts new file mode 100644 index 00000000..bdc2bcf7 --- /dev/null +++ b/Source/Index.ts @@ -0,0 +1,18 @@ +import { Command } from "commander"; +import Build from "./Command/Build.js"; +import _JSON from "./Library/JSON.js"; + +try { + const { version } = await _JSON("../package.json", import.meta.url); + + new Command() + .name("baxast") + .version(version) + .description("Builds files") + .argument("", "Files to build") + .option("-ts, --TypeScript ", "TypeScript configuration file") + .action(Build) + .parse(); +} catch (_Error) { + console.log(_Error); +} diff --git a/Source/Library/JSON.ts b/Source/Library/JSON.ts new file mode 100644 index 00000000..0b31dd5f --- /dev/null +++ b/Source/Library/JSON.ts @@ -0,0 +1,13 @@ +import { readFile as _File } from "fs/promises"; +import { dirname as Dir } from "path"; +import { fileURLToPath as Path } from "url"; + +export default async (File: string, From: string = import.meta.url) => + JSON.parse( + ( + await _File( + `${Dir(Path(From ?? import.meta.url))}/${File}`, + "utf-8" + ) + ).toString() + ); diff --git a/Target/Bin.d.ts b/Target/Bin.d.ts new file mode 100644 index 00000000..87be97ad --- /dev/null +++ b/Target/Bin.d.ts @@ -0,0 +1,2 @@ +#!/usr/bin/env node +import "./Index.js"; diff --git a/Target/Bin.js b/Target/Bin.js new file mode 100644 index 00000000..e6efb466 --- /dev/null +++ b/Target/Bin.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +import"./Index.js"; diff --git a/Target/Command/Build.d.ts b/Target/Command/Build.d.ts new file mode 100644 index 00000000..a7755216 --- /dev/null +++ b/Target/Command/Build.d.ts @@ -0,0 +1,6 @@ +import type { Pattern } from "fast-glob"; +export type Pipe = string[]; +declare const _default: (Files: Pattern[], Options?: { + TypeScript?: string; +}) => Promise; +export default _default; diff --git a/Target/Command/Build.js b/Target/Command/Build.js new file mode 100644 index 00000000..439eb7cf --- /dev/null +++ b/Target/Command/Build.js @@ -0,0 +1 @@ +import{exec as i}from"child_process";import{deepmerge as s}from"deepmerge-ts";import{build as l}from"esbuild";import a from"fast-glob";import c from"../Configuration/esbuild.js";var y=async(o,r)=>{const t=[];for(const e of o)for(const p of await a(e.replaceAll("'","").replaceAll('"',"")))t.push(p);t.reverse(),await l(s(c,{entryPoints:Object.fromEntries(t.map(e=>[e.replace("Source/","").split(".").slice(0,-1).join("."),e]))})),r?.TypeScript?i(`tsc -p ${r?.TypeScript}`):i("tsc")};export{y as default}; diff --git a/Target/Configuration/TypeScript.json b/Target/Configuration/TypeScript.json new file mode 100644 index 00000000..358d9833 --- /dev/null +++ b/Target/Configuration/TypeScript.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "allowArbitraryExtensions": true, + "allowImportingTsExtensions": true, + "allowJs": true, + "allowSyntheticDefaultImports": true, + "allowUmdGlobalAccess": false, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "alwaysStrict": true, + "assumeChangesOnlyAffectDirectDependencies": true, + "baseUrl": "./", + "checkJs": true, + "declaration": true, + "disableReferencedProjectLoad": false, + "emitDeclarationOnly": true, + "esModuleInterop": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "jsx": "preserve", + "lib": [ + "ESNext" + ], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "strictBindCallApply": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "target": "ESNext", + "types": [ + "node" + ], + "verbatimModuleSyntax": true + }, + "ts-node": { + "esm": true + } +} diff --git a/Target/Configuration/esbuild.d.ts b/Target/Configuration/esbuild.d.ts new file mode 100644 index 00000000..702ca568 --- /dev/null +++ b/Target/Configuration/esbuild.d.ts @@ -0,0 +1,10 @@ +declare const _default: { + format: "esm"; + minify: true; + outdir: string; + platform: "node"; + target: string; + write: true; + plugins: any[]; +}; +export default _default; diff --git a/Target/Configuration/esbuild.js b/Target/Configuration/esbuild.js new file mode 100644 index 00000000..dafdee0a --- /dev/null +++ b/Target/Configuration/esbuild.js @@ -0,0 +1 @@ +import{rm as e}from"fs/promises";import{copy as i}from"esbuild-plugin-copy";const t="Target";var a={format:"esm",minify:!0,outdir:t,platform:"node",target:"esnext",write:!0,plugins:[{name:"Target",setup(o){o.onStart(async()=>{try{await e(t,{recursive:!0})}catch(r){console.log(r)}})}},i({resolveFrom:"out",assets:[{from:"./Source/Configuration/TypeScript.json",to:"./Configuration/"}]})]};export{a as default}; diff --git a/Target/Index.d.ts b/Target/Index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/Target/Index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/Target/Index.js b/Target/Index.js new file mode 100644 index 00000000..b958a361 --- /dev/null +++ b/Target/Index.js @@ -0,0 +1 @@ +import{Command as o}from"commander";import r from"./Command/Build.js";import t from"./Library/JSON.js";try{const{version:i}=await t("../package.json",import.meta.url);new o().name("baxast").version(i).description("Builds files").argument("","Files to build").option("-ts, --TypeScript ","TypeScript configuration file").action(r).parse()}catch(i){console.log(i)} diff --git a/Target/Library/JSON.d.ts b/Target/Library/JSON.d.ts new file mode 100644 index 00000000..dbbd59fc --- /dev/null +++ b/Target/Library/JSON.d.ts @@ -0,0 +1,2 @@ +declare const _default: (File: string, From?: string) => Promise; +export default _default; diff --git a/Target/Library/JSON.js b/Target/Library/JSON.js new file mode 100644 index 00000000..fb981427 --- /dev/null +++ b/Target/Library/JSON.js @@ -0,0 +1 @@ +import{readFile as a}from"fs/promises";import{dirname as i}from"path";import{fileURLToPath as m}from"url";var s=async(r,t=import.meta.url)=>JSON.parse((await a(`${i(m(t??import.meta.url))}/${r}`,"utf-8")).toString());export{s as default}; diff --git a/package.json b/package.json new file mode 100644 index 00000000..52e3c03d --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "baxast", + "version": "0.0.2", + "type": "module", + "main": "./Target/Index.js", + "types": "./Target/Index.d.ts", + "bin": { + "baxast": "./Target/Bin.js" + }, + "scripts": { + "prepublishOnly": "node --no-warnings --loader ts-node/esm Source/Index.ts 'Source/**/*.ts'" + }, + "dependencies": { + "commander": "11.0.0", + "deepmerge-ts": "5.1.0", + "esbuild": "0.18.19", + "esbuild-plugin-copy": "2.1.1", + "fast-glob": "3.3.1", + "typescript": "5.1.6" + }, + "devDependencies": { + "@types/node": "20.4.8", + "ts-node": "10.9.1" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..ee1d5c80 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "outDir": "Target" + }, + "extends": "./Source/Configuration/TypeScript", + "include": ["Source"] +}