Skip to content

Commit

Permalink
[TASK] big refactoring, update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh committed Jan 12, 2024
1 parent 2efe942 commit 2702457
Show file tree
Hide file tree
Showing 47 changed files with 3,836 additions and 4,022 deletions.
4 changes: 1 addition & 3 deletions lib/cmd/build.exec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import { config } from '../config/config.js'
import { build } from './build.js'

build({ config })
build()
25 changes: 10 additions & 15 deletions lib/cmd/build.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import { cleanVendorFolder } from '../compile/clean.js'
import '../utils/check.js'
import * as ui from '../utils/ui.js'
import { cleanVendorDestFolder } from '../compile/clean.js'
import { compileScss } from '../compile/sass.js'
import { compileCss } from '../compile/css.js'
import { compileJs } from '../compile/js.js'
import { confirmThemeName } from '../hubspot/helpers.js'
import { compileFieldsJs } from '../hubspot/fields.js'
import * as utils from '../utils/ui.js'
checkNode()
checkPackageThemeConsistent()

/**
* #### Build/compile all src CSS/JS/SCSS files
* @async
* @memberof Theme_Commands
* @param {Object} [opt] - local theme based config
* @returns undefined
* @example
* node build/build.js
*/
async function build (opt) {
await confirmThemeName()
const timeStart = utils.startTaskGroup('Build task')
await cleanVendorFolder()
async function build () {
const timeStart = ui.startTaskGroup('Build')
await cleanVendorDestFolder()
await compileScss()
await Promise.all([compileCss(), compileJs(opt), compileFieldsJs()])
utils.endTaskGroup({ taskName: 'Build task', timeStart })
await compileCss()
await compileJs()
await compileFieldsJs()
ui.endTaskGroup({ taskName: 'Build', timeStart })
}

export { build }
2 changes: 1 addition & 1 deletion lib/cmd/fetch.exec.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { hubspotFetchAll } from './fetchAll.js'
import { hubspotFetchAll } from './fetch.js'
hubspotFetchAll()
20 changes: 20 additions & 0 deletions lib/cmd/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import '../utils/check.js'
import themeName from '../hubspot/theme.js'
import { fetch } from '../hubspot/fetch.js'
import { loadAuthConfig } from '../hubspot/auth/auth.js'
import * as ui from '../utils/ui.js'

/**
* #### Fetch all theme files
* @async
* @memberof Theme_Commands
* @returns undefined
*/
async function hubspotFetchAll () {
const timeStart = ui.startTaskGroup(`Fetch all from ${themeName}`)
const hubAuthData = await loadAuthConfig(themeName)
await fetch(hubAuthData, themeName)
ui.endTaskGroup({ taskName: `Fetch all from ${themeName}`, timeStart })
}

export { hubspotFetchAll }
26 changes: 0 additions & 26 deletions lib/cmd/fetchAll.js

This file was deleted.

24 changes: 9 additions & 15 deletions lib/cmd/fetchModules.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import '../utils/check.js'
import themeName from '../hubspot/theme.js'
import { fetchModules } from '../hubspot/fetch.js'
import { globals } from '../config/globals.js'
import { getAuthConfig } from '../hubspot/auth.js'
import { confirmThemeName } from '../hubspot/helpers.js'
import * as utils from '../utils/ui.js'
checkNode()
checkPackageThemeConsistent()
import { loadAuthConfig } from '../hubspot/auth/auth.js'
import * as ui from '../utils/ui.js'

/**
* #### Fetch Modules from HUBSPOT cms portall
* #### Fetch only modules from HubSpot theme
* @async
* @memberof Theme_Commands
* @returns undefined
* @example
* node build/fetchModules.js
*/
async function hubspotFetchModules () {
await confirmThemeName()
const hubAuth = await getAuthConfig()
const timeStart = utils.startTaskGroup(`Fetch modules from ${globals.THEME_NAME}`)
await fetchModules(hubAuth)
utils.endTaskGroup({ taskName: `Fetch modules from ${globals.THEME_NAME}`, timeStart })
const timeStart = ui.startTaskGroup(`Fetch modules from ${themeName}`)
const hubAuthData = await loadAuthConfig(themeName)
await fetchModules(hubAuthData, themeName)
ui.endTaskGroup({ taskName: `Fetch modules from ${themeName}`, timeStart })
}

export { hubspotFetchModules }
15 changes: 5 additions & 10 deletions lib/cmd/fields.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import '../utils/check.js'
import { compileFieldsJs } from '../hubspot/fields.js'
import { confirmThemeName } from '../hubspot/helpers.js'
import * as utils from '../utils/ui.js'
checkNode()
checkPackageThemeConsistent()
import * as ui from '../utils/ui.js'

/**
* #### 'Compile fields.js to fields.json
* @async
* @memberof Theme_Commands
* @param {Object} [opt] - local theme based config
* @returns undefined
*/
async function fields (opt) {
await confirmThemeName()
const timeStart = utils.startTaskGroup('Compile fields.js to fields.json')
async function fields () {
const timeStart = ui.startTaskGroup('Compile fields.js')
await compileFieldsJs()
utils.endTaskGroup({ taskName: 'Compile fields.js to fields.json', timeStart })
ui.endTaskGroup({ taskName: 'Compile fields.js', timeStart })
}

export { fields }
3 changes: 1 addition & 2 deletions lib/cmd/lighthouse.exec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import { config } from '../config/config.js'
import { lighthouse } from './lighthouse.js'
lighthouse({ config })
lighthouse()
28 changes: 10 additions & 18 deletions lib/cmd/lighthouse.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import * as T from '../config/types.js' // eslint-disable-line
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import { lighthouseScore } from '../hubspot/lighthouse-score.js'
// import { globals } from '../config/globals.js'
import { getAuthConfig } from '../hubspot/auth.js'
import { confirmThemeName } from '../hubspot/helpers.js'
import * as utils from '../utils/ui.js'
checkNode()
checkPackageThemeConsistent()
import '../utils/check.js'
import themeName from '../hubspot/theme.js'
import { lighthouseScore } from '../hubspot/lighthouse.js'
import { loadAuthConfig } from '../hubspot/auth/auth.js'
import * as ui from '../utils/ui.js'

/**
* #### Get Lighthouse Score for theme
* @async
* @memberof Theme_Commands
* @param {T.THEME_BUILD_OPTIONS} opt - local theme based config
* @returns undefined
* @example
* node build/lighthouseScore.js
*/
async function lighthouse (opt) {
await confirmThemeName()
const hubAuth = await getAuthConfig()
const timeStart = utils.startTaskGroup('Lighthouse')
await lighthouseScore(hubAuth, opt)
utils.endTaskGroup({ taskName: 'Lighthouse', timeStart })
async function lighthouse () {
const timeStart = ui.startTaskGroup(`Lighthouse tests for ${themeName}`)
const hubAuthData = await loadAuthConfig(themeName)
await lighthouseScore(hubAuthData, themeName)
ui.endTaskGroup({ taskName: `Lighthouse tests for ${themeName}`, timeStart })
}

export { lighthouse }
4 changes: 1 addition & 3 deletions lib/cmd/upload.exec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import { config } from '../config/config.js'
import { upload } from './upload.js'

upload({ config })
upload()
33 changes: 14 additions & 19 deletions lib/cmd/upload.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import '../utils/check.js'
import themeName from '../hubspot/theme.js'
import { loadAuthConfig } from '../hubspot/auth/auth.js'
import { uploadTheme } from '../hubspot/upload.js'
import { cleanVendorFolder } from '../compile/clean.js'
import { cleanVendorDestFolder } from '../compile/clean.js'
import { compileScss } from '../compile/sass.js'
import { compileCss } from '../compile/css.js'
import { compileJs } from '../compile/js.js'
import { globals } from '../config/globals.js'
import { getAuthConfig } from '../hubspot/auth.js'
import { confirmThemeName } from '../hubspot/helpers.js'
import { compileFieldsJs } from '../hubspot/fields.js'
import * as utils from '../utils/ui.js'
checkNode()
checkPackageThemeConsistent()
import * as ui from '../utils/ui.js'

/**
* #### Upload theme to HUBSPOT cms portall
* @async
* @memberof Theme_Commands
* @param {object} [opt] - local theme based config
* @returns undefined
* @example
* node build/upload.js
*/
async function upload (opt) {
await confirmThemeName()
const hubAuth = await getAuthConfig()
const timeStart = utils.startTaskGroup(`Upload ${globals.THEME_NAME}`)
await cleanVendorFolder()
async function upload () {
const timeStart = ui.startTaskGroup(`Upload ${themeName}`)
const hubAuthData = await loadAuthConfig(themeName)
await cleanVendorDestFolder()
await compileScss()
await Promise.all([compileCss(), compileJs(opt), compileFieldsJs()])
await uploadTheme(hubAuth)
utils.endTaskGroup({ taskName: `Upload ${globals.THEME_NAME}`, timeStart })
await compileCss()
await compileJs()
await compileFieldsJs()
await uploadTheme(hubAuthData, themeName)
ui.endTaskGroup({ taskName: `Upload ${themeName}`, timeStart })
}

export { upload }
24 changes: 9 additions & 15 deletions lib/cmd/validate.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import { marketplaceValidate } from '../hubspot/marketplace-validate.js'
import { globals } from '../config/globals.js'
import { getAuthConfig } from '../hubspot/auth.js'
import { confirmThemeName } from '../hubspot/helpers.js'
import * as utils from '../utils/ui.js'
checkNode()
checkPackageThemeConsistent()
import '../utils/check.js'
import themeName from '../hubspot/theme.js'
import { marketplaceValidate } from '../hubspot/validate.js'
import { loadAuthConfig } from '../hubspot/auth/auth.js'
import * as ui from '../utils/ui.js'

/**
* #### Theme Validation
* @async
* @memberof Theme_Commands
* @returns undefined
* @example
* node build/validate.js
*/
async function validate () {
await confirmThemeName()
const hubAuth = await getAuthConfig()
const timeStart = utils.startTaskGroup(`Validation for ${globals.THEME_NAME}`)
await marketplaceValidate(hubAuth)
utils.endTaskGroup({ taskName: `Validation for ${globals.THEME_NAME}`, timeStart })
const timeStart = ui.startTaskGroup(`Validate ${themeName}`)
const hubAuthData = await loadAuthConfig(themeName)
await marketplaceValidate(hubAuthData, themeName)
ui.endTaskGroup({ taskName: `Validate ${themeName}`, timeStart })
}

export { validate }
4 changes: 1 addition & 3 deletions lib/cmd/watch.exec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import { config } from '../config/config.js'
import { watch } from './watch.js'

watch({ config })
watch()
22 changes: 8 additions & 14 deletions lib/cmd/watch.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { checkNode, checkPackageThemeConsistent } from '../utils/check.js'
import { watchSrc } from '../compile/watch.js'
import { getAuthConfig } from '../hubspot/auth.js'
import '../utils/check.js'
import themeName from '../hubspot/theme.js'
import { watchVendor } from '../compile/watch.js'
import { watchHubspotTheme } from '../hubspot/watch.js'
import { confirmThemeName } from '../hubspot/helpers.js'
checkNode()
checkPackageThemeConsistent()
import { loadAuthConfig } from '../hubspot/auth/auth.js'

/**
* #### Run watch process with css/js/scss compilation
* @async
* @memberof Theme_Commands
* @param {object} [opt] - local theme based config
* @returns undefined
* @example
* node build/watch.js
*/
async function watch (opt) {
await confirmThemeName()
const hubAuth = await getAuthConfig()
await watchSrc(opt)
await watchHubspotTheme(hubAuth)
async function watch () {
const hubAuthData = await loadAuthConfig(themeName)
await watchVendor()
await watchHubspotTheme(hubAuthData, themeName)
}

export { watch }
20 changes: 9 additions & 11 deletions lib/compile/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

import { deleteAsync } from 'del'
import fsPromises from 'fs/promises'
import { globals } from '../config/globals.js'
import * as utils from '../utils/ui.js'
import * as ui from '../utils/ui.js'
import { getThemeOptions } from '../utils/options.js'

/**
* #### clean all vendor folders
* @async
* @returns undefined
*/
async function cleanVendorFolder () {
async function cleanVendorDestFolder () {
try {
const timeStart = utils.startTask('cleanVendorFolder')

const themeVendor = globals.THEME_VENDOR
await fsPromises.mkdir(themeVendor, { recursive: true })
await deleteAsync([`${themeVendor}/*`], { force: true })

utils.endTask({ taskName: 'cleanVendorFolder', timeStart })
const timeStart = ui.startTask('cleanVendorDestFolder')
const options = getThemeOptions()
await fsPromises.mkdir(options.vendorDest, { recursive: true })
await deleteAsync([`${options.vendorDest}/*`], { force: true })
ui.endTask({ taskName: 'cleanVendorDestFolder', timeStart })
} catch (error) {
console.error(error)
}
}

export { cleanVendorFolder }
export { cleanVendorDestFolder }
Loading

0 comments on commit 2702457

Please sign in to comment.