Skip to content

Commit

Permalink
3.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBrahma committed Dec 18, 2023
1 parent 350383c commit 274c62d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .bun-create/ts/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

bun pre-commit
12 changes: 6 additions & 6 deletions .bun-create/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"scripts": {
"start": "bun --watch run src/index.ts",
"build": "rimraf dist && tsc -p ./tsconfig.build.json",
"prepublishOnly": "bun run build"
"prepublishOnly": "bun run build",
"pre-commit": "bun test",
"prepare": "husky install"
},
"keywords": [],
"license": "MIT",
Expand All @@ -22,13 +24,11 @@
"bun-types": "latest",
"lint-staged": "^15.2.0",
"rimraf": "^5.0.5",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"husky": "^8.0.1"
},
"bun-create": {
"start": "bun run dev",
"preinstall": [
"bunx husky-init",
"npx husky add .husky/pre-commit \"npm pre-commit\""
]
"preinstall": []
}
}
Binary file modified bun.lockb
Binary file not shown.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gev",
"type": "module",
"version": "3.0.13",
"version": "3.0.14",
"description": "Sets up templates",
"keywords": [
"generator",
Expand Down Expand Up @@ -49,17 +49,12 @@
"dependencies": {
"chalk": "5.3.0",
"commander": "11.1.0",
"execa": "8.0.1",
"globby": "14.0.0",
"inquirer": "9.1.4",
"latest-version": "^7.0.0",
"semver-compare": "1.0.0"
},
"devDependencies": {
"@types/inquirer": "^9.0.2",
"@types/latest-version": "^4.0.1",
"@types/semver-compare": "^1.0.3",
"bun-plugin-dts": "^0.2.1",
"bun-types": "latest",
"eslint-config-gev": "^3.8.1",
"husky": "^8.0.1",
Expand Down
52 changes: 23 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import path from 'path';
import chalk from 'chalk';
import { Argument, Command } from 'commander';
import { execa } from 'execa';
import inquirer from 'inquirer';
import latestVersion from 'latest-version';
import compareSemver from 'semver-compare';
import {
configData,
Expand All @@ -26,7 +24,7 @@ program
.helpOption('-h, --help', 'Display help for command.') // Just capitalize the first letter of description.
.showHelpAfterError()
.option('-c, --no-check-latest', "Won't check if is using the latest version of gev.")
.option('--config', 'Prompt for configs even after they were already set.')
.option('--config', 'Prompt for configs even if they were already set.')
// https://github.com/tj/commander.js/issues/518#issuecomment-872769249
.addArgument(new Argument('<template>', `The project template.`).choices(getAvailableFlavors())) // Will also print in the usage the possible options
.argument('[projectName]', 'The name of the new project.')
Expand All @@ -44,7 +42,8 @@ program

if (opts.checkLatest) {
console.log('Ensuring latest version');
const latestVer = await latestVersion('gev');
// Can't use latest-version pkg as bun doesn't support its internal `got` packaget yet. Using CLI instead.
const latestVer = Bun.spawnSync(['bunx', 'latest-version-cli', 'gev']).stdout.toString();

if (compareSemver(version, latestVer) === -1) {
console.log(
Expand All @@ -55,42 +54,37 @@ program
)}]. Recalling gev with @latest.\n`,
);

await execa('bunx', [`gev@${latestVer}`, '--no-check-latest', ...process.argv.slice(2)], {
stdio: 'inherit',
}).catch(null); // ignore throw here. It will already be treated in the @latest.
Bun.spawn(['bunx', `gev@${latestVer}`, '--no-check-latest', ...process.argv.slice(2)], {
stdio: ['inherit', 'inherit', 'inherit'],
cwd: pathFromRoot(),
});

return;
}
}

await loadConfigs();
// These are no longer being used atm. TODO use it.
loadConfigs();

const areConfigsSet = !!configData.githubAuthor;
const getUserConfigs = opts.config || !areConfigsSet;

if (getUserConfigs) {
const canReadStdin = process.stdin.isTTY;

if (canReadStdin) {
const input = await inquirer.prompt<{ githubAuthor: string }>([
{
name: 'githubAuthor',
type: 'input',
default: configData.githubAuthor,
message: 'Who is the GitHub Author of this project?',
},
]);

setConfigs(input);
}
if ((opts.config || !areConfigsSet) && process.stdin.isTTY) {
const input = await inquirer.prompt<{ githubAuthor: string }>([
{
name: 'githubAuthor',
type: 'input',
default: configData.githubAuthor,
message: 'Who is the GitHub Author of this project?',
},
]);

setConfigs(input);
}

await execa('bun', ['create', '--no-check-latest', ...process.argv.slice(2)], {
stdio: 'inherit',
}).catch(null); // ignore throw here. It will already be treated in the @latest.
console.log('Setting up template');

await execa('bun', ['create', template, projectPath], {
stdio: 'inherit',
Bun.spawnSync(['bun', 'create', template, projectPath], {
stdio: ['ignore', 'inherit', 'inherit'],
cwd: pathFromRoot(),
});
});
Expand Down
7 changes: 3 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readdirSync, readFileSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { execaCommand, execaSync } from 'execa';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand All @@ -19,14 +18,14 @@ type Config = {

export let configData: Config = {};

export const loadConfigs = async (): Promise<void> => {
let loadedData: string = (await execaCommand('npm get gev')).stdout;
export const loadConfigs = (): void => {
let loadedData: string = Bun.spawnSync(['npm', 'get', 'gev']).stdout.toString();

if (loadedData === 'undefined') loadedData = '{}';
configData = JSON.parse(loadedData) as Config;
};

export const setConfigs = (props: Partial<Config>): void => {
configData = { ...configData, ...props };
execaSync('npm', ['set', 'gev', JSON.stringify(configData)]);
Bun.spawnSync(['npm', 'set', 'gev', JSON.stringify(configData)]);
};

0 comments on commit 274c62d

Please sign in to comment.