Skip to content

Commit

Permalink
feat: expose generateScripts and generateStyles methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Jul 31, 2024
1 parent 9461ac5 commit 455394d
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ module.exports = function defineShipwrightHook(sails) {
const files = data.allFiles
return files
}
function generateScripts() {
const manifestFiles = getManifestFiles()
let scripts = []
manifestFiles.forEach((file) => {
if (file.endsWith('.js')) {
scripts.push(`<script type="text/javascript" src="${file}"></script>`)
}
})
return scripts.join('\n')
}

function generateStyles() {
const manifestFiles = getManifestFiles()
let styles = []
manifestFiles.forEach((file) => {
if (file.endsWith('.css')) {
styles.push(`<link rel="stylesheet" href="${file}">`)
}
})
return styles.join('\n')
}
return {
generateScripts: function generateScripts() {
const manifestFiles = getManifestFiles()
let scripts = []
manifestFiles.forEach((file) => {
if (file.endsWith('.js')) {
scripts.push(`<script type="text/javascript" src="${file}"></script>`)
}
})
return scripts.join('\n')
},
generateStyles: function generateStyles() {
const manifestFiles = getManifestFiles()
let styles = []
manifestFiles.forEach((file) => {
if (file.endsWith('.css')) {
styles.push(`<link rel="stylesheet" href="${file}">`)
}
})
return styles.join('\n')
},
defaults: {
shipwright: {
build: {}
Expand All @@ -50,6 +50,7 @@ module.exports = function defineShipwrightHook(sails) {
* Runs when this Sails app loads/lifts.
*/
initialize: async function () {
const hook = this
const appPath = sails.config.appPath
const defaultConfigs = defineConfig({
source: {
Expand Down Expand Up @@ -139,7 +140,10 @@ module.exports = function defineShipwrightHook(sails) {
sails.after('lifted', () => {})
}
sails.config.views.locals = {
shipwright: { scripts: generateScripts, styles: generateStyles }
shipwright: {
scripts: hook.generateScripts,
styles: hook.generateStyles
}
}
} catch (error) {
sails.log.error(error)
Expand Down

0 comments on commit 455394d

Please sign in to comment.