Skip to content

Commit

Permalink
get build/watch working
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed May 13, 2020
1 parent 2d31fa9 commit 36db542
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 52 deletions.
62 changes: 62 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exports.localesUp = localesUp
exports.localesUpWatch = localesUpWatch
exports.localesAll = localesAll
exports.localesAllWatch = localesAllWatch
exports.distDirs = distDirs
exports.distLinks = distLinks


/*
Expand Down Expand Up @@ -49,3 +51,63 @@ async function localesAll() {
function localesAllWatch() {
return watch(SRC_LOCALE_DIR, localesAll)
}



const PKG_DIRS = [
'packages?(-premium)/*',
'!packages?(-premium)/{bundle,__tests__}'
]

const fs = require('fs')

const exec = require('./scripts/lib/shell').sync.withOptions({
live: true,
exitOnError: true
})


async function distDirs() {
let pkgDirs = await globby(PKG_DIRS, { onlyDirectories: true })

return pkgDirs.forEach((pkgDir) => {
let distDir = path.join(pkgDir, 'dist')
let stat

try {
stat = fs.lstatSync(distDir)
} catch (ex) {} // if doesn't exist

if (stat && !stat.isDirectory()) {
exec([ 'rm', '-rf', distDir ])
stat = null
}

if (!stat) {
exec([ 'mkdir', distDir ])
}
})
}


async function distLinks() {
let pkgDirs = await globby(PKG_DIRS, { onlyDirectories: true })

return pkgDirs.forEach((pkgDir) => {
let distDir = path.join(pkgDir, 'dist')
let stat

try {
stat = fs.lstatSync(distDir)
} catch (ex) {} // if doesn't exist

if (stat && !stat.isSymbolicLink()) {
exec([ 'rm', '-rf', distDir ])
stat = null
}

if (!stat) {
exec([ 'ln', '-s', 'tsc', distDir ])
}
})
}
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@
},
"scripts": {
"postinstall": "./scripts/postinstall.sh",
"build": "gulp build",
"watch": "gulp watch",
"lint": "gulp lint",
"build": "./scripts/build.sh",
"watch": "./scripts/watch.sh",
"clean": "./scripts/clean.sh",
"tsc": "tsc -b --verbose",
"tsc:watch": "tsc -b --verbose --watch",
"lint": "gulp lint",
"tsc": "gulp distLinks && tsc -b",
"tsc:watch": "gulp distLinks && tsc -b --watch",
"sass": "sass `./scripts/sass-args.js`",
"sass:watch": "sass --watch `./scripts/sass-args.js`",
"locales": "gulp localesUp localesAll",
"locales:watch": "gulp localesUpWatch localesAllWatch",
"rollup": "rollup -c --environment BUILD:production",
"rollup:watch": "rollup -c --environment BUILD:development --watch",
"rollup:packages": "gulp distDirs && rollup -c rollup.packages.js",
"rollup:bundles": "rollup -c rollup.bundles.js",
"rollup:bundles:watch": "rollup -c rollup.bundles.js --watch",
"test": "concurrently --restart-tries 999 --prefix none 'karma start karma.config.js'",
"test:ci": "karma start karma.config.js ci",
"ci": "./scripts/ci.sh",
Expand Down
91 changes: 91 additions & 0 deletions rollup.bundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const path = require('path')
const globby = require('globby')
const nodeResolve = require('@rollup/plugin-node-resolve')
const postCss = require('rollup-plugin-postcss')

const CORE_PKG_DIR = 'packages/core'
const BUNDLE_DIRS = [ // TODO: use glob!
'packages/bundle',
'packages-premium/bundle'
]


module.exports = [
...BUNDLE_DIRS.map(bundleMainConfig),
localeAllConfig(),
...localEachConfigs()
]


function bundleMainConfig(bundleDir) {
return {
input: path.join(bundleDir, 'tsc/main.js'),
output: {
format: 'iife',
name: 'FullCalendar',
dir: path.join(bundleDir, 'dist')
},
plugins: [
nodeResolve(),
postCss({
extract: true // to separate file
})
],
watch: {
// chokidar: {
// awaitWriteFinish: true, // has good defaults
// },
// buildDelay: 1000, // doesn't work in rollup v1
clearScreen: false // because tsc does it
}
}
}


function localeAllConfig() {
return {
input: path.join(CORE_PKG_DIR, 'locales-all.js'),
output: BUNDLE_DIRS.map((bundleDir) => ({
format: 'iife',
name: 'FullCalendar',
dir: bundleDir
})),
plugins: [
localeAllWrap()
]
}
}


function localEachConfigs() {
return globby.sync('locales/*.js', { cwd: CORE_PKG_DIR }).map((localeFile) => ({
input: path.join(CORE_PKG_DIR, localeFile),
output: BUNDLE_DIRS.map((bundleDir) => ({
format: 'iife',
name: 'FullCalendar',
dir: bundleDir,
entryFileNames: localeFile
})),
plugins: [
localeEachWrap()
]
}))
}


function localeAllWrap() {
return {
renderChunk(code) {
return code.replace(/^var FullCalendar = /, 'FullCalendar.globalLocales = ')
}
}
}


function localeEachWrap() {
return {
renderChunk(code) {
return code.replace(/^var FullCalendar = /, 'FullCalendar.globalLocales.push')
}
}
}
21 changes: 0 additions & 21 deletions rollup.config.js

This file was deleted.

92 changes: 92 additions & 0 deletions rollup.packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const path = require('path')
const globby = require('globby')
const dts = require('rollup-plugin-dts').default


const MAIN_PATHS = [
'packages?(-premium)/*/tsc/main.js',
'!packages?(-premium)/bundle/tsc/main.js',
'!packages?(-premium)/__tests__/tsc/main.js'
]


