-
Notifications
You must be signed in to change notification settings - Fork 53
chore(mixed): fix imports and introduce bundler test #570
Changes from 16 commits
07fa488
0d58036
2b7a4dd
1929f00
a9683e2
363d3b4
aa8ed3b
8b8a748
7b9987d
d567968
abbf734
34c32b0
a7deb19
da99b8d
a2cef68
a105f7e
09d2dd6
38770f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import { Button, Provider, themes } from '@stardust-ui/react' | ||
|
||
ReactDOM.render( | ||
React.createElement( | ||
Provider, | ||
{ theme: themes.teams }, | ||
React.createElement(Button, { content: 'Theming' }), | ||
), | ||
document.getElementById('root'), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import replace from 'rollup-plugin-replace' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be placed somewhere under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's already placed in the separate dir. I don't want to be so specific for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but the same reasoning would apply well in case it will be put in any dir - thus, I am not sure that this is a valid argument. The reasoning behind my ask is the following: currently, with the dir introduced at the place where you are suggesting, we would have the following project structure:
So, reasonable question is why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At now, yes. But in the future, I think that we will have other tasks that will should also have files and templates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must agree here that better directory structure would reflect exactly what we test even. Having structure, something like:
will be much more cleaner, and it will be obvious what scenarios we got covered so far... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import resolve from 'rollup-plugin-node-resolve' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
|
||
const warningWhitelist = [ | ||
'THIS_IS_UNDEFINED', // comes from TS transforms | ||
'CIRCULAR_DEPENDENCY', // we should fix all other circular imports | ||
'UNUSED_EXTERNAL_IMPORT', // to avoid throw on unused externals | ||
] | ||
|
||
export default { | ||
external: [ | ||
'lodash', | ||
'lodash/fp', | ||
'prop-types', | ||
'react', | ||
'react-dom', | ||
'react-is', | ||
], | ||
input: 'app.js', | ||
onwarn: (warning, warn) => { | ||
if (warningWhitelist.includes(warning.code)) { | ||
warn(warning) | ||
return | ||
} | ||
|
||
throw warning | ||
}, | ||
output: { | ||
file: 'bundle.js', | ||
format: 'iife', | ||
globals: { | ||
lodash: '_', | ||
'lodash/fp': 'fp', | ||
'prop-types': 'PropTypes', | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'react-is': 'ReactIs', | ||
}, | ||
sourcemap: true, | ||
}, | ||
plugins: [ | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify('development'), | ||
}), | ||
resolve(), | ||
commonjs({ | ||
include: 'node_modules/**', | ||
namedExports: { | ||
'node_modules/keyboard-key/src/keyboardKey.js': [ | ||
'ArrowDown', | ||
'ArrowUp', | ||
'ArrowLeft', | ||
'ArrowRight', | ||
'End', | ||
'Enter', | ||
'Escape', | ||
'Home', | ||
'getCode', | ||
'Spacebar', | ||
'Tab', | ||
], | ||
'node_modules/what-input/dist/what-input.js': ['ask'], | ||
}, | ||
}), | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import * as debug from 'debug' | ||
import * as fs from 'fs' | ||
import { task } from 'gulp' | ||
import { series, task } from 'gulp' | ||
import * as path from 'path' | ||
import sh from '../sh' | ||
import * as rimraf from 'rimraf' | ||
|
||
|
@@ -15,12 +17,13 @@ const log = msg => { | |
console.log('='.repeat(80)) | ||
} | ||
|
||
const runIn = path => cmd => sh(`cd ${path} && ${cmd}`) | ||
export const createPackageFilename = () => tmp.tmpNameSync({ prefix: 'stardust-', postfix: '.tgz' }) | ||
|
||
const buildAndPackStardust = async (): Promise<string> => { | ||
await sh('yarn build:dist') | ||
export const runIn = path => cmd => sh(`cd ${path} && ${cmd}`) | ||
|
||
return (await sh(`npm pack`, true)).trim() | ||
export const buildAndPackStardust = async (packageFilename: string) => { | ||
await sh('yarn build:dist') | ||
await sh(`yarn pack --filename ${packageFilename}`) | ||
layershifter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const createReactApp = async (atTempDirectory: string, appName: string): Promise<string> => { | ||
|
@@ -90,8 +93,10 @@ export default App; | |
//////// PREPARE STARDUST PACKAGE /////// | ||
log('STEP 0. Preparing Stardust package..') | ||
|
||
const stardustPackageFilename = await buildAndPackStardust() | ||
log(`Stardust package is published: ${paths.base(stardustPackageFilename)}`) | ||
const packageFilename = createPackageFilename() | ||
|
||
await buildAndPackStardust(packageFilename) | ||
log(`Stardust package is published: ${packageFilename}`) | ||
|
||
try { | ||
//////// CREATE TEST REACT APP /////// | ||
|
@@ -107,7 +112,7 @@ export default App; | |
//////// ADD STARDUST AS A DEPENDENCY /////// | ||
log('STEP 2. Add Stardust dependency to test project..') | ||
|
||
await runInTestApp(`yarn add ${paths.base(stardustPackageFilename)}`) | ||
await runInTestApp(`yarn add ${packageFilename}`) | ||
log("Stardust is successfully added as test project's dependency.") | ||
|
||
//////// REFERENCE STARDUST COMPONENTS IN TEST APP's MAIN FILE /////// | ||
|
@@ -120,6 +125,54 @@ export default App; | |
|
||
log('Test project is built successfully!') | ||
} finally { | ||
fs.unlinkSync(stardustPackageFilename) | ||
fs.unlinkSync(packageFilename) | ||
} | ||
}) | ||
|
||
task('test:projects:rollup', async () => { | ||
const logger = debug('bundle:rollup') | ||
logger.enabled = true | ||
|
||
const packageFilename = createPackageFilename() | ||
|
||
await buildAndPackStardust(packageFilename) | ||
logger(`✔️Stardust UI package was prepared: ${packageFilename}`) | ||
|
||
const tmpDirectory = tmp.dirSync({ prefix: 'stardust-' }).name | ||
logger(`✔️Temporary directory was created: ${tmpDirectory}`) | ||
|
||
const dependencies = [ | ||
'rollup', | ||
'rollup-plugin-replace', | ||
'rollup-plugin-commonjs', | ||
'rollup-plugin-node-resolve', | ||
'react', | ||
'react-dom', | ||
].join(' ') | ||
await runIn(tmpDirectory)(`yarn add ${dependencies}`) | ||
logger(`✔️Dependencies were installed`) | ||
|
||
await runIn(tmpDirectory)(`yarn add ${packageFilename}`) | ||
logger(`✔️Stardust UI was added to dependencies`) | ||
|
||
fs.copyFileSync( | ||
path.resolve(__dirname, '..', 'scaffold', 'app.js'), | ||
path.resolve(tmpDirectory, 'app.js'), | ||
) | ||
fs.copyFileSync( | ||
path.resolve(__dirname, '..', 'scaffold', 'rollup.config.js'), | ||
path.resolve(tmpDirectory, 'rollup.config.js'), | ||
) | ||
logger(`✔️Source and bundler's config were created`) | ||
|
||
await runIn(tmpDirectory)(`yarn rollup -c`) | ||
logger(`✔️Example project was successfully built: ${tmpDirectory}`) | ||
}) | ||
|
||
task( | ||
'test:projects', | ||
series( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, can we run them in parallel? It seems that there is no shared state between these tasks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will left it as is for now. When this task will be enabled, we will able to test that it works in parallel. However, I almost sure that it will work. |
||
// 'test:projects:cra-ts', Temporary disabled | ||
'test:projects:rollup', | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