Skip to content

Commit

Permalink
Run lint on update config
Browse files Browse the repository at this point in the history
  • Loading branch information
geekiam23 committed Aug 8, 2023
1 parent c974078 commit 0dfd5d1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/commands/prettier.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { log } from 'console';
import fs from 'fs-extra';
import path from 'path';
import chalk from 'chalk';
import { fileURLToPath, URL } from 'url';
import chalk from 'chalk';
import * as eta from 'eta';
import isPrettierConfigured from '../util/isPrettierConfigured';
import fs from 'fs-extra';
import addDependency from '../util/addDependency';
import getProjectDir from '../util/getProjectDir';
import isPrettierConfigured from '../util/isPrettierConfigured';
import writeFile from '../util/writeFile';

const dirname = fileURLToPath(new URL('.', import.meta.url));
Expand Down
38 changes: 19 additions & 19 deletions src/commands/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import chalk from "chalk";
import { log } from "console";
import * as eta from "eta";
import fs from "fs-extra";
import path from "path";
import { fileURLToPath, URL } from "url";
import addDependency from "../util/addDependency";
import getProjectDir from "../util/getProjectDir";
import getProjectType from "../util/getProjectType";
import writeFile from "../util/writeFile";
import { log } from 'console';
import path from 'path';
import { fileURLToPath, URL } from 'url';
import chalk from 'chalk';
import * as eta from 'eta';
import fs from 'fs-extra';
import addDependency from '../util/addDependency';
import getProjectDir from '../util/getProjectDir';
import getProjectType from '../util/getProjectType';
import writeFile from '../util/writeFile';

// for manual testing, change this to another name so doesn't conflict
// with project's tsconfig.json
const tsConfig = "tsconfig.json";
const dirname = fileURLToPath(new URL(".", import.meta.url));
const tsConfig = 'tsconfig.json';
const dirname = fileURLToPath(new URL('.', import.meta.url));

export default async function addTypescript() {
const projectDir = await getProjectDir();

if (await fs.exists(path.join(projectDir, tsConfig))) {
log(
chalk.yellow(
"tsconfig.json already exists, exiting.\nIf you would like to perform a fresh TypeScript install, delete this file and rerun the script.\n"
)
'tsconfig.json already exists, exiting.\nIf you would like to perform a fresh TypeScript install, delete this file and rerun the script.\n',
),
);
return;
}

await addDependency("typescript @types/react", { dev: true });
await addDependency('typescript @types/react', { dev: true });

const projectType = await getProjectType();
const template = await fs.readFile(
path.join(dirname, "templates", "tsconfig.json.eta")
path.join(dirname, 'templates', 'tsconfig.json.eta'),
);
const fileContents = eta.render(template.toString(), {
expo: projectType === "expo-bare" || projectType === "expo-managed",
expo: projectType === 'expo-bare' || projectType === 'expo-managed',
});

await writeFile(path.join(projectDir, tsConfig), fileContents, {
Expand All @@ -42,7 +42,7 @@ export default async function addTypescript() {

log(
chalk.green(
"\n🎉 TypeScript successfully configured\nConsider renaming your existing JS files as .ts or .tsx.\n"
)
'\n🎉 TypeScript successfully configured\nConsider renaming your existing JS files as .ts or .tsx.\n',
),
);
}
14 changes: 7 additions & 7 deletions src/util/addDependency.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { exec } from "child_process";
import * as fs from "fs-extra";
import * as path from "path";
import getProjectDir from "./getProjectDir";
import { exec } from 'child_process';
import * as path from 'path';
import * as fs from 'fs-extra';
import getProjectDir from './getProjectDir';

export default async function addDependency(deps: string, { dev = false }) {
const isYarn = await fs.exists(path.join(await getProjectDir(), "yarn.lock"));
const isYarn = await fs.exists(path.join(await getProjectDir(), 'yarn.lock'));

if (isYarn) {
exec(`yarn add ${dev ? "--dev" : ""} ${deps}`);
exec(`yarn add ${dev ? '--dev' : ''} ${deps}`);
} else {
exec(`npm install ${dev ? "--save-dev" : "--save"} ${deps}`);
exec(`npm install ${dev ? '--save-dev' : '--save'} ${deps}`);
}
}
20 changes: 0 additions & 20 deletions src/util/getPackageManager.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/util/getProjectDir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs-extra';
import path from 'path';
import fs from 'fs-extra';

export default async function getProjectDir(
base: string = process.cwd(),
Expand Down
18 changes: 9 additions & 9 deletions src/util/isPrettierConfigured.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fsExtra from "fs-extra";
import path from "path";
import getProjectDir from "./getProjectDir";
import readPackageJson from "./readPackageJson";
import path from 'path';
import fsExtra from 'fs-extra';
import getProjectDir from './getProjectDir';
import readPackageJson from './readPackageJson';

export default async function isPrettierConfigured() {
const packageJson = await readPackageJson();
Expand All @@ -10,19 +10,19 @@ export default async function isPrettierConfigured() {

const hasPrettierConfigInPackageJson = Object.prototype.hasOwnProperty.call(
packageJson,
"prettier"
'prettier',
);
const hasPrettierrcJsFile = await fsExtra.exists(
path.join(projectDir, "prettierrc.js")
path.join(projectDir, 'prettierrc.js'),
);
const hasPrettierrcFile = await fsExtra.exists(
path.join(projectDir, ".prettierrc")
path.join(projectDir, '.prettierrc'),
);
const hasPrettierrcJsonFile = await fsExtra.exists(
path.join(projectDir, ".prettierrc.json")
path.join(projectDir, '.prettierrc.json'),
);
const hasPrettierConfigFile = await fsExtra.exists(
path.join(projectDir, ".prettier.config.js")
path.join(projectDir, '.prettier.config.js'),
);

return (
Expand Down
10 changes: 5 additions & 5 deletions src/util/readPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from "fs-extra";
import path from "path";
import { PackageJson } from "../types";
import getProjectDir from "./getProjectDir";
import path from 'path';
import fs from 'fs-extra';
import { PackageJson } from '../types';
import getProjectDir from './getProjectDir';

export default async function readPackageJson() {
const rootDir = await getProjectDir();
const pkg = await fs.readFile(path.join(rootDir, "package.json"));
const pkg = await fs.readFile(path.join(rootDir, 'package.json'));
return JSON.parse(pkg.toString()) as PackageJson;
}

0 comments on commit 0dfd5d1

Please sign in to comment.