module.exports = [
...jsConfigs(),
...dtsConfigs()
]


function jsConfigs() {
return globby.sync(MAIN_PATHS).map((mainPath) => ({
input: mainPath,
output: {
format: 'es',
dir: path.resolve(mainPath, '../../dist')
},
plugins: [
externalizeStylesheets(),
externalizeNamed(mainPath)
],
watch: {
chokidar: { // better than default watch util. doesn't fire change events on stat changes (like last opened)
awaitWriteFinish: { // because tsc/rollup sometimes takes a long time to write and triggers two recompiles
stabilityThreshold: 500,
pollInterval: 100
}
},
clearScreen: false
}
}))
}


function externalizeStylesheets() {
return {
resolveId(id) {
if (id.match(/\.css$/)) {
return { id, external: true }
}
}
}
}


function externalizeNamed(mainPath) {
return {
resolveId(id) {
if (
id !== mainPath && // not the main file
!id.match(/^\./) // non-relative
) {
return { id, external: true }
}
}
}
}


function dtsConfigs() {
return globby.sync(MAIN_PATHS).map((mainPath) => ({
input: mainPath.replace(/\.js$/, '.d.ts'),
output: {
format: 'es',
file: path.resolve(mainPath, '../../dist/main.d.ts')
},
plugins: [
externalizeStylesheets(),
externalizeVDom(),
dts()
]
}))
}


function externalizeVDom() { // TODO: will need to copy these over manually!!!
return {
resolveId(id) {
if (id.match(/\/vdom$/)) {
return { id, external: true }
}
}
}
}
10 changes: 10 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e # immediately exit upon error
cd "`dirname $0`/.." # start in project root

npm run tsc
npm run locales
npm run rollup:packages
npm run sass # will write to dest dirs created by rollup:packages
npm run rollup:bundles
4 changes: 2 additions & 2 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

set -e # always immediately exit upon error
cd "`dirname $0`/.." # always start in project root
set -e # immediately exit upon error
cd "`dirname $0`/.." # start in project root

npm run clean
npm run build
Expand Down
12 changes: 6 additions & 6 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ cd "`dirname $0`/.." # always start in project root
rm -rf archives

rm -rf packages/*/tsconfig.tsbuildinfo
rm -rf packages/*/dist
rm -rf packages/*/tsc
rm -rf packages/*/rollup
rm -rf packages/core/locales
rm -rf packages/core/locales-all.js
rm -rf packages/*/dist
rm -rf packages/*/locales
rm -rf packages/*/locales-all.js

rm -rf packages-premium/*/tsconfig.tsbuildinfo
rm -rf packages-premium/*/dist
rm -rf packages-premium/*/tsc
rm -rf packages-premium/*/rollup
rm -rf packages-premium/*/dist
rm -rf packages/*/locales
rm -rf packages/*/locales-all.js
2 changes: 1 addition & 1 deletion scripts/example-projects-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ glob.sync('*/', { cwd: PROJECTS_ROOT }).forEach(function(exampleDir) { // will m
)

} else {
let { success } = exec.sync('yarn', [ 'run', 'build' ], {
let { success } = exec.sync([ 'yarn', 'run', 'build' ], {
cwd: path.join(PROJECTS_ROOT, exampleDir),
live: true
})
Expand Down

0 comments on commit 36db542

Please sign in to comment.