Skip to content

Commit

Permalink
Make --force skip project name confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
danneu committed Aug 26, 2018
1 parent e547a74 commit dbb23e6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -86,9 +86,9 @@ Here's the generated project folder:
├── webpack.config.js
├── src # your elm code/components go in here
│   ├── Main.elm # root elm component, begin hacking here
│   ├── index.html # root html file, Main.elm mounts to it
│   └── index.js # root javascript file, webpack entrypoint
├── public
│   ├── index.html # root html file, Main.elm mounts to it
│   ├── favicon.ico # a default favicon for you to replace
│   ├── css
│   │   └── index.scss # root css file that should @import other css files
Expand Down
15 changes: 13 additions & 2 deletions generators/app/index.js
Expand Up @@ -14,6 +14,12 @@ module.exports = class extends Generator {
required: true,
desc: 'Where to generate the project (folder name, ".", or path)',
})

this.option('force', {
desc:
'Skip project name confirmation and always overwrite on file conflicts',
default: false,
})
}

initializing() {
Expand All @@ -31,6 +37,11 @@ module.exports = class extends Generator {
}

async prompting() {
if (this.options.force) {
this.log('Skipping project name prompt because --force flag was given...')
return
}

const props = await this.prompt([
{
type: 'input',
Expand Down Expand Up @@ -60,13 +71,13 @@ module.exports = class extends Generator {
copyTpl('package.json')
copyTpl('webpack.config.js')
// dotfiles
copyTpl('.gitignore')
copyTpl('_gitignore', '.gitignore')
copyTpl('.eslintrc.json')
// src
copyTpl('src/Main.elm')
copyTpl('src/index.html')
copyTpl('src/index.js')
// public
copyTpl('public/index.html')
copyTpl('public/css/index.scss')
// binary data (cannot use copyTpl)
this.fs.copy(
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions generators/app/templates/public/css/index.scss
@@ -0,0 +1,5 @@
/*
Example, this will inline './child.scss':
@import 'child';
*/
File renamed without changes.
26 changes: 9 additions & 17 deletions generators/app/templates/src/Main.elm
@@ -1,20 +1,19 @@
module Main exposing (..)

import Html.Events as Events
import Html exposing (Html)
import Html.Attributes
import Html exposing (Html, div, img, text)
import Html.Attributes as Attr


-- MODEL


type alias Model =
{ counter : Int }
{}


init : ( Model, Cmd Msg )
init =
( { counter = 99 }
( {}
, Cmd.none
)

Expand All @@ -25,7 +24,6 @@ init =

type Msg
= NoOp
| Increment


update : Msg -> Model -> ( Model, Cmd Msg )
Expand All @@ -34,27 +32,21 @@ update msg model =
NoOp ->
( model, Cmd.none )

Increment ->
( { model | counter = model.counter + 1 }, Cmd.none )



-- VIEW


view : Model -> Html Msg
view model =
Html.div
div
[]
[ Html.img
[ Html.Attributes.src "/img/elm.png"
, Html.Attributes.style [ ( "border", "1px solid black" ) ]
[ img
[ Attr.src "/img/elm.png"
, Attr.style [ ( "border", "1px solid black" ) ]
]
[]
, Html.text " Hello world"
, Html.button
[ Events.onClick Increment ]
[ Html.text ("Increment " ++ toString model.counter) ]
, text "Hello world"
]


Expand Down
4 changes: 2 additions & 2 deletions generators/app/templates/src/index.js
@@ -1,5 +1,5 @@
require('../public/css/index.scss')

const Elm = require('./Main.elm')
const { Main } = require('./Main.elm')

const app = Elm.Main.embed(document.querySelector('#main'))
const app = Main.embed(document.querySelector('#main'))
4 changes: 2 additions & 2 deletions generators/app/templates/webpack.config.js
Expand Up @@ -64,7 +64,7 @@ const common = (env, argv) => {
{
test: /\.js$/,
exclude: /node_modules/,
include: [path.resolve(__dirname, 'src')],
include: [path.resolve(__dirname, 'public')],
use: {
loader: 'babel-loader',
options: {
Expand Down Expand Up @@ -108,7 +108,7 @@ const common = (env, argv) => {

new HtmlWebpackPlugin({
title: '<%= projectName %>',
template: 'src/index.html',
template: 'public/index.html',
}),

new CopyWebpackPlugin([
Expand Down

0 comments on commit dbb23e6

Please sign in to comment.