Skip to content

Commit 167f0c1

Browse files
authored
Merge pull request #138 from halfzebra/revising-template-structure
Revising template structure
2 parents 4e9e42e + db88cbb commit 167f0c1

27 files changed

+995
-709
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
elm-stuff/
2+
template/
3+
tests/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ elm-stuff
8989
repl-temp-*
9090

9191
# create-elm-app
92-
template/dist
92+
template/build
9393
template/package.json
94+
template/scripts/
95+
template/config/
9496

9597
# Desktop Services Store on macOS
9698
.DS_Store

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ Create a production build with `elm-app build`
1919
## Getting Started
2020

2121
### Installation
22-
Node >=4 is required only as a build dependency.
2322

23+
Node >=6 is required as a dependency.
24+
25+
#### Yarn
26+
27+
`yarn global add create-elm-app`
28+
29+
#### NPM
2430
`npm install create-elm-app -g`
2531

2632
If you are running Linux OS, you should install it as the superuser:
@@ -45,10 +51,11 @@ my-app/
4551
.gitignore
4652
README.md
4753
elm-package.json
48-
src/
49-
App.elm
54+
public/
5055
favicon.ico
5156
index.html
57+
src/
58+
App.elm
5259
index.js
5360
main.css
5461
tests/
@@ -105,12 +112,23 @@ Inspired by [create-react-app](https://github.com/facebookincubator/create-react
105112

106113
* **No Lock-In:** You can “eject” to a custom setup at any time. Run a single command, and all the configuration and build dependencies will be moved directly into your project, so you can pick up right where you left off.
107114

115+
## What is inside
116+
117+
The tools used by Create React App are subject to change.
118+
Currently it is a thin layer on top of many amazing community projects, such as:
119+
120+
* [elm-platform](https://github.com/elm-lang/elm-platform)
121+
* [elm-test](https://github.com/elm-community/elm-test)
122+
* [webpack](https://webpack.js.org/) with [webpack-dev-server](https://github.com/webpack/webpack-dev-server), [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) and [style-loader](https://github.com/webpack/style-loader)
123+
* [Babel](http://babeljs.io/) with ES6
124+
* [Autoprefixer](https://github.com/postcss/autoprefixer)
125+
* and others.
126+
127+
All of them are transitive dependencies of the provided npm package.
128+
108129
## Contributing
109130
We would love to get you involved! Please check our [Contributing Guide](CONTRIBUTING.md) to get started!
110131

111-
## What is inside
112-
This tool contains a local installation of [elm-platform](https://github.com/elm-lang/elm-platform) and heavily relies on [webpack](https://github.com/webpack/webpack) in the build process.
113-
114132
## Alternatives
115133
- [elm-webpack-starter](https://github.com/moarwick/elm-webpack-starter)
116134
- [elm-app-boilerplate](https://github.com/gkubisa/elm-app-boilerplate)

bin/create-elm-app-cli.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
#!/usr/bin/env node
22

3-
const path = require('path')
4-
const spawn = require('cross-spawn')
5-
const argv = require('minimist')(process.argv.slice(2))
6-
const version = require('../package.json').version
7-
const elmPlatformVersion = require('elm/package.json').version
8-
const commands = argv._
3+
'use strict';
4+
5+
const path = require('path');
6+
const spawn = require('cross-spawn');
7+
const argv = require('minimist')(process.argv.slice(2));
8+
const version = require('../package.json').version;
9+
const elmPlatformVersion = require('elm/package.json').version;
10+
const commands = argv._;
911

1012
if (commands.length === 0) {
11-
console.log('\nUsage: create-elm-app <project-directory>\n')
12-
console.log('where <project-directory> is the name of the directory with your future project')
13-
console.log('\nElm Platform ' + elmPlatformVersion + '\n')
14-
console.log('create-elm-app@' + version + ' ' + path.resolve(__dirname, '..'))
15-
process.exit(1)
13+
console.log('\nUsage: create-elm-app <project-directory>\n');
14+
console.log(
15+
'where <project-directory> is the name of the directory with your future project'
16+
);
17+
console.log('\nElm Platform ' + elmPlatformVersion + '\n');
18+
console.log(
19+
'create-elm-app@' + version + ' ' + path.resolve(__dirname, '..')
20+
);
21+
process.exit(1);
1622
}
1723

18-
spawn.sync(
19-
'node',
20-
[ path.resolve(__dirname, '../scripts/create'), commands ],
21-
{ stdio: 'inherit' }
22-
)
24+
spawn.sync('node', [path.resolve(__dirname, '../scripts/create'), commands], {
25+
stdio: 'inherit'
26+
});

bin/elm-app-cli.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
#!/usr/bin/env node
22

3-
const path = require('path')
4-
const spawn = require('cross-spawn')
5-
const argv = require('minimist')(process.argv.slice(2))
6-
const executablePaths = require('elm/platform').executablePaths
3+
'use strict';
74

8-
const version = require('../package.json').version
9-
const elmPlatformVersion = require('elm/package.json').version
5+
const path = require('path');
6+
const spawn = require('cross-spawn');
7+
const argv = require('minimist')(process.argv.slice(2));
8+
const executablePaths = require('elm/platform').executablePaths;
9+
const version = require('../package.json').version;
10+
const elmPlatformVersion = require('elm/package.json').version;
1011

11-
const commands = argv._
12+
const commands = argv._;
1213

1314
if (commands.length === 0) {
14-
help(version)
15-
process.exit(1)
15+
help(version);
16+
process.exit(1);
1617
}
1718

18-
const script = commands[ 0 ]
19-
const scriptArgs = commands.splice(1)
19+
const script = commands[0];
20+
const scriptArgs = commands.splice(1);
2021

2122
switch (script) {
2223
case 'create':
2324
case 'build':
2425
case 'eject':
2526
case 'start':
2627
spawnSyncNode(path.resolve(__dirname, '../scripts', script), scriptArgs);
27-
break
28+
break;
2829

2930
case 'test': {
30-
let args = []
31-
Object.keys(argv || {}).forEach(function (key) {
31+
let args = [];
32+
Object.keys(argv || {}).forEach(key => {
3233
if (key !== '_' && key !== 'compiler') {
33-
args = args.concat([ '--' + key, argv[ key ] ])
34+
args = args.concat(['--' + key, argv[key]]);
3435
}
35-
})
36+
});
3637

37-
args = args.concat([ '--compiler', path.normalize(executablePaths[ 'elm-make' ]) ])
38+
args = args.concat([
39+
'--compiler',
40+
path.normalize(executablePaths['elm-make'])
41+
]);
3842

39-
const cp = spawn.sync(
40-
require.resolve('elm-test/bin/elm-test'),
41-
args,
42-
{ stdio: 'inherit' }
43-
)
43+
const cp = spawn.sync(require.resolve('elm-test/bin/elm-test'), args, {
44+
stdio: 'inherit'
45+
});
4446

4547
if (cp.status !== 0) {
46-
process.exit(cp.status)
48+
process.exit(cp.status);
4749
}
4850

49-
break
51+
break;
5052
}
5153
default:
5254
// Proxy elm-platform cli commands.
53-
if ([ 'package', 'reactor', 'make', 'repl' ].indexOf(script) !== -1) {
54-
const executable = executablePaths[ 'elm-' + script ]
55+
if (['package', 'reactor', 'make', 'repl'].indexOf(script) !== -1) {
56+
const executable = executablePaths['elm-' + script];
5557

56-
spawn.sync(
57-
path.normalize(executable),
58-
process.argv.slice(3),
59-
{ stdio: 'inherit' }
60-
)
61-
break
58+
spawn.sync(path.normalize(executable), process.argv.slice(3), {
59+
stdio: 'inherit'
60+
});
61+
break;
6262
} else {
63-
help(version)
64-
process.exit(1)
63+
help(version);
64+
process.exit(1);
6565
}
6666
}
6767

@@ -71,12 +71,14 @@ switch (script) {
7171
* @param {string} version [description]
7272
* @return {undefined}
7373
*/
74-
function help (version) {
75-
console.log('\nUsage: elm-app <command>\n')
76-
console.log('where <command> is one of:')
77-
console.log(' create, build, start, package, reactor, make, repl\n')
78-
console.log('\nElm ' + elmPlatformVersion + '\n')
79-
console.log('create-elm-app@' + version + ' ' + path.resolve(__dirname, '..'))
74+
function help(version) {
75+
console.log('\nUsage: elm-app <command>\n');
76+
console.log('where <command> is one of:');
77+
console.log(' create, build, start, package, reactor, make, repl\n');
78+
console.log('\nElm ' + elmPlatformVersion + '\n');
79+
console.log(
80+
'create-elm-app@' + version + ' ' + path.resolve(__dirname, '..')
81+
);
8082
}
8183

8284
/**
@@ -86,14 +88,12 @@ function help (version) {
8688
* @param {Arrays} args Script arguments
8789
* @return {undefined}
8890
*/
89-
function spawnSyncNode (script, args) {
90-
const cp = spawn.sync(
91-
'node',
92-
[ script ].concat(args || []),
93-
{ stdio: 'inherit' }
94-
)
91+
function spawnSyncNode(script, args) {
92+
const cp = spawn.sync('node', [script].concat(args || []), {
93+
stdio: 'inherit'
94+
});
9595

9696
if (cp.status !== 0) {
97-
process.exit(cp.status)
97+
process.exit(cp.status);
9898
}
9999
}

config/env.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function getClientEnvironment () {
2-
return Object
3-
.keys(process.env)
4-
.reduce((acc, current) => {
5-
acc[ `process.env.${current}` ] = `"${process.env[ current ]}"`
6-
return acc
7-
}, {})
1+
'use strict';
2+
3+
function getClientEnvironment() {
4+
return Object.keys(process.env).reduce((acc, current) => {
5+
acc[`process.env.${current}`] = `"${process.env[current]}"`;
6+
return acc;
7+
}, {});
88
}
99

10-
module.exports = getClientEnvironment
10+
module.exports = getClientEnvironment;

config/paths.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
1-
const path = require('path')
1+
'use strict';
22

3-
const appRoot = process.cwd()
3+
const path = require('path');
4+
const fs = require('fs');
5+
const url = require('url');
46

5-
let paths = {
6-
appRoot,
7-
entry: path.resolve('./src/index.js'),
8-
dist: path.resolve('./dist'),
9-
template: path.resolve('./src/index.html'),
10-
favicon: path.resolve('./src/favicon.ico'),
11-
elmPkg: path.resolve('elm-package.json'),
12-
elmMake: require('elm/platform').executablePaths['elm-make'],
13-
servedPath: './' || process.env.SERVED_PATH
7+
// Make sure any symlinks in the project folder are resolved:
8+
// https://github.com/facebookincubator/create-react-app/issues/637
9+
const appDirectory = fs.realpathSync(process.cwd());
10+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
11+
12+
const envPublicUrl = process.env.PUBLIC_URL;
13+
14+
function ensureSlash(path, needsSlash) {
15+
const hasSlash = path.endsWith('/');
16+
if (hasSlash && !needsSlash) {
17+
return path.substr(path, path.length - 1);
18+
} else if (!hasSlash && needsSlash) {
19+
return `${path}/`;
20+
}
21+
return path;
1422
}
1523

16-
module.exports = paths
24+
const getPublicUrl = appPackageJson =>
25+
envPublicUrl || require(appPackageJson).homepage;
26+
27+
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
28+
// "public path" at which the app is served.
29+
// Webpack needs to know it to put the right <script> hrefs into HTML even in
30+
// single-page apps that may serve index.html for nested URLs like /todos/42.
31+
// We can't use a relative path in HTML because we don't want to load something
32+
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
33+
function getServedPath(appPackageJson) {
34+
const publicUrl = getPublicUrl(appPackageJson);
35+
const servedUrl =
36+
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
37+
return ensureSlash(servedUrl, true);
38+
}
39+
40+
module.exports = {
41+
appPath: resolveApp('.'),
42+
appPublic: resolveApp('./public'),
43+
appHtml: resolveApp('./public/index.html'),
44+
appIndexJs: resolveApp('./src/index.js'),
45+
appSrc: resolveApp('./src'),
46+
entry: resolveApp('./src/index.js'),
47+
appBuild: resolveApp('./build'),
48+
elmPackageJson: resolveApp('./elm-package.json'),
49+
elmMake: require('elm/platform').executablePaths['elm-make'],
50+
publicUrl: getPublicUrl(resolveApp('elm-package.json')),
51+
servedPath: getServedPath(resolveApp('elm-package.json'))
52+
};

0 commit comments

Comments
 (0)