Skip to content
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
11 changes: 6 additions & 5 deletions src/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const reserved = {

const root = path.join(__dirname, '..', '..')
const cwd = process.cwd()
export const dotElmSpa = path.join(cwd, '.elm-spa');

const config = {
reserved,
Expand All @@ -16,18 +17,18 @@ const config = {
src: path.join(cwd, 'src'),
pages: {
src: path.join(cwd, 'src', 'Pages'),
defaults: path.join(cwd, '.elm-spa', 'defaults', 'Pages')
defaults: path.join(dotElmSpa, 'defaults', 'Pages')
},
defaults: {
src: path.join(root, 'src', 'defaults'),
dest: path.join(cwd, '.elm-spa', 'defaults')
dest: path.join(dotElmSpa, 'defaults')
},
generated: path.join(cwd, '.elm-spa', 'generated'),
generated: path.join(dotElmSpa, 'generated'),
templates: {
defaults: path.join(root, 'src', 'templates', 'add'),
user: path.join(cwd, '.elm-spa', 'templates')
user: path.join(dotElmSpa, 'templates')
},
package: path.join(cwd, '.elm-spa', 'package'),
package: path.join(dotElmSpa, 'package'),
public: path.join(cwd, 'public'),
dist: path.join(cwd, 'public', 'dist'),
},
Expand Down
18 changes: 15 additions & 3 deletions src/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node

import CLI from './cli'
import { dotElmSpa } from './config'
import { checkIfFolderExists } from './file'
import { Commands } from './types'

const commands : Commands = {
const commands: Commands = {
new: CLI.new,
add: CLI.add,
build: CLI.build,
Expand All @@ -16,13 +18,23 @@ const commands : Commands = {
make: CLI.build,
}

const command : string | undefined = process.argv[2]
const commandsNotRequiringInitialization = ['new', 'init', 'help']

const command: string | undefined = process.argv[2]

Promise.resolve(command)
.then(async cmd => {
if (!commandsNotRequiringInitialization.includes(cmd as string)) {
if (!await checkIfFolderExists(dotElmSpa)) {
throw ' This command must be run in a project folder containing a .elm-spa folder.'
}
}
return cmd
})
.then(cmd => commands[cmd as keyof Commands] || commands.help)
.then(task => task())
.then(output => {
const message = output instanceof Array ? output : [ output ]
const message = output instanceof Array ? output : [output]
console.info('')
console.info(message.join('\n\n'))
})
Expand Down