Skip to content

Commit

Permalink
start reorganizing the constructor vs init/start concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
Autre31415 committed Jan 9, 2025
1 parent bb29b6c commit e3bbf80
Show file tree
Hide file tree
Showing 5 changed files with 2,218 additions and 1,472 deletions.
16 changes: 8 additions & 8 deletions lib/preprocessCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = async app => {
const cssPath = app.get('cssPath')
const cssCompiledOutput = app.get('cssCompiledOutput')
const usingAllowlist = !!params.css.allowlist
const allowlist = app.get('params').css.allowlist
const allowlist = params.css.allowlist
const logger = app.get('logger')
const fsr = require('./tools/fsr')(app)
let preprocessorModule
Expand Down Expand Up @@ -60,10 +60,10 @@ module.exports = async app => {
// determine which preprocessor is in use and abstract a generic api for it
if (moduleName === 'less') {
preprocessorModule = {
versionCode: app => `@${app.get('params').css.versionFile.varName}: '${app.get('appVersion')}';\n`,
versionCode: app => `@${params.css.versionFile.varName}: '${app.get('appVersion')}';\n`,
parse: (app, file) => {
return new Promise((resolve, reject) => {
const compilerOptions = app.get('params').css.compiler.options
const compilerOptions = params.css.compiler.options
const env = app.get('env')

// set less options based on roosevelt config
Expand Down Expand Up @@ -96,11 +96,11 @@ module.exports = async app => {
}
} else if (moduleName === 'sass') {
preprocessorModule = {
versionCode: app => `$${app.get('params').css.versionFile.varName}: '${app.get('appVersion')}';\n`,
versionCode: app => `$${params.css.versionFile.varName}: '${app.get('appVersion')}';\n`,
parse: (app, file) => {
return new Promise((resolve, reject) => {
const env = app.get('env')
const compilerOptions = app.get('params').css.compiler.params
const compilerOptions = params.css.compiler.params
const options = {
...compilerOptions,
file: path.basename(file),
Expand Down Expand Up @@ -132,10 +132,10 @@ module.exports = async app => {
}
} else if (moduleName === 'stylus') {
preprocessorModule = {
versionCode: app => `${app.get('params').css.versionFile.varName} = '${app.get('appVersion')}';\n`,
versionCode: app => `${params.css.versionFile.varName} = '${app.get('appVersion')}';\n`,
parse: (app, file) => {
return new Promise((resolve, reject) => {
const compilerOptions = app.get('params').css.compiler.options
const compilerOptions = params.css.compiler.options
const env = app.get('env')

// set less options based on roosevelt config
Expand Down Expand Up @@ -231,7 +231,7 @@ module.exports = async app => {
}
}
try {
let baseFile = file.replace(app.get('params').css.sourcePath + path.sep, '')
let baseFile = file.replace(params.css.sourcePath + path.sep, '')

// update filepath on windows
if (process.platform === 'win32') baseFile = baseFile.replaceAll('\\', '/')
Expand Down
44 changes: 3 additions & 41 deletions lib/sourceParams.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// reads user supplied params from roosevelt constructor or from the app's package.json and configures the app
require('@colors/colors')
const path = require('path')
const appModulePath = require('app-module-path')
const Logger = require('roosevelt-logger')
const sourceConfigs = require('source-configs')
const defaults = require('./defaults/config')
const template = require('./tools/templateLiteralRenderer')

module.exports = (params, app, appSchema) => {
module.exports = (params, appSchema) => {
const appDir = params.appDir

// determine if app has a package.json
Expand Down Expand Up @@ -417,6 +415,7 @@ module.exports = (params, app, appSchema) => {
params.js.sourcePath = path.join(params.staticsRoot, params.js.sourcePath)
params.clientViews.output = path.join(params.publicFolder, params.clientViews.output)
params.isomorphicControllers.output = path.join(params.publicFolder, params.isomorphicControllers.output)
params.pkg = pkg

// scan for variables in params and resolve them
const configTemplateLiterals = []
Expand Down Expand Up @@ -465,9 +464,6 @@ module.exports = (params, app, appSchema) => {
if (passes > 0) paramVariables(params)
})(params)

// configure logger with params
const logger = new Logger(params.logging)

// set mode specific overrides
if (params.mode === 'production' || params.mode === 'production-proxy') {
process.env.NODE_ENV = 'production'
Expand Down Expand Up @@ -515,46 +511,12 @@ module.exports = (params, app, appSchema) => {
params.routePrefix = ''
}

// make the app directory requirable
appModulePath.addPath(appDir)

// make the models directory requirable
appModulePath.addPath(path.join(appDir, params.modelsPath, '../'))

// make the controllers directory requirable
appModulePath.addPath(path.join(appDir, params.controllersPath, '../'))

// expose express variables
if (app) {
app.set('env', params.mode === 'production-proxy' ? 'production' : params.mode)
app.set('logger', logger) // expose instance of roosevelt-logger module
app.set('params', params) // expose app configuration
app.set('appDir', appDir)
app.set('package', pkg) // expose contents of package.json if any
app.set('appName', pkg.name || 'Roosevelt Express')
app.set('appVersion', pkg.version)
app.set('routePrefix', params.routePrefix)
app.set('modelsPath', path.join(appDir, params.modelsPath))
app.set('viewsPath', path.join(appDir, params.viewsPath))
app.set('controllersPath', path.join(appDir, params.controllersPath))
app.set('staticsRoot', params.staticsRoot)
app.set('htmlPath', params.html.sourcePath)
app.set('htmlModels', params.html.models)
app.set('cssPath', params.css.sourcePath)
app.set('jsPath', params.js.sourcePath)
app.set('htmlRenderedOutput', params.html.output)
app.set('cssCompiledOutput', params.css.output)
app.set('clientViewsBundledOutput', params.clientViews.output)
app.set('isomorphicControllersListOutput', params.isomorphicControllers.output)
app.set('publicFolder', params.unversionedPublic)
}

// goes through all config variables and checks if it exists
let extract
for (const row in configTemplateLiterals) {
extract = configTemplateLiterals[row].match(/\${(.*)}/).pop()
const ex = getOrSetObjectByDotNotation(params, extract)
if (!ex) logger.warn(`Config variable ${extract} does not exist.`)
if (!ex) console.warn(`Config variable ${extract} does not exist.`)
}
return params
}
Expand Down
Loading

0 comments on commit e3bbf80

Please sign in to comment.