1
- import * as debug from 'debug'
2
1
import * as fs from 'fs'
3
- import { series , task } from 'gulp'
2
+ import { parallel , series , task } from 'gulp'
4
3
import * as path from 'path'
5
4
import sh from '../sh'
6
5
import * as rimraf from 'rimraf'
@@ -10,22 +9,22 @@ import * as tmp from 'tmp'
10
9
11
10
const { paths } = config
12
11
13
- const log = msg => {
12
+ const log = ( context : string ) => ( message : string ) => {
14
13
console . log ( )
15
14
console . log ( '=' . repeat ( 80 ) )
16
- console . log ( 'CRA TS:' , msg )
15
+ console . log ( ` ${ context } : ${ message } ` )
17
16
console . log ( '=' . repeat ( 80 ) )
18
17
}
19
18
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 } ` )
21
22
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
27
24
}
28
25
26
+ export const runIn = path => cmd => sh ( `cd ${ path } && ${ cmd } ` )
27
+
29
28
const createReactApp = async ( atTempDirectory : string , appName : string ) : Promise < string > => {
30
29
const atDirectorySubpath = paths . withRootAt ( atTempDirectory )
31
30
@@ -59,89 +58,50 @@ const createReactApp = async (atTempDirectory: string, appName: string): Promise
59
58
// - Update the App.tsx to include some stardust imports
60
59
// - Try and run a build
61
60
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' )
97
63
98
- await buildAndPackStardust ( packageFilename )
99
- log ( `Stardust package is published: ${ packageFilename } `)
64
+ const packageFilename = await publishPackage ( )
65
+ logger ( `✔️Package was published: ${ packageFilename } `)
100
66
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..' )
104
69
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
+ )
108
73
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 ( ) } ` )
111
76
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..' )
114
79
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." )
117
82
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' ) )
121
86
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` )
125
90
126
- log ( 'Test project is built successfully!' )
127
- } finally {
128
- fs . unlinkSync ( packageFilename )
129
- }
91
+ logger ( 'Test project is built successfully!' )
130
92
} )
131
93
132
94
task ( 'test:projects:rollup' , async ( ) => {
133
- const logger = debug ( 'bundle:rollup' )
134
- logger . enabled = true
95
+ const logger = log ( 'test:projects:rollup' )
135
96
136
- const packageFilename = createPackageFilename ( )
137
97
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
-
142
98
const tmpDirectory = tmp . dirSync ( { prefix : 'stardust-' } ) . name
99
+
143
100
logger ( `✔️Temporary directory was created: ${ tmpDirectory } ` )
144
101
102
+ const packageFilename = await publishPackage ( )
103
+ logger ( `✔️Package was published: ${ packageFilename } ` )
104
+
145
105
const dependencies = [
146
106
'rollup' ,
147
107
'rollup-plugin-replace' ,
@@ -166,8 +126,5 @@ task('test:projects:rollup', async () => {
166
126
167
127
task (
168
128
'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' ) ) ,
173
130
)
0 commit comments