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

feat(create-waku): bundle into single file #330

Merged
merged 19 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,28 @@ jobs:
- run: pnpm install --frozen-lockfile
- run: pnpm test

build-create-waku:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm -r --filter="./packages/create-waku" run compile
- uses: actions/upload-artifact@v4
with:
name: create-waku
path: packages/create-waku
if-no-files-found: error

e2e:
name: E2E on ${{ matrix.os }} (Node ${{ matrix.version }}) - (${{ matrix.shared }}/4)
needs:
- build-create-waku
strategy:
fail-fast: false
matrix:
Expand All @@ -41,6 +61,10 @@ jobs:
node-version: ${{ matrix.version }}
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- uses: actions/download-artifact@v4
with:
name: create-waku
path: packages/create-waku
- run: pnpm install --frozen-lockfile
- run: pnpm run compile
- name: Cache Playwright
Expand Down
46 changes: 46 additions & 0 deletions e2e/create-waku.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import crypto from 'node:crypto';
import { mkdir, readdir } from 'node:fs/promises';
import { test, debugChildProcess } from './utils.js';
import { expect } from '@playwright/test';

test('should create waku with default setup work', async () => {
const cliPath = fileURLToPath(
new URL('../packages/create-waku/dist/index.js', import.meta.url),
);

const dirname = crypto.randomUUID();
await mkdir(new URL(`./.cache/${dirname}/`, import.meta.url), {
recursive: true,
});
const cwd = fileURLToPath(new URL(`./.cache/${dirname}`, import.meta.url));
const cp = spawn(process.execPath, [cliPath], {
cwd,
env: process.env,
});
debugChildProcess(cp);
const stdin = cp.stdin!;
await new Promise<void>((resolve) => {
cp.stdout!.on('data', (data) => {
const str = data.toString();
if (str.includes('Project Name')) {
stdin.write('\n'); // use default
} else if (str.includes('Choose a starter template')) {
stdin.write('\n'); // use default
}
if (str.includes('Done.')) {
resolve();
}
});
});
const paths = await readdir(cwd);
expect(paths[0]).toBe('waku-project');
expect(paths.length).toBe(1);
const files = await readdir(
new URL(`./.cache/${dirname}/waku-project`, import.meta.url),
);
expect(files).toContain('package.json');
expect(files).toContain('src');
expect(files).toContain('tsconfig.json');
});
17 changes: 8 additions & 9 deletions packages/create-waku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
"directory": "packages/create-waku"
},
"bin": {
"create-waku": "./dist/cli.js"
"create-waku": "./dist/index.js"
},
"files": [
"src",
"dist",
"template"
],
"scripts": {
"start": "node dist/cli.js",
"start": "node ./dist/index.js",
"dev": "ncc build ./src/index.ts -w -o ./dist/",
"compile": "rm -rf template dist *.tsbuildinfo && pnpm run template && pnpm run build",
"template": "cp -r ../../examples template/ && rm -rf template/*/dist && rm -rf template/*/node_modules",
"build": "tsc -b"
"build": "ncc build ./src/index.ts -o ./dist/ --minify --no-cache --no-source-map-register"
},
"dependencies": {
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/prompts": "^2.4.9",
"@vercel/ncc": "^0.38.1",
"fs-extra": "^11.2.0",
"kolorist": "^1.8.0",
"prompts": "^2.4.2"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/prompts": "^2.4.9"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env node

import { existsSync, readdirSync } from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import path, { dirname } from 'node:path';
himself65 marked this conversation as resolved.
Show resolved Hide resolved
import { default as prompts } from 'prompts';
import { red, green, bold } from 'kolorist';
import fse from 'fs-extra/esm';
import { fileURLToPath } from 'node:url';
himself65 marked this conversation as resolved.
Show resolved Hide resolved

function isValidPackageName(projectName: string) {
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
Expand All @@ -31,9 +30,12 @@ function canSafelyOverwrite(dir: string) {
async function init() {
let targetDir = '';
const defaultProjectName = 'waku-project';

const templateRoot = fileURLToPath(new URL('../template', import.meta.url));
const CHOICES = await fsPromises.readdir(templateRoot);
const __dirname = dirname(fileURLToPath(import.meta.url));
const templateRoot = path.resolve(__dirname, '../template');
himself65 marked this conversation as resolved.
Show resolved Hide resolved
// maybe include `.DS_Store` on macOS
const CHOICES = (await fsPromises.readdir(templateRoot)).filter(
(dir) => !dir.startsWith('.'),
);
let result: {
packageName: string;
shouldOverwrite: string;
Expand Down
36 changes: 22 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading