Skip to content
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
14 changes: 14 additions & 0 deletions __tests__/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@
it('prompts for the framework if none supplied when target dir is current directory', () => {
fs.mkdirSync(genPath, { recursive: true })
const { stdout } = run(['.'], { cwd: genPath })
expect(stdout).toContain('Select a framework:')

Check failure on line 63 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > prompts for the framework if none supplied when target dir is current directory

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain 'Select a framework:' - Expected + Received - Select a framework: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:63:18

Check failure on line 63 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > prompts for the framework if none supplied when target dir is current directory

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain 'Select a framework:' - Expected + Received - Select a framework: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:63:18
})

it('prompts for the framework if none supplied', () => {
const { stdout } = run([projectName])
expect(stdout).toContain('Select a framework:')

Check failure on line 68 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > prompts for the framework if none supplied

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain 'Select a framework:' - Expected + Received - Select a framework: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:68:18

Check failure on line 68 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > prompts for the framework if none supplied

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain 'Select a framework:' - Expected + Received - Select a framework: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:68:18
})

it('prompts for the framework on not supplying a value for --template', () => {
const { stdout } = run([projectName, '--template'])
expect(stdout).toContain('Select a framework:')

Check failure on line 73 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > prompts for the framework on not supplying a value for --template

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain 'Select a framework:' - Expected + Received - Select a framework: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:73:18

Check failure on line 73 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > prompts for the framework on not supplying a value for --template

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain 'Select a framework:' - Expected + Received - Select a framework: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:73:18
})

it('prompts for the framework on supplying an invalid template', () => {
const { stdout } = run([projectName, '--template', 'unknown'])
expect(stdout).toContain(

Check failure on line 78 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > prompts for the framework on supplying an invalid template

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain '"unknown" isn\'t a valid template. Pl…' - Expected + Received - "unknown" isn't a valid template. Please choose from below: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:78:18

Check failure on line 78 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > prompts for the framework on supplying an invalid template

AssertionError: expected '\n\u001b[90m┌\u001b[39m \u001b[104m …' to contain '"unknown" isn\'t a valid template. Pl…' - Expected + Received - "unknown" isn't a valid template. Please choose from below: + + ┌ create-crxjs - quickly start a browser extension + │ + ◆ Extension description (you can edit this anytime in package.json): + │ A browser extension built with CRXJS. + └ ❯ __tests__/cli.spec.ts:78:18
`"unknown" isn't a valid template. Please choose from below:`,
)
})
Expand Down Expand Up @@ -104,29 +104,43 @@
const { stdout } = run([projectName, '--template', 'vue'], {
cwd: __dirname,
})
const generatedFiles = fs.readdirSync(genPath).sort()

Check failure on line 107 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > successfully scaffolds a project based on vue starter template

Error: ENOENT: no such file or directory, scandir '/Users/runner/work/create-crxjs/create-crxjs/__tests__/test-app' ❯ __tests__/cli.spec.ts:107:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/Users/runner/work/create-crxjs/create-crxjs/__tests__/test-app' }

Check failure on line 107 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > successfully scaffolds a project based on vue starter template

Error: ENOENT: no such file or directory, scandir '/home/runner/work/create-crxjs/create-crxjs/__tests__/test-app' ❯ __tests__/cli.spec.ts:107:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/home/runner/work/create-crxjs/create-crxjs/__tests__/test-app' }
const generatedPackage = JSON.parse(
fs.readFileSync(path.join(genPath, 'package.json'), 'utf-8'),
)

// Assertions
expect(stdout).toContain(`Scaffolding project in ${genPath}`)
expect(templateFiles).toEqual(generatedFiles)
expect(generatedPackage.name).toBe(projectName)
expect(generatedPackage.description).toBe(
'A browser extension built with CRXJS.',
)
})

it('successfully scaffolds a project with subfolder based on react starter template', () => {
const { stdout } = run([`subfolder/${projectName}`, '--template', 'react'], {
cwd: __dirname,
})
const generatedFiles = fs.readdirSync(genPathWithSubfolder).sort()

Check failure on line 125 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > successfully scaffolds a project with subfolder based on react starter template

Error: ENOENT: no such file or directory, scandir '/Users/runner/work/create-crxjs/create-crxjs/__tests__/subfolder/test-app' ❯ __tests__/cli.spec.ts:125:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/Users/runner/work/create-crxjs/create-crxjs/__tests__/subfolder/test-app' }

Check failure on line 125 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > successfully scaffolds a project with subfolder based on react starter template

Error: ENOENT: no such file or directory, scandir '/home/runner/work/create-crxjs/create-crxjs/__tests__/subfolder/test-app' ❯ __tests__/cli.spec.ts:125:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/home/runner/work/create-crxjs/create-crxjs/__tests__/subfolder/test-app' }
const generatedPackage = JSON.parse(
fs.readFileSync(path.join(genPathWithSubfolder, 'package.json'), 'utf-8'),
)

// Assertions
expect(stdout).toContain(`Scaffolding project in ${genPathWithSubfolder}`)
expect(templateFilesReact).toEqual(generatedFiles)
expect(generatedPackage.name).toBe(projectName)
expect(generatedPackage.description).toBe(
'A browser extension built with CRXJS.',
)
})

