Skip to content

Commit

Permalink
working version
Browse files Browse the repository at this point in the history
  • Loading branch information
jjurman committed Sep 10, 2017
1 parent 9d9d846 commit d8976fc
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 216 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tram-one-example

# Logs
logs
*.log
Expand Down
Empty file added README.md
Empty file.
64 changes: 0 additions & 64 deletions generate.js

This file was deleted.

41 changes: 41 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env node

const fs = require('fs')
const path = require('path')

const appTitle = process.argv[2] || 'tram-one-app'

const processFile = (file, currentPath) => {
const filePath = path.join(currentPath, file)
const newFilePath = filePath
.replace(path.join(__dirname, 'template'), path.join(process.cwd(), appTitle))

// copy a directory
if (fs.existsSync(filePath) && fs.statSync(filePath).isDirectory()) {
// make the directory
if (fs.existsSync(newFilePath)) {
console.warn(`Folder ${newFilePath} already exists`)
} else {
fs.mkdirSync(newFilePath)
}

// process all the files in the directory
const files = fs.readdirSync(filePath)
files.forEach((file) => processFile(file, filePath))
return
}

// copy a file
const normalFile = fs.readFileSync(filePath)
.toString()
.replace('%TITLE%', appTitle)
if (fs.existsSync(newFilePath)) {
console.warn(`File ${newFilePath} already exists`)
} else {
fs.appendFileSync(newFilePath, normalFile)
}
}

const filePath = path.join(__dirname, 'template')
console.log(`${Creating} appTitle`)
processFile('', filePath)
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "tram-one-express",
"version": "1.0.7",
"version": "2.0.0",
"description": "Generator to build Tram-One applications quickly",
"bin": "./prompts.js",
"bin": "./generator.js",
"files": [
"template",
"generate.js",
"prompts.js"
"generator.js"
],
"main": "prompts.js",
"main": "generator.js",
"keywords": [
"tram-one",
"generator"
],
"scripts": {
"clean": "rm -rf ./tram-one-example",
"start": "node prompts.js",
"start": "node generator tram-one-example",
"poststart": "npm --prefix ./tram-one-example install ./tram-one-example",
"example-start": "npm --prefix ./tram-one-example start",
"example-test": "npm --prefix ./tram-one-example test"
},
"author": "Jesse Jurman",
"license": "MIT",
"dependencies": {
"inquirer": "^3.2.2"
"inquirer": "^3.2.2",
"mem-fs": "^1.1.3",
"mem-fs-editor": "^3.0.2"
}
}
47 changes: 0 additions & 47 deletions prompts.js

This file was deleted.

3 changes: 3 additions & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Distributable
dist

# Logs
logs
*.log
Expand Down
13 changes: 13 additions & 0 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# %TITLE%

## Developement Instructions
1. In the root directory, run `npm install` to install all the project dependencies
2. Run `npm start` to start the dev server
3. Navigate to http://localhost:9966 (or the url provided after running `npm start`)

## Developement Commands
Below are a list of commands used for developement. The logic for all the commands are in the local `package.json`
- `npm start` - starts a server hosting the webapp on localhost using budo; will live update with changes
- `npm run build` - builds a final distributable using browserify
- `npm run test-dev` - starts a server hosting test files on localhost; Test results are shown when you navigate to the webapp on a browser
- `npm test` - runs tests against all browsers on the device
10 changes: 10 additions & 0 deletions template/elements/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Tram = require('tram-one')
const html = Tram.html()

module.exports = () => {
return html`
<h1>
%TITLE%
</h1>
`
}
20 changes: 0 additions & 20 deletions template/elements/header.js.js

This file was deleted.

2 changes: 0 additions & 2 deletions template/main.js.js → template/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module.exports = (options) => `
const Tram = require('tram-one')
const html = Tram.html()

const app = new Tram()
app.addRoute('/', require('./pages/home'))
app.addRoute('/404', require('./pages/404'))
app.start('.main')
`
24 changes: 24 additions & 0 deletions template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "%TITLE%",
"version": "1.0.0",
"scripts": {
"start": "budo main.js:bundle.js --pushstate --dir public --live",
"prebuild": "cp -r public/ dist",
"build": "browserify ./main.js -o ./dist/bundle.js -t [ babelify --presets [ env ] ]",
"test-build": "browserify ./specs/specs.js -o ./specs/spec-bundle.js -t [ babelify --presets [ env ] ]",
"test-dev": "testem -f ./specs/testem.yml",
"test": "testem ci -f ./specs/testem.yml"
},
"keywords": [
"%TITLE%",
"tram-one"
],
"dependencies": {
"babel-preset-env": "^1.6.0",
"babelify": "^7.3.0",
"browserify": "^14.4.0",
"budo": "^10.0.4",
"testem": "^1.16.2",
"tram-one": "^1.4.1"
}
}
22 changes: 0 additions & 22 deletions template/package.json.js

This file was deleted.

12 changes: 12 additions & 0 deletions template/pages/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Tram = require('tram-one')
const html = Tram.html()

module.exports = () => {
return html`
<div>
<h1>404</h1>
<code>No route ${window.location.pathname}</code><br>
Check <code>%TITLE%/main.js</code> to see all the available routes.
</div>
`
}
14 changes: 0 additions & 14 deletions template/pages/404.js.js

This file was deleted.

10 changes: 4 additions & 6 deletions template/pages/home.js.js → template/pages/home.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module.exports = (options) => `
const Tram = require('tram-one')
const html = Tram.html({
header: require('../elements/header')
})

module.exports = (${options.extraParams ? 'state' : ''}) => {
return html\`
module.exports = () => {
return html`
<div>
<header></header>
<div>
Thank you for using Tram-One!<br>
To get started, edit <code>${options.name}/pages/home.js</code>.
To get started, edit <code>%TITLE%/pages/home.js</code>.
</div>
</div>
\`
`
}
`
10 changes: 10 additions & 0 deletions template/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>%TITLE%</title>
<link rel="icon" type="image/png" href="./favicon.png" />
</head>
<body>
<div class="main"></div>
<script src="bundle.js"></script>
</body>
</html>
16 changes: 0 additions & 16 deletions template/public/index.html.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module.exports = (options) => `
const header = require('../elements/header')

describe('header', () => {
it('should have the title', () => {
const page = header()
expect(page.textContent).toEqual('${options.name}')
expect(page.textContent).toMatch('%TITLE%')
})
})
`
Loading

0 comments on commit d8976fc

Please sign in to comment.