Skip to content

Commit

Permalink
Ejected chomp templates to better thread NODE_ENV param through the b…
Browse files Browse the repository at this point in the history
…uild process and to the node process (#4 #5)
  • Loading branch information
zachsa committed Jul 12, 2022
1 parent f3aa4d7 commit c3ad996
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 39 deletions.
68 changes: 30 additions & 38 deletions web/chompfile.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
version = 0.1
default-task = 'start'
extensions = ['[email protected]:jspm', '[email protected]:swc']

#############################
#############################
#############################

[[task]]
name = 'start'
deps = [
'.cache',
'.cache/*.html',
'copy-static-files',
'server',
]
serial = true
deps = ['.cache', '.cache/*.html', 'copy-static-files', 'server']

#############################
#############################
#############################

[[task]]
name = 'copy-static-files'
run = """
run = '''
cp -r public/* .cache/
"""
'''

[[task]]
name = 'server'
Expand Down Expand Up @@ -58,36 +58,31 @@ run = 'rollup -c rollup/server.config.js'
# Create an import map for node
[[task]]
name = 'jspm:node'
deps = ['index.importmap.js', '.cache']
target = 'node.importmap'
template = 'jspm'
[task.template-options]
default-provider = 'jspm'
env = ['node', 'production', 'module']
ignore = [
'mongodb',
'graphql',
'apollo-server-core',
'apollo-server-koa',
'koa-bodyparser',
'http-errors'
targets = ['node.importmap']
deps = [
'index.importmap.js',
'.cache'
]
invalidation = 'always'
run = "node jspm-node.js"

# Transpile HTML + js => HTML / import map
[[task]]
name = 'jspm:client'
deps = ['client/html/#.html', '.cache']
target = '.cache/#.html'
template = 'jspm'
[task.template-options]
env = ['browser', 'production', 'module']
default-provider = 'jspm'
preload = false
integrity = false
targets = ['.cache/#.html']
deps = [
'client/html/#.html',
'.cache'
]
invalidation = 'always'
run = "node jspm-client.js"

[[task]]
target = '.cache'
deps = ['client/**/*', 'common/**/*']
deps = [
'client/**/*',
'common/**/*'
]
env = { TZ='UTC'}
run = """
prettier \
Expand All @@ -101,19 +96,19 @@ prettier \
--config rollup/client.config.js
"""

# First delete and recreate the cache
[[task]]
name = 'clear-cache'
run = """
run = '''
rimraf node.importmap
rimraf .cache
rimraf .ssr
"""
'''

#############################
#############################
#############################


[[task]]
name = 'prettier'
run = """
Expand All @@ -129,8 +124,6 @@ prettier \
--write "./*.@(js|jsx|json|mjs|cjs|graphql|yml|ts|tsx)"
"""

# DEPENDENCY MANAGEMNT

[[task]]
name = 'reset'
run = 'find . -name node_modules -type d -exec rm -rv {} + && find . -name package-lock.json -type f -delete'
Expand All @@ -141,8 +134,7 @@ run = 'ncu'

[[task]]
name = 'ncu:u'
run = """
run = '''
ncu -u
npm install
"""

'''
25 changes: 25 additions & 0 deletions web/jspm-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Generator } from '@jspm/generator'
import { readFile, writeFile } from 'fs/promises'
import { pathToFileURL } from 'url'
import mkdirp from 'mkdirp'
import { dirname } from 'path'

const NODE_ENV = process.env.NODE_ENV || 'development'

const generator = new Generator({
mapUrl: pathToFileURL(process.env.TARGET),
env: ['browser', NODE_ENV, 'module'],
defaultProvider: 'jspm',
})

const htmlSource = await readFile(process.env.DEP, 'utf-8')

mkdirp.sync(dirname(process.env.TARGET))
await writeFile(
process.env.TARGET,
await generator.htmlGenerate(htmlSource, {
htmlUrl: pathToFileURL(process.env.TARGET),
preload: false,
integrity: false,
})
)
25 changes: 25 additions & 0 deletions web/jspm-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Generator } from '@jspm/generator'
import { writeFile } from 'fs/promises'
import mkdirp from 'mkdirp'
import { dirname } from 'path'

const NODE_ENV = process.env.NODE_ENV || 'development'

const generator = new Generator({
mapUrl: import.meta.url,
env: ['node', NODE_ENV, 'module'],
defaultProvider: 'jspm',
ignore: [
'mongodb',
'graphql',
'apollo-server-core',
'apollo-server-koa',
'koa-bodyparser',
'http-errors',
],
})

await Promise.all(process.env.DEPS.split(':').map(dep => generator.traceInstall('./' + dep)))

mkdirp.sync(dirname(process.env.TARGET))
await writeFile(process.env.TARGET, JSON.stringify(generator.getMap(), null, 2))
2 changes: 1 addition & 1 deletion web/server/lib/log-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as config from '../config/index.js'
const mask = str => str?.replace(/./g, '*').padEnd(60, '*')
const MASKED_FIELDS = config.DEPLOYMENT_ENV === 'production' ? ['KEY'] : []
const MASKED_FIELDS = config.DEPLOYMENT_ENV === 'production' ? ['KEY', 'MONGO_PASSWORD'] : []

console.info(
'Server configuration',
Expand Down

0 comments on commit c3ad996

Please sign in to comment.