it('works with the -t alias', () => {
const { stdout } = run([projectName, '-t', 'vue'], {
cwd: __dirname,
})
const generatedFiles = fs.readdirSync(genPath).sort()

Check failure on line 143 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

__tests__/cli.spec.ts > works with the -t alias

Error: ENOENT: no such file or directory, scandir '/Users/runner/work/create-crxjs/create-crxjs/__tests__/test-app' ❯ __tests__/cli.spec.ts:143:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/Users/runner/work/create-crxjs/create-crxjs/__tests__/test-app' }

Check failure on line 143 in __tests__/cli.spec.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

__tests__/cli.spec.ts > works with the -t alias

Error: ENOENT: no such file or directory, scandir '/home/runner/work/create-crxjs/create-crxjs/__tests__/test-app' ❯ __tests__/cli.spec.ts:143:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/home/runner/work/create-crxjs/create-crxjs/__tests__/test-app' }

// Assertions
expect(stdout).toContain(`Scaffolding project in ${genPath}`)
Expand Down
12 changes: 12 additions & 0 deletions __tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from 'vitest'
import { isValidDescription } from '../src/utils'

describe('isValidDescription', () => {
it('accepts descriptions up to 132 characters', () => {
expect(isValidDescription('a'.repeat(132))).toBe(true)
})

it('rejects descriptions longer than 132 characters', () => {
expect(isValidDescription('a'.repeat(133))).toBe(false)
})
})
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
generateBanner,
isEmpty,
isGitHubUrl,
isValidDescription,
isValidPackageName,
pkgFromUserAgent,
toValidPackageName,
Expand Down Expand Up @@ -120,6 +121,20 @@ async function init() {
packageName = packageNameResult
}

const packageDescriptionResult = await prompts.text({
message: 'Extension description (you can edit this anytime in package.json):',
defaultValue: 'A browser extension built with CRXJS.',
placeholder: 'A browser extension built with CRXJS.',
validate(description) {
if (!isValidDescription(description)) {
return 'Description must be non-blank and 132 characters or fewer'
}
},
})
if (prompts.isCancel(packageDescriptionResult))
return cancel()
const packageDescription = packageDescriptionResult

// 4. Choose a framework and variant
let template = argTemplate
let hasInvalidArgTemplate = false
Expand Down Expand Up @@ -180,6 +195,7 @@ async function init() {
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
pkg.name = packageName
pkg.description = packageDescription
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
}
s.stop('Cloning completed successfully')
Expand Down Expand Up @@ -213,6 +229,7 @@ async function init() {
)

pkg.name = packageName
pkg.description = packageDescription

write('package.json', `${JSON.stringify(pkg, null, 2)}\n`)
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function isValidPackageName(projectName: string) {
)
}

// Chrome webstore limit reference: https://developer.chrome.com/docs/extensions/reference/manifest#required-web-store
export function isValidDescription(description: string): boolean {
return description.trim().length > 0 && description.length <= 132
}
export function toValidPackageName(projectName: string) {
return projectName
.trim()
Expand Down
1 change: 1 addition & 0 deletions templates/react-ts/manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
Expand Down
1 change: 1 addition & 0 deletions templates/react/manifest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
1 change: 1 addition & 0 deletions templates/solid-ts/manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/solid-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
Expand Down
1 change: 1 addition & 0 deletions templates/solid/manifest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vite build"
Expand Down
1 change: 1 addition & 0 deletions templates/svelte-ts/manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vite build"
Expand Down
1 change: 1 addition & 0 deletions templates/svelte/manifest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vite build"
Expand Down
1 change: 1 addition & 0 deletions templates/vanilla-ts/manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/vanilla-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "tsc && vite build"
Expand Down
1 change: 1 addition & 0 deletions templates/vanilla/manifest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vite build"
Expand Down
1 change: 1 addition & 0 deletions templates/vue-ts/manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build"
Expand Down
1 change: 1 addition & 0 deletions templates/vue/manifest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pkg from './package.json'
export default defineManifest({
manifest_version: 3,
name: pkg.name,
description: pkg.description,
version: pkg.version,
icons: {
48: 'public/logo.png',
Expand Down
1 change: 1 addition & 0 deletions templates/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "1.0.0",
"private": true,
"description": "A browser extension built with CRXJS.",
"scripts": {
"dev": "vite",
"build": "vite build"
Expand Down
Loading