Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

add nobundle and sourcesLocation argument #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class Bundle extends Command {
static flags = {
help: flags.help({char: 'h'}),
folder: flags.string({description: 'Subfolder to output to', required: false}),
sourceslocation: flags.string({description: 'Subfolder where sources are located', required: false}),
};

async run() {
Expand All @@ -28,7 +29,7 @@ export default class Bundle extends Command {
this.log()

const execTime = this.time('Execution time', Utils.headingFormat)
await this.bundleSources(flags.folder)
await this.bundleSources(flags.folder, flags.sourceslocation)

const versionTime = this.time('Versioning File', Utils.headingFormat)
await this.generateVersioningFile(flags.folder)
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class Bundle extends Command {
})
}

async bundleSources(folder = '') {
async bundleSources(folder = '', sourcesLocation = '') {
const basePath = process.cwd()

// Make sure there isn't a built folder already
Expand All @@ -127,25 +128,47 @@ export default class Bundle extends Command {

fs.mkdirSync(bundlesPath, {recursive: true})

const directoryPath = path.join(basePath, 'temp_build')
const promises: Promise<void>[] = fs.readdirSync(directoryPath).map(async file => {
const fileBundleTime = this.time(`- Building ${file}`)
if (sourcesLocation === '') {
const directoryPath = path.join(basePath, 'temp_build')
const promises: Promise<void>[] = fs.readdirSync(directoryPath).map(async file => {
const fileBundleTime = this.time(`- Building ${file}`)

Utils.copyFolderRecursive(
path.join(basePath, 'src', file, 'external'),
path.join(directoryPath, file)
)
Utils.copyFolderRecursive(
path.join(basePath, 'src', file, 'external'),
path.join(directoryPath, file)
)

await this.bundle(file, directoryPath, bundlesPath)
await this.bundle(file, directoryPath, bundlesPath)

Utils.copyFolderRecursive(
path.join(basePath, 'src', file, 'includes'),
path.join(bundlesPath, file)
)
fileBundleTime.end()
})
Utils.copyFolderRecursive(
path.join(basePath, 'src', file, 'includes'),
path.join(bundlesPath, file)
)
fileBundleTime.end()
})

await Promise.all(promises)
await Promise.all(promises)
} else {
const directoryPath = path.join(basePath, 'temp_build', sourcesLocation)
const promises: Promise<void>[] = fs.readdirSync(directoryPath).map(async file => {
const fileBundleTime = this.time(`- Building ${file}`)

Utils.copyFolderRecursive(
path.join(basePath, 'src', sourcesLocation, file, 'external'),
path.join(directoryPath, file)
)

await this.bundle(file, directoryPath, bundlesPath)

Utils.copyFolderRecursive(
path.join(basePath, 'src', sourcesLocation, file, 'includes'),
path.join(bundlesPath, file)
)
fileBundleTime.end()
})

await Promise.all(promises)
}

bundleTime.end()

Expand Down
17 changes: 11 additions & 6 deletions src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Serve extends Command {
static flags = {
help: flags.help({char: 'h'}),
port: flags.integer({char: 'p', default: 8080}),
nobundle: flags.boolean({description: 'Prevent bundling when launching serve. Will use existing bundle. Make sure that it\'s present.', default: false}),
}

async run() {
Expand All @@ -20,10 +21,13 @@ export default class Serve extends Command {
// eslint-disable-next-line no-console
console.clear()

this.log(chalk.underline.blue('Building Sources'))
if (flags.nobundle) {
this.log(chalk.underline.blue('nobundle argument detected => NOT building sources, make sure that a bundle is present.'))
} else {
this.log(chalk.underline.blue('Building Sources'))
await Bundle.run([])
}

// Make sure the repo is bundled
await Bundle.run([])
this.log()
this.log(chalk.underline.blue('Starting Server on port ' + flags.port))

Expand Down Expand Up @@ -57,9 +61,10 @@ export default class Serve extends Command {

this.log(chalk.underline.blue('Building Sources'))

// Make sure the repo is bundled
// eslint-disable-next-line no-await-in-loop
await Bundle.run()
if (!flags.nobundle) {
// eslint-disable-next-line no-await-in-loop
await Bundle.run([])
}
this.log()
this.log(chalk.underline.blue('Starting Server on port ' + flags.port))

Expand Down