-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from halfzebra/revising-template-structure
Revising template structure
- Loading branch information
Showing
27 changed files
with
995 additions
and
709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
elm-stuff/ | ||
template/ | ||
tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path') | ||
const spawn = require('cross-spawn') | ||
const argv = require('minimist')(process.argv.slice(2)) | ||
const version = require('../package.json').version | ||
const elmPlatformVersion = require('elm/package.json').version | ||
const commands = argv._ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const spawn = require('cross-spawn'); | ||
const argv = require('minimist')(process.argv.slice(2)); | ||
const version = require('../package.json').version; | ||
const elmPlatformVersion = require('elm/package.json').version; | ||
const commands = argv._; | ||
|
||
if (commands.length === 0) { | ||
console.log('\nUsage: create-elm-app <project-directory>\n') | ||
console.log('where <project-directory> is the name of the directory with your future project') | ||
console.log('\nElm Platform ' + elmPlatformVersion + '\n') | ||
console.log('create-elm-app@' + version + ' ' + path.resolve(__dirname, '..')) | ||
process.exit(1) | ||
console.log('\nUsage: create-elm-app <project-directory>\n'); | ||
console.log( | ||
'where <project-directory> is the name of the directory with your future project' | ||
); | ||
console.log('\nElm Platform ' + elmPlatformVersion + '\n'); | ||
console.log( | ||
'create-elm-app@' + version + ' ' + path.resolve(__dirname, '..') | ||
); | ||
process.exit(1); | ||
} | ||
|
||
spawn.sync( | ||
'node', | ||
[ path.resolve(__dirname, '../scripts/create'), commands ], | ||
{ stdio: 'inherit' } | ||
) | ||
spawn.sync('node', [path.resolve(__dirname, '../scripts/create'), commands], { | ||
stdio: 'inherit' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
function getClientEnvironment () { | ||
return Object | ||
.keys(process.env) | ||
.reduce((acc, current) => { | ||
acc[ `process.env.${current}` ] = `"${process.env[ current ]}"` | ||
return acc | ||
}, {}) | ||
'use strict'; | ||
|
||
function getClientEnvironment() { | ||
return Object.keys(process.env).reduce((acc, current) => { | ||
acc[`process.env.${current}`] = `"${process.env[current]}"`; | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
module.exports = getClientEnvironment | ||
module.exports = getClientEnvironment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,52 @@ | ||
const path = require('path') | ||
'use strict'; | ||
|
||
const appRoot = process.cwd() | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const url = require('url'); | ||
|
||
let paths = { | ||
appRoot, | ||
entry: path.resolve('./src/index.js'), | ||
dist: path.resolve('./dist'), | ||
template: path.resolve('./src/index.html'), | ||
favicon: path.resolve('./src/favicon.ico'), | ||
elmPkg: path.resolve('elm-package.json'), | ||
elmMake: require('elm/platform').executablePaths['elm-make'], | ||
servedPath: './' || process.env.SERVED_PATH | ||
// Make sure any symlinks in the project folder are resolved: | ||
// https://github.com/facebookincubator/create-react-app/issues/637 | ||
const appDirectory = fs.realpathSync(process.cwd()); | ||
const resolveApp = relativePath => path.resolve(appDirectory, relativePath); | ||
|
||
const envPublicUrl = process.env.PUBLIC_URL; | ||
|
||
function ensureSlash(path, needsSlash) { | ||
const hasSlash = path.endsWith('/'); | ||
if (hasSlash && !needsSlash) { | ||
return path.substr(path, path.length - 1); | ||
} else if (!hasSlash && needsSlash) { | ||
return `${path}/`; | ||
} | ||
return path; | ||
} | ||
|
||
module.exports = paths | ||
const getPublicUrl = appPackageJson => | ||
envPublicUrl || require(appPackageJson).homepage; | ||
|
||
// We use `PUBLIC_URL` environment variable or "homepage" field to infer | ||
// "public path" at which the app is served. | ||
// Webpack needs to know it to put the right <script> hrefs into HTML even in | ||
// single-page apps that may serve index.html for nested URLs like /todos/42. | ||
// We can't use a relative path in HTML because we don't want to load something | ||
// like /todos/42/static/js/bundle.7289d.js. We have to know the root. | ||
function getServedPath(appPackageJson) { | ||
const publicUrl = getPublicUrl(appPackageJson); | ||
const servedUrl = | ||
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); | ||
return ensureSlash(servedUrl, true); | ||
} | ||
|
||
module.exports = { | ||
appPath: resolveApp('.'), | ||
appPublic: resolveApp('./public'), | ||
appHtml: resolveApp('./public/index.html'), | ||
appIndexJs: resolveApp('./src/index.js'), | ||
appSrc: resolveApp('./src'), | ||
entry: resolveApp('./src/index.js'), | ||
appBuild: resolveApp('./build'), | ||
elmPackageJson: resolveApp('./elm-package.json'), | ||
elmMake: require('elm/platform').executablePaths['elm-make'], | ||
publicUrl: getPublicUrl(resolveApp('elm-package.json')), | ||
servedPath: getServedPath(resolveApp('elm-package.json')) | ||
}; |
Oops, something went wrong.