Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 81f97c4

Browse files
authored
chore(CI): reenable test:projects:cra-ts (#608)
* chore(CI): reenable `test:projects:cra-ts` * restore log util * minor fixes
1 parent 3fcabc1 commit 81f97c4

File tree

2 files changed

+58
-80
lines changed

2 files changed

+58
-80
lines changed

build/gulp/tasks/test-projects.tsx

Lines changed: 37 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as debug from 'debug'
21
import * as fs from 'fs'
3-
import { series, task } from 'gulp'
2+
import { parallel, series, task } from 'gulp'
43
import * as path from 'path'
54
import sh from '../sh'
65
import * as rimraf from 'rimraf'
@@ -10,22 +9,22 @@ import * as tmp from 'tmp'
109

1110
const { paths } = config
1211

13-
const log = msg => {
12+
const log = (context: string) => (message: string) => {
1413
console.log()
1514
console.log('='.repeat(80))
16-
console.log('CRA TS:', msg)
15+
console.log(`${context} : ${message}`)
1716
console.log('='.repeat(80))
1817
}
1918

20-
export const createPackageFilename = () => tmp.tmpNameSync({ prefix: 'stardust-', postfix: '.tgz' })
19+
export const publishPackage = async () => {
20+
const filename = tmp.tmpNameSync({ prefix: 'stardust-', postfix: '.tgz' })
21+
await sh(`yarn pack --filename ${filename}`)
2122

22-
export const runIn = path => cmd => sh(`cd ${path} && ${cmd}`)
23-
24-
export const buildAndPackStardust = async (packageFilename: string) => {
25-
await sh('yarn build:dist')
26-
await sh(`yarn pack --filename ${packageFilename}`)
23+
return filename
2724
}
2825

26+
export const runIn = path => cmd => sh(`cd ${path} && ${cmd}`)
27+
2928
const createReactApp = async (atTempDirectory: string, appName: string): Promise<string> => {
3029
const atDirectorySubpath = paths.withRootAt(atTempDirectory)
3130

@@ -59,89 +58,50 @@ const createReactApp = async (atTempDirectory: string, appName: string): Promise
5958
// - Update the App.tsx to include some stardust imports
6059
// - Try and run a build
6160
task('test:projects:cra-ts', async () => {
62-
const appTSX = `import {
63-
Avatar,
64-
Button,
65-
Header,
66-
Image,
67-
Input,
68-
Popup,
69-
Provider,
70-
themes
71-
} from '@stardust-ui/react';
72-
import * as React from 'react';
73-
74-
class App extends React.Component {
75-
public render() {
76-
return (
77-
<Provider theme={themes.teams}>
78-
<div>
79-
<Popup trigger={<Button content="Popup" />} content="Popup content" />
80-
<Avatar src="//placehold.it" />
81-
<Button content="Click me" />
82-
<Header content="This is " />
83-
<Image src="//placehold.it" />
84-
<Input placeholder="Type here" />
85-
</div>
86-
</Provider>
87-
);
88-
}
89-
}
90-
91-
export default App;
92-
`
93-
//////// PREPARE STARDUST PACKAGE ///////
94-
log('STEP 0. Preparing Stardust package..')
95-
96-
const packageFilename = createPackageFilename()
61+
const logger = log('test:projects:cra-ts')
62+
const scaffoldPath = paths.base.bind(null, 'build/gulp/tasks/test-projects/cra')
9763

98-
await buildAndPackStardust(packageFilename)
99-
log(`Stardust package is published: ${packageFilename}`)
64+
const packageFilename = await publishPackage()
65+
logger(`✔️Package was published: ${packageFilename}`)
10066

101-
try {
102-
//////// CREATE TEST REACT APP ///////
103-
log('STEP 1. Create test React project with TSX scripts..')
67+
//////// CREATE TEST REACT APP ///////
68+
logger('STEP 1. Create test React project with TSX scripts..')
10469

105-
const testAppPath = paths.withRootAt(
106-
await createReactApp(tmp.dirSync({ prefix: 'stardust-' }).name, 'test-app'),
107-
)
70+
const testAppPath = paths.withRootAt(
71+
await createReactApp(tmp.dirSync({ prefix: 'stardust-' }).name, 'test-app'),
72+
)
10873

109-
const runInTestApp = runIn(testAppPath())
110-
log(`Test React project is successfully created: ${testAppPath()}`)
74+
const runInTestApp = runIn(testAppPath())
75+
logger(`Test React project is successfully created: ${testAppPath()}`)
11176

112-
//////// ADD STARDUST AS A DEPENDENCY ///////
113-
log('STEP 2. Add Stardust dependency to test project..')
77+
//////// ADD STARDUST AS A DEPENDENCY ///////
78+
logger('STEP 2. Add Stardust dependency to test project..')
11479

115-
await runInTestApp(`yarn add ${packageFilename}`)
116-
log("Stardust is successfully added as test project's dependency.")
80+
await runInTestApp(`yarn add ${packageFilename}`)
81+
logger("Stardust is successfully added as test project's dependency.")
11782

118-
//////// REFERENCE STARDUST COMPONENTS IN TEST APP's MAIN FILE ///////
119-
log("STEP 3. Reference Stardust components in test project's App.tsx")
120-
fs.writeFileSync(testAppPath('src', 'App.tsx'), appTSX)
83+
//////// REFERENCE STARDUST COMPONENTS IN TEST APP's MAIN FILE ///////
84+
logger("STEP 3. Reference Stardust components in test project's App.tsx")
85+
fs.copyFileSync(scaffoldPath('App.tsx'), testAppPath('src', 'App.tsx'))
12186

122-
//////// BUILD TEST PROJECT ///////
123-
log('STEP 4. Build test project..')
124-
await runInTestApp(`yarn build`)
87+
//////// BUILD TEST PROJECT ///////
88+
logger('STEP 4. Build test project..')
89+
await runInTestApp(`yarn build`)
12590

126-
log('Test project is built successfully!')
127-
} finally {
128-
fs.unlinkSync(packageFilename)
129-
}
91+
logger('Test project is built successfully!')
13092
})
13193

13294
task('test:projects:rollup', async () => {
133-
const logger = debug('bundle:rollup')
134-
logger.enabled = true
95+
const logger = log('test:projects:rollup')
13596

136-
const packageFilename = createPackageFilename()
13797
const scaffoldPath = paths.base.bind(null, 'build/gulp/tasks/test-projects/rollup')
138-
139-
await buildAndPackStardust(packageFilename)
140-
logger(`✔️Stardust UI package was prepared: ${packageFilename}`)
141-
14298
const tmpDirectory = tmp.dirSync({ prefix: 'stardust-' }).name
99+
143100
logger(`✔️Temporary directory was created: ${tmpDirectory}`)
144101

102+
const packageFilename = await publishPackage()
103+
logger(`✔️Package was published: ${packageFilename}`)
104+
145105
const dependencies = [
146106
'rollup',
147107
'rollup-plugin-replace',
@@ -166,8 +126,5 @@ task('test:projects:rollup', async () => {
166126

167127
task(
168128
'test:projects',
169-
series(
170-
// 'test:projects:cra-ts', Temporary disabled
171-
'test:projects:rollup',
172-
),
129+
series('build:dist', parallel('test:projects:cra-ts', 'test:projects:rollup')),
173130
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Avatar, Button, Header, Image, Input, Popup, Provider, themes } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
class App extends React.Component {
5+
public render() {
6+
return (
7+
<Provider theme={themes.teams}>
8+
<div>
9+
<Popup trigger={<Button content="Popup" />} content="Popup content" />
10+
<Avatar src="//placehold.it" />
11+
<Button content="Click me" />
12+
<Header content="This is " />
13+
<Image src="//placehold.it" />
14+
<Input placeholder="Type here" />
15+
</div>
16+
</Provider>
17+
)
18+
}
19+
}
20+
21+
export default App

0 commit comments

Comments
 (0)