Skip to content

Commit

Permalink
build: allow running in dev mode without recompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
lgandecki committed Aug 21, 2023
1 parent 9d37e6d commit a7cdf4e
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 15 deletions.
17 changes: 17 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

require('ts-node').register({project})

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
"devDependencies": {
"@oclif/test": "^2.4.2",
"@types/chai": "^4",
"@types/debug": "^4.1.8",
"@types/find-package-json": "^1.2.3",
"@types/jest": "^29.5.3",
"@types/node": "^20.5.0",
"@types/shelljs": "^0.8.12",
"axios": "^1.4.0",
"chai": "^4.2.0",
"copyfiles": "^2.4.1",
Expand All @@ -48,7 +51,7 @@
"testdouble-jest": "^2.0.0",
"ts-jest": "29.1.1",
"ts-node": "^8",
"typescript": "4.4.4",
"typescript": "5.1.6",
"wait-on": "^5.2.1"
},
"engines": {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ const fixGenerated = async (projectMainPath: string) => {
};

const prettifyGenerated = async (projectMainPath: string, modulesPath = 'src') => {
await execQuietly(`npx prettier --write "${modulesPath}/**/*.ts" "generated/**/*.ts" --log-level error`, {
cwd: projectMainPath,
});
await execQuietly(
`npx prettier --ignore-path /dev/null --write "${modulesPath}/**/*.ts" "generated/**/*.ts" --log-level error`,
{
cwd: projectMainPath,
},
);
};

export default class Generate extends Command {
Expand Down
2 changes: 1 addition & 1 deletion src/generate/generate-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import getUnions from './parse-graphql/getUnions';
const debug = configureDebug('generate-module');

const generateSchema = async (projectMainPath: string) => {
await execQuietly(`ts-node -r tsconfig-paths/register ./generated/graphql/printSchema.ts`, {
await execQuietly(`npx ts-node -r tsconfig-paths/register ./generated/graphql/printSchema.ts`, {
cwd: projectMainPath,
});
};
Expand Down
6 changes: 3 additions & 3 deletions src/generate/helpers/execQuietly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export async function execQuietly(command: string, options: Record<string, unkno
let stdoutData = '';
let stderrData = '';

child.stdout.on('data', (data: string) => {
child.stdout!.on('data', (data: string) => {
stdoutData += data;
});

child.stderr.on('data', (data: string) => {
child.stderr!.on('data', (data: string) => {
stderrData += data;
});

Expand All @@ -24,7 +24,7 @@ export async function execQuietly(command: string, options: Record<string, unkno
if (code === 0) {
resolve(stdoutData);
} else {
reject(new Error(`${stdoutData} ${errorMessage}: ${stderrData}`));
reject(new Error(`${stdoutData} ${errorMessage}: ${stderrData} ${command}`));
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/generate/helpers/findProjectMainPath.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import finder from 'find-package-json';

export function findProjectMainPath() {
const f = finder(process.cwd());
const f = finder(process.cwd()) as any;
return f
.next()
.filename.split('/')
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/get-chimp-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export const getChimpVersion = () => {
const f = finder(__dirname);
const packageJson = f.next();

return packageJson.value.version;
return packageJson!.value!.version;
};
37 changes: 32 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1295,12 +1295,26 @@
dependencies:
"@types/node" "*"

"@types/debug@^4.1.8":
version "4.1.8"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.8.tgz#cef723a5d0a90990313faec2d1e22aee5eecb317"
integrity sha512-/vPO1EPOs306Cvhwv7KfVfYvOJqA/S/AXjaHQiJboCZzcNDb+TIJFN9/2C9DZ//ijSKWioNyUxD792QmDJ+HKQ==
dependencies:
"@types/ms" "*"

"@types/expect@^1.20.4":
version "1.20.4"
resolved "https://registry.yarnpkg.com/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5"
integrity sha512-Q5Vn3yjTDyCMV50TB6VRIbQNxSE4OmZR86VSbGaNpfUolm0iePBB4KdEEHmxoY5sT2+2DIvXW0rvMDP2nHZ4Mg==

"@types/glob@^7.1.1":
"@types/find-package-json@^1.2.3":
version "1.2.3"
resolved "https://registry.yarnpkg.com/@types/find-package-json/-/find-package-json-1.2.3.tgz#45482a72eb8a21fcc330adff774fb9c7971e6ced"
integrity sha512-UCmxThB05dWlToG6ekGbW3iJLUzd7Z2uGP7R+d1ktlgOttxRGgqQcIeIaCT4pLlO2WkPg9bebqBhs4Epw4Bs8Q==
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1", "@types/glob@~7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==
Expand Down Expand Up @@ -1374,6 +1388,11 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==

"@types/ms@*":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==

"@types/node@*":
version "20.4.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.4.8.tgz#b5dda19adaa473a9bf0ab5cbd8f30ec7d43f5c85"
Expand Down Expand Up @@ -1401,6 +1420,14 @@
dependencies:
"@types/node" "*"

"@types/shelljs@^0.8.12":
version "0.8.12"
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.12.tgz#79dc9632af7d5ca1b5afb65a6bfc1422d79b5fa0"
integrity sha512-ZA8U81/gldY+rR5zl/7HSHrG2KDfEb3lzG6uCUDhW1DTQE9yC/VBQ45fXnXq8f3CgInfhZmjtdu/WOUlrXRQUg==
dependencies:
"@types/glob" "~7.2.0"
"@types/node" "*"

"@types/sinon@*":
version "10.0.16"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.16.tgz#4bf10313bd9aa8eef1e50ec9f4decd3dd455b4d3"
Expand Down Expand Up @@ -6768,10 +6795,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@4.4.4:
version "4.4.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==
typescript@5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

uglify-js@^3.1.4:
version "3.17.4"
Expand Down

0 comments on commit a7cdf4e

Please sign in to comment.