Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI check that builds with latest Expo #19

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ jobs:
run: yarn lint
- name: Run tests
run: yarn test:run
- name: Build with latest Expo
run: node bin/checks/build-with-latest-expo.check.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ npm-debug.log
.vscode/*
.DS_Store
/dist
/builds
35 changes: 35 additions & 0 deletions bin/checks/build-with-latest-expo.check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node
import { execSync } from 'child_process';
import fs from 'fs-extra';

async function runCheck() {
const dir = './builds';

if (process.env.CI) {
execSync('git config --global user.email "[email protected]"', {
stdio: 'inherit',
});
execSync('git config --global user.name "CI User"', { stdio: 'inherit' });
}

// build to /dist
execSync('yarn build', { stdio: 'inherit' });

// clean /builds, cd into it
fs.rmSync(dir, { recursive: true, force: true });
fs.mkdirSync(dir, { recursive: true });
process.chdir(dir);

// run CLI
execSync('node ../dist/index.js ExpoSample --no-interactive --is-test', {
stdio: 'inherit',
});

process.chdir('./ExpoSample');

// verify linter and tests all pass in new project
const pkgMgr = fs.existsSync('package-lock.json') ? 'npm run' : 'yarn';
execSync(`${pkgMgr} test:all`, { stdio: 'inherit' });
}

void runCheck();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
"ignorePatterns": [
"templates",
"__mocks__/**/*.js",
"bin/belt.js",
"/bin",
"/dist",
"/builds",
"vitest.setup.js"
],
"rules": {
Expand Down
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default function runCli() {
'--no-testing',
'Pass true to skip installing Jest and React Native Testing Library',
)
.option('--is-test', 'Used only by test suite')
.option('--no-interactive', 'Pass true to skip all prompts')
.action(buildAction(import('./commands/createApp')));

program
Expand Down
26 changes: 23 additions & 3 deletions src/commands/createApp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { confirm, input } from '@inquirer/prompts';
import { execSync, spawnSync } from 'child_process';
import { globals } from '../constants';
import addDependency from '../util/addDependency';
import addPackageJsonScripts from '../util/addPackageJsonScripts';
import print from '../util/print';
Expand All @@ -10,13 +11,18 @@ import addTestingLibrary from './testingLibrary';
import addTypescript from './typescript';

type Options = {
testing: boolean;
testing?: boolean;
interactive?: boolean;
isTest?: boolean;
};

export async function createApp(
name: string | undefined,
{ testing }: Options,
{ interactive = true, isTest = false, testing = false }: Options,
) {
globals.interactive = interactive;
globals.isTest = isTest;

const appName = name || (await getAppName());
await printIntro();

Expand All @@ -26,6 +32,11 @@ export async function createApp(

process.chdir(`./${appName}`);

if (isTest) {
// since is inside our git repo, the project git repo is not initialized
execSync('git init');
commit('Initial commit');
}
// add dependencies that every project will use
await addDependency(
[
Expand Down Expand Up @@ -65,6 +76,12 @@ export async function createApp(
}

async function getAppName() {
if (!globals.interactive) {
throw new Error(
'App name not provided and running in non-interactive mode, aborting..',
);
}

return input({ message: 'What is the name of your app?' });
}

Expand Down Expand Up @@ -92,7 +109,10 @@ async function printIntro() {
- Install and configure Jest and Testing Library
`);

if (!(await confirm({ message: 'Ready to proceed?' }))) {
if (
globals.interactive &&
!(await confirm({ message: 'Ready to proceed?' }))
) {
process.exit(0);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/testingLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ export default async function addTestingLibrary() {
});

const mgr = await getPackageManager();
const cmd = mgr === 'npm' ? 'npm run' : mgr;
await addPackageJsonScripts(
{
test: 'jest',
'test:ci': `${mgr} test --maxWorkers=2 --silent --ci`,
'test:cov': `${mgr} test --coverage --coverageDirectory ./.cache/coverage`,
'test:all': `${mgr} lint && ${mgr} test:cov`,
'test:ci': `jest --maxWorkers=2 --silent --ci`,
'test:cov': `jest --coverage --coverageDirectory ./.cache/coverage`,
'test:all': `${cmd} lint && ${cmd} test:cov`,
},
{ overwrite: true },
);
Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import path from 'path';
import { fileURLToPath } from 'url';

export const globals = {
interactive: true,
isTest: false,
};

// TSUP builds files without hierarchy to dist/, so the path is ultimately
// in relation to the dist/ directory. NPM package structure is:
// <root>
Expand Down
1 change: 1 addition & 0 deletions templates/eslint/.eslintrc.js.eta
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
root: true,
extends: [
"@thoughtbot/eslint-config/native",
<% if(it.typescript) { %>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"experimentalSpecifierResolution": "node"
},
"include": ["./**/*.ts"],
"exclude": ["templates/**/*", "./dist"]
"exclude": ["templates", "dist", "builds"]
}
7 changes: 6 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { configDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, 'build/**/*', 'templates/**/*'],
exclude: [
...configDefaults.exclude,
'build/**/*',
'templates/**/*',
'builds/**/*',
],
setupFiles: ['./vitest.setup.js'],
},
});