From 3d9f858b2b060a35faaeea643e122d736525b1ce Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 5 Aug 2023 12:48:25 -0400 Subject: [PATCH 1/3] Add a node-support package for dealing with the git stuff --- apps/repl/config/environment.js | 18 ++-------- apps/repl/package.json | 1 + packages/app-support/node/.eslintignore | 7 ++++ packages/app-support/node/.eslintrc.cjs | 10 ++++++ packages/app-support/node/.prettierignore | 13 +++++++ packages/app-support/node/.prettierrc.cjs | 35 ++++++++++++++++++ packages/app-support/node/package.json | 41 +++++++++++++++++++++ packages/app-support/node/src/git.cjs | 34 ++++++++++++++++++ pnpm-lock.yaml | 43 +++++++++++++++++------ 9 files changed, 176 insertions(+), 26 deletions(-) create mode 100644 packages/app-support/node/.eslintignore create mode 100644 packages/app-support/node/.eslintrc.cjs create mode 100644 packages/app-support/node/.prettierignore create mode 100644 packages/app-support/node/.prettierrc.cjs create mode 100644 packages/app-support/node/package.json create mode 100644 packages/app-support/node/src/git.cjs diff --git a/apps/repl/config/environment.js b/apps/repl/config/environment.js index 690329124..df7a298b2 100644 --- a/apps/repl/config/environment.js +++ b/apps/repl/config/environment.js @@ -1,20 +1,6 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); - -function ref() { - const rev = fs.readFileSync(path.join(__dirname, '../../../.git/HEAD')).toString().trim(); - - if (rev.indexOf(':') === -1) { - return rev; - } else { - return fs - .readFileSync(path.join(__dirname, '../../../.git/' + rev.substring(5))) - .toString() - .trim(); - } -} +const { refAbbr } = require('@glimdown/app-node-support/git'); module.exports = function (environment) { let ENV = { @@ -34,7 +20,7 @@ module.exports = function (environment) { }, APP: { - version: `REPL :: ${ref()} :: ${new Date()}`, + version: `REPL :: ${refAbbr()} :: ${new Date()}`, // Here you can pass flags/options to your application instance // when it is created }, diff --git a/apps/repl/package.json b/apps/repl/package.json index f06ab56a3..d89165885 100644 --- a/apps/repl/package.json +++ b/apps/repl/package.json @@ -58,6 +58,7 @@ "@glint/environment-ember-loose": "^1.0.2", "@glint/environment-ember-template-imports": "^1.0.2", "@glint/template": "^1.0.2", + "@glimdown/app-node-support": "workspace:*", "@nullvoxpopuli/eslint-configs": "^3.2.0", "@nullvoxpopuli/limber-untyped": "workspace:^0.0.0", "@types/babel__core": "^7.20.1", diff --git a/packages/app-support/node/.eslintignore b/packages/app-support/node/.eslintignore new file mode 100644 index 000000000..e99befd13 --- /dev/null +++ b/packages/app-support/node/.eslintignore @@ -0,0 +1,7 @@ +dist/ +node_modules/ +tmp/ +vendor/ +public/ +coverage/ +*.ember-try diff --git a/packages/app-support/node/.eslintrc.cjs b/packages/app-support/node/.eslintrc.cjs new file mode 100644 index 000000000..dba2f3b5c --- /dev/null +++ b/packages/app-support/node/.eslintrc.cjs @@ -0,0 +1,10 @@ +'use strict'; + +const { configs } = require('@nullvoxpopuli/eslint-configs'); + +const config = configs.node(); + +module.exports = { + ...config, + overrides: [...config.overrides], +}; diff --git a/packages/app-support/node/.prettierignore b/packages/app-support/node/.prettierignore new file mode 100644 index 000000000..2c2166f4b --- /dev/null +++ b/packages/app-support/node/.prettierignore @@ -0,0 +1,13 @@ +*.yml +*.yaml +*.md +*.json +renovate.json5 +docs/ + +node_modules/ +dist/ +public/ +vendor/ +coverage/ +.lint-todo/ diff --git a/packages/app-support/node/.prettierrc.cjs b/packages/app-support/node/.prettierrc.cjs new file mode 100644 index 000000000..4a70f1981 --- /dev/null +++ b/packages/app-support/node/.prettierrc.cjs @@ -0,0 +1,35 @@ +'use strict'; + +module.exports = { + printWidth: 100, + overrides: [ + { + // Lol, JavaScript + files: ['*.js', '*.ts', '*.cjs', '.mjs', '.cts', '.mts', '.cts'], + options: { + singleQuote: true, + trailingComma: 'es5', + }, + }, + { + files: ['*.json'], + options: { + singleQuote: false, + }, + }, + { + files: ['**/*.hbs'], + options: { + singleQuote: false, + }, + }, + { + files: ['**/*.gjs', '**/*.gts'], + options: { + singleQuote: true, + trailingComma: 'es5', + }, + plugins: ['prettier-plugin-ember-template-tag'], + }, + ], +}; diff --git a/packages/app-support/node/package.json b/packages/app-support/node/package.json new file mode 100644 index 000000000..ef05e90b2 --- /dev/null +++ b/packages/app-support/node/package.json @@ -0,0 +1,41 @@ +{ + "name": "@glimdown/app-node-support", + "private": true, + "type": "module", + "license": "MIT", + "author": "NullVoxPopuli", + "exports": { + "./git": "./src/git.cjs" + }, + "scripts": { + "lint:fix": "pnpm -w exec lint fix", + "build": "tailwindcss -o dist/tailwind.css", + "start": "tailwindcss -o dist/tailwind.css --watch", + "lint": "pnpm -w exec lint", + "lint:js": "pnpm -w exec lint js", + "lint:js:fix": "pnpm -w exec lint js:fix", + "lint:prettier:fix": "pnpm -w exec lint prettier:fix", + "lint:prettier": "pnpm -w exec lint prettier" + }, + "devDependencies": { + "@babel/core": "^7.22.9", + "@nullvoxpopuli/eslint-configs": "^3.2.0", + "concurrently": "^8.2.0", + "eslint": "^8.45.0", + "prettier": "^2.8.8", + "prettier-plugin-ember-template-tag": "^1.0.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/NullVoxPopuli/limber.git", + "directory": "packages/app-support/node" + }, + "engines": { + "node": ">= v16", + "npm": "use pnpm", + "yarn": "use pnpm" + }, + "volta": { + "extends": "../../../package.json" + } +} diff --git a/packages/app-support/node/src/git.cjs b/packages/app-support/node/src/git.cjs new file mode 100644 index 000000000..b72778e2e --- /dev/null +++ b/packages/app-support/node/src/git.cjs @@ -0,0 +1,34 @@ +const { spawnSync } = require('child_process'); + +function currentCommitSHA() { + const result = spawnSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf-8' }); + + if (result.error) { + throw result.error; + } + + if (result.status !== 0) { + throw new Error(`Git command failed with status ${result.status}: ${result.stderr}`); + } + + return result.stdout.trim(); +} +function currentGitBranch() { + const result = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf-8' }); + + if (result.error) { + throw result.error; + } + + if (result.status !== 0) { + throw new Error(`Git command failed with status ${result.status}: ${result.stderr}`); + } + + return result.stdout.trim(); +} + +function refAbbr() { + return `${currentGitBranch()} :: ${currentCommitSHA()}`; +} + +module.exports = { currentCommitSHA, currentGitBranch, refAbbr }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2ebde1974..f6090fd7a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -244,6 +244,9 @@ importers: '@fortawesome/free-solid-svg-icons': specifier: ^6.4.2 version: 6.4.2 + '@glimdown/app-node-support': + specifier: workspace:* + version: link:../../packages/app-support/node '@glint/core': specifier: ^1.0.2 version: 1.0.2(typescript@5.1.6) @@ -1120,6 +1123,27 @@ importers: specifier: ^5.88.2 version: 5.88.2 + packages/app-support/node: + devDependencies: + '@babel/core': + specifier: ^7.22.9 + version: 7.22.9(supports-color@8.1.1) + '@nullvoxpopuli/eslint-configs': + specifier: ^3.1.3 + version: 3.1.3(@babel/core@7.22.9)(eslint@8.45.0)(prettier@2.8.8) + concurrently: + specifier: ^8.2.0 + version: 8.2.0 + eslint: + specifier: ^8.45.0 + version: 8.45.0 + prettier: + specifier: ^2.8.8 + version: 2.8.8 + prettier-plugin-ember-template-tag: + specifier: ^1.0.0 + version: 1.0.0(prettier@2.8.8) + packages/app-support/styles: dependencies: '@tailwindcss/typography': @@ -2625,7 +2649,7 @@ packages: '@babel/helper-plugin-utils': 7.22.5 debug: 4.3.4(supports-color@8.1.1) lodash.debounce: 4.0.8 - resolve: 1.22.2 + resolve: 1.22.3 transitivePeerDependencies: - supports-color @@ -8110,7 +8134,7 @@ packages: dependencies: '@babel/runtime': 7.22.6 cosmiconfig: 6.0.0 - resolve: 1.22.2 + resolve: 1.22.3 dev: false /babel-plugin-module-resolver@3.2.0: @@ -9097,7 +9121,7 @@ packages: ensure-posix-path: 1.1.1 fs-extra: 8.1.0 minimatch: 3.1.2 - resolve: 1.22.2 + resolve: 1.22.3 rsvp: 4.8.5 symlink-or-copy: 1.3.1 walk-sync: 1.1.4 @@ -12320,7 +12344,7 @@ packages: dependencies: debug: 3.2.7 is-core-module: 2.12.1 - resolve: 1.22.2 + resolve: 1.22.3 transitivePeerDependencies: - supports-color dev: true @@ -12602,7 +12626,7 @@ packages: ignore: 5.2.4 is-core-module: 2.12.1 minimatch: 3.1.2 - resolve: 1.22.2 + resolve: 1.22.3 semver: 7.5.4 dev: true @@ -12798,7 +12822,7 @@ packages: dependencies: acorn: 8.10.0 acorn-walk: 8.2.0 - resolve: 1.22.2 + resolve: 1.22.3 serve-static: 1.15.0 transitivePeerDependencies: - supports-color @@ -16829,7 +16853,7 @@ packages: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} dependencies: hosted-git-info: 2.8.9 - resolve: 1.22.2 + resolve: 1.22.3 semver: 5.7.2 validate-npm-package-license: 3.0.4 dev: true @@ -18542,14 +18566,14 @@ packages: resolution: {integrity: sha512-fVEKHGeK85bGbVFuwO9o1aU0n3vqQGrezPc51JGu9UTXpFQfWq5qCeKxyaRUSvephs+06c5j5rPq/dzHGEo8+Q==} dependencies: path-root: 0.1.1 - resolve: 1.22.2 + resolve: 1.22.3 /resolve-package-path@2.0.0: resolution: {integrity: sha512-/CLuzodHO2wyyHTzls5Qr+EFeG6RcW4u6//gjYvUfcfyuplIX1SSccU+A5A9A78Gmezkl3NBkFAMxLbzTY9TJA==} engines: {node: 8.* || 10.* || >= 12} dependencies: path-root: 0.1.1 - resolve: 1.22.2 + resolve: 1.22.3 /resolve-package-path@3.1.0: resolution: {integrity: sha512-2oC2EjWbMJwvSN6Z7DbDfJMnD8MYEouaLn5eIX0j8XwPsYCVIyY9bbnX88YHVkbr8XHqvZrYbxaLPibfTYKZMA==} @@ -18595,7 +18619,6 @@ packages: is-core-module: 2.12.1 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 - dev: true /responselike@1.0.2: resolution: {integrity: sha512-/Fpe5guzJk1gPqdJLJR5u7eG/gNY4nImjbRDaVWVMRhne55TCmj2i9Q+54PBRfatRC8v/rIiv9BN0pMd9OV5EQ==} From c527c98b0d56824580c414ce1df805257220c078 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 5 Aug 2023 15:31:32 -0400 Subject: [PATCH 2/3] Progress, but I need to figure out checking auth status --- apps/repl/app/components/limber/github.gts | 26 ++++++++ apps/repl/app/components/limber/header.gts | 2 + apps/repl/app/routes/application.ts | 7 +++ apps/repl/app/services/editor.ts | 2 + apps/repl/app/utils/auth.ts | 72 ++++++++++++++++++++++ apps/repl/package.json | 3 +- pnpm-lock.yaml | 7 +++ 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 apps/repl/app/components/limber/github.gts create mode 100644 apps/repl/app/utils/auth.ts diff --git a/apps/repl/app/components/limber/github.gts b/apps/repl/app/components/limber/github.gts new file mode 100644 index 000000000..340f57925 --- /dev/null +++ b/apps/repl/app/components/limber/github.gts @@ -0,0 +1,26 @@ +import { on } from '@ember/modifier'; + +import { service } from 'ember-primitives'; + +import type EditorService from 'limber/services/editor'; + +function getAuth(editor: EditorService) { + return editor.auth; +} + +export const GitHubLogin = ; diff --git a/apps/repl/app/components/limber/header.gts b/apps/repl/app/components/limber/header.gts index 77e155f5f..a4e8e9d14 100644 --- a/apps/repl/app/components/limber/header.gts +++ b/apps/repl/app/components/limber/header.gts @@ -2,6 +2,7 @@ import FaIcon from '@fortawesome/ember-fontawesome/components/fa-icon'; import ExternalLink from '../external-link'; import DemoSelect from './demo-select'; +import { GitHubLogin } from './github';