Skip to content
This repository was archived by the owner on Apr 1, 2023. It is now read-only.

Commit b6b4380

Browse files
fix: typescript template
1 parent e46464b commit b6b4380

16 files changed

+85
-77
lines changed

lib/create-library.test.js

+37-34
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict'
22

3-
const { test } = require('ava')
3+
const test = require('ava')
44
const execa = require('execa')
55
const path = require('path')
66
const rmfr = require('rmfr')
77

88
const createLibrary = require('./create-library')
99

10-
const tests = [
10+
const fixtures = [
1111
{
1212
name: 'my-test-library',
1313
author: 'nala',
14-
description: 'this is a auto-generated test module. please ignore.',
14+
description: 'this is an auto-generated test module. please ignore.',
1515
repo: 'nala/my-test-library',
1616
license: 'MIT',
1717
manager: 'yarn',
@@ -21,7 +21,7 @@ const tests = [
2121
{
2222
name: 'my-test-typescript-library',
2323
author: 'nala',
24-
description: 'this is a auto-generated test module. please ignore.',
24+
description: 'this is an auto-generated test module. please ignore.',
2525
repo: 'nala/my-test-library',
2626
license: 'MIT',
2727
manager: 'yarn',
@@ -31,7 +31,7 @@ const tests = [
3131
{
3232
name: 'my-test-library',
3333
author: 'nala',
34-
description: 'this is a auto-generated test module. please ignore.',
34+
description: 'this is an auto-generated test module. please ignore.',
3535
repo: 'nala/my-test-library',
3636
license: 'MIT',
3737
manager: 'npm',
@@ -41,7 +41,7 @@ const tests = [
4141
{
4242
name: 'my-test-library',
4343
author: 'nala',
44-
description: 'this is a auto-generated test module. please ignore.',
44+
description: 'this is an auto-generated test module. please ignore.',
4545
repo: 'nala/my-test-typescript-library',
4646
license: 'MIT',
4747
manager: 'npm',
@@ -51,7 +51,7 @@ const tests = [
5151
{
5252
name: '@automagical/nala',
5353
author: 'superstar-cats',
54-
description: 'this is a auto-generated test module. please ignore.',
54+
description: 'this is an auto-generated test module. please ignore.',
5555
repo: 'superstar-cats/nala',
5656
license: 'GPL',
5757
manager: 'yarn',
@@ -61,7 +61,7 @@ const tests = [
6161
{
6262
name: 'no-git-library',
6363
author: 'nala',
64-
description: 'this is a auto-generated test module. please ignore.',
64+
description: 'this is an auto-generated test module. please ignore.',
6565
repo: 'nala/no-git-library',
6666
license: 'MIT',
6767
manager: 'yarn',
@@ -71,7 +71,7 @@ const tests = [
7171
{
7272
name: 'my-custom-template',
7373
author: 'nala',
74-
description: 'this is a auto-generated test module. please ignore.',
74+
description: 'this is an auto-generated test module. please ignore.',
7575
repo: 'nala/my-custom-template',
7676
license: 'GPL',
7777
manager: 'yarn',
@@ -81,36 +81,39 @@ const tests = [
8181
}
8282
]
8383

84-
tests.forEach((opts) => {
85-
test.serial(`creating "${opts.name}" using ${opts.manager}`, async (t) => {
86-
console.log(`creating "${opts.name}" using ${opts.manager}...`)
87-
let ret
84+
fixtures.forEach((fixture) => {
85+
test.serial(
86+
`creating "${fixture.name}" using ${fixture.manager}`,
87+
async (t) => {
88+
console.log(`creating "${fixture.name}" using ${fixture.manager}...`)
89+
let ret
8890

89-
// ensure library is created successfully
90-
const root = await createLibrary(opts)
91-
const example = path.join(root, 'example')
92-
t.truthy(root.indexOf(opts.shortName) >= 0)
91+
// ensure library is created successfully
92+
const root = await createLibrary(fixture)
93+
const example = path.join(root, 'example')
94+
t.truthy(root.indexOf(fixture.shortName) >= 0)
9395

94-
// ensure deps install successfully in root
95-
ret = await execa.shell(`${opts.manager} install`, { cwd: root })
96-
t.is(ret.code, 0)
96+
// ensure deps install successfully in root
97+
ret = await execa.shell(`${fixture.manager} install`, { cwd: root })
98+
t.is(ret.code, 0)
9799

98-
// ensure root tests pass
99-
ret = await execa.shell(`${opts.manager} test`, { cwd: root })
100-
t.is(ret.code, 0)
100+
// ensure root tests pass
101+
ret = await execa.shell(`${fixture.manager} test`, { cwd: root })
102+
t.is(ret.code, 0)
101103

102-
// ensure deps install successfully in example
103-
ret = await execa.shell(`${opts.manager} install`, { cwd: example })
104-
t.is(ret.code, 0)
104+
// ensure deps install successfully in example
105+
ret = await execa.shell(`${fixture.manager} install`, { cwd: example })
106+
t.is(ret.code, 0)
105107

106-
// ensure bundle builds successfully in example
107-
ret = await execa.shell(`${opts.manager} build`, { cwd: example })
108-
t.is(ret.code, 0)
108+
// ensure bundle builds successfully in example
109+
ret = await execa.shell(`${fixture.manager} build`, { cwd: example })
110+
t.is(ret.code, 0)
109111

110-
// ensure git is initialized properly
111-
ret = await execa.shell('git rev-parse --git-dir', { cwd: root })
112-
t.is(ret.stdout, opts.git ? '.git' : path.join(process.cwd(), '.git'))
112+
// ensure git is initialized properly
113+
ret = await execa.shell('git rev-parse --git-dir', { cwd: root })
114+
t.is(ret.stdout, fixture.git ? '.git' : path.join(process.cwd(), '.git'))
113115

114-
await rmfr(root)
115-
})
116+
await rmfr(root)
117+
}
118+
)
116119
})

lib/get-default-library-params.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const config = require('./config')
1010
module.exports = async () => {
1111
const defaults = {
1212
name: '',
13-
description: 'React module created with Create React Library',
13+
description: 'Made with create-react-library',
1414
author: config.get('author'),
1515
repo: (info) => `${info.author}/${info.name}`,
1616
license: config.get('license', 'MIT'),

template/default/example/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

33
import { ExampleComponent } from '{{name}}'
4-
import '{{name}/dist/index.css'
4+
import '{{name}}/dist/index.css'
55

66
const App = () => {
77
return <ExampleComponent text="Create React Library Example 😄" />

template/default/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"node": ">=10"
1313
},
1414
"scripts": {
15-
"build": "microbundle --no-compress --format modern,cjs",
16-
"start": "microbundle watch --no-compress --format modern,cjs",
15+
"build": "microbundle-crl --no-compress --format modern,cjs",
16+
"start": "microbundle-crl watch --no-compress --format modern,cjs",
1717
"prepublish": "run-s build",
1818
"test": "run-s test:unit test:lint test:build",
1919
"test:build": "run-s build",
@@ -27,7 +27,7 @@
2727
"react": "^16.0.0"
2828
},
2929
"devDependencies": {
30-
"@saasify/microbundle": "^0.13.7",
30+
"microbundle-crl": "^0.13.8",
3131
"babel-eslint": "^10.0.3",
3232
"cross-env": "^7.0.2",
3333
"eslint": "^6.8.0",

template/default/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import styles from './styles.css'
2+
import styles from './styles.module.css'
33

44
export const ExampleComponent = ({ text }) => {
55
return <div className={styles.test}>Example Component: {text}</div>

template/typescript/src/test.ts renamed to template/default/src/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ExampleComponent from './'
1+
import { ExampleComponent } from '.'
22

33
describe('ExampleComponent', () => {
44
it('is truthy', () => {

template/default/src/styles.css

-8
This file was deleted.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* add css module styles here (optional) */
2+
3+
.test {
4+
margin: 2em;
5+
padding: 0.5em;
6+
border: 2px solid #000;
7+
font-size: 2em;
8+
text-align: center;
9+
}

template/typescript/example/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

33
import { ExampleComponent } from '{{name}}'
4-
import '{{name}/dist/index.css'
4+
import '{{name}}/dist/index.css'
55

66
const App = () => {
77
return <ExampleComponent text="Create React Library Example 😄" />

template/typescript/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"license": "{{license}}",
77
"repository": "{{repo}}",
88
"main": "dist/index.js",
9-
"module": "dist/index.es.js",
10-
"source": "src/index.ts",
9+
"module": "dist/index.modern.js",
10+
"source": "src/index.tsx",
1111
"engines": {
1212
"node": ">=10"
1313
},
1414
"scripts": {
15-
"build": "microbundle --no-compress --format modern,cjs",
16-
"start": "microbundle watch --no-compress --format modern,cjs",
15+
"build": "microbundle-crl --no-compress --format modern,cjs",
16+
"start": "microbundle-crl watch --no-compress --format modern,cjs",
1717
"prepublish": "run-s build",
1818
"test": "run-s test:unit test:lint test:build",
1919
"test:build": "run-s build",
@@ -27,7 +27,8 @@
2727
"react": "^16.0.0"
2828
},
2929
"devDependencies": {
30-
"@saasify/microbundle": "^0.13.7",
30+
"@types/react": "^16.9.27",
31+
"microbundle-crl": "^0.13.8",
3132
"babel-eslint": "^10.0.3",
3233
"cross-env": "^7.0.2",
3334
"eslint": "^6.8.0",
File renamed without changes.

template/typescript/src/index.ts

-6
This file was deleted.

template/typescript/src/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react'
2+
import styles from './styles.module.css'
3+
4+
interface Props {
5+
text: string
6+
}
7+
8+
export const ExampleComponent = ({ text }: Props) => {
9+
return <div className={styles.test}>Example Component: {text}</div>
10+
}

template/typescript/src/styles.css

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* add css module styles here (optional) */
2+
3+
.test {
4+
margin: 2em;
5+
padding: 0.5em;
6+
border: 2px solid #000;
7+
font-size: 2em;
8+
text-align: center;
9+
}

template/typescript/tsconfig.json

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{
22
"compilerOptions": {
3-
"outDir": "build",
3+
"outDir": "dist",
44
"module": "esnext",
5-
"target": "es5",
6-
"lib": ["es6", "dom", "es2016", "es2017"],
7-
"sourceMap": true,
8-
"allowJs": false,
5+
"lib": ["dom", "esnext"],
6+
"moduleResolution": "node",
97
"jsx": "react",
8+
"sourceMap": true,
109
"declaration": true,
11-
"moduleResolution": "node",
12-
"forceConsistentCasingInFileNames": true,
10+
"esModuleInterop": true,
1311
"noImplicitReturns": true,
1412
"noImplicitThis": true,
1513
"noImplicitAny": true,
@@ -20,5 +18,5 @@
2018
"allowSyntheticDefaultImports": true
2119
},
2220
"include": ["src"],
23-
"exclude": ["node_modules", "build", "dist", "example"]
21+
"exclude": ["node_modules", "dist", "example"]
2422
}

0 commit comments

Comments
 (0)