Skip to content

Commit

Permalink
Remove or rename references to hammer.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterp committed Jan 6, 2020
1 parent c91bd22 commit 1974421
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 78 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ node_modules
dist
lerna-debug.log
yarn-error.log

packages/hammer-api/graphql
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 hammerframework
Copyright (c) 2020 Redwood

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/makeMergedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export const makeMergedSchema = (
scalar Time
scalar DateTime
type HammerFramework {
type Redwood {
version: String
}
type Query {
hammerframework: HammerFramework
redwood: Redwood
}
`

Expand All @@ -41,7 +41,7 @@ export const makeMergedSchema = (
Time: GraphQLTime,
DateTime: GraphQLDateTime,
Query: {
hammerframework: () => ({
redwood: () => ({
version: '0.0.0',
}),
},
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/Dev/Dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
// $ redwood dev

import concurrently from 'concurrently'
import { getHammerBaseDir } from '@redwoodjs/core'
import { getBaseDir } from '@redwoodjs/core'

const Dev = () => {
const baseDir = getHammerBaseDir()
const baseDir = getBaseDir()

concurrently(
[
{
command: `cd ${baseDir}/web && yarn webpack-dev-server --config ./config/webpack.dev.js`,
command: `cd ${baseDir}/web && yarn dev`,
name: 'web',
prefixColor: 'yellow',
},
{
command: `cd ${baseDir}/api && yarn hammer-dev-server`,
command: `cd ${baseDir}/api && yarn dev`,
name: 'api',
prefixColor: 'green',
},
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/Generate/Generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'

import React from 'react'
import { Box, Text, Color } from 'ink'
import { getHammerBaseDir } from '@redwoodjs/core'
import { getBaseDir } from '@redwoodjs/core'

import { readFile, writeFile, bytes } from 'src/lib'

Expand All @@ -15,17 +15,17 @@ import sdl from './generators/sdl'
import service from './generators/service'

const GENERATORS = [cell, component, layout, page, scaffold, sdl, service]
const ROUTES_PATH = path.join(getHammerBaseDir(), 'web', 'src', 'Routes.js')
const ROUTES_PATH = path.join(getBaseDir(), 'web', 'src', 'Routes.js')

const Generate = ({
args,
generators = GENERATORS,
fileWriter = writeFile,
}) => {
if (!getHammerBaseDir()) {
if (!getBaseDir()) {
return (
<Color red>
The `generate` command has to be run in your redwood project directory.
The `generate` command has to be run in your Redwood project directory.
</Color>
)
}
Expand All @@ -34,7 +34,7 @@ const Generate = ({
return Object.keys(files).map((filename) => {
const contents = files[filename]
try {
fileWriter(path.join(getHammerBaseDir(), filename), contents)
fileWriter(path.join(getBaseDir(), filename), contents)
return (
<Text key={`wrote-${filename}`}>
<Color green>Wrote {filename}</Color> {bytes(contents)} bytes
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/Generate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Generators go in `src/commands/Generate/generators` and should be named for the generate command that invokes them (not required). For example, for page generator invoked with:

hammer generate page foo
redwood generate page foo

you would create `src/commands/Generate/generators/page.js`. The file name does not have to match the generator command (the name is pulled from the object returned when importing the generator) but it is clearest to have the command and the name match.

Expand All @@ -22,17 +22,17 @@ The generator must export a default hash containing the following keys:
| `name` | The name of the generator | Yes |
| `command` | The command line input that triggers the generator | Yes |
| `description` | Text that is shown on the generator's help message | Yes |
| `files` | A function which accepts the array of arguments given to the `hammer` command. Returns an object containing filenames and contents of those files to be created | No |
| `routes` | A function which accepts the array of arguments given to the `hammer` command. Returns an array of `<Route>` tags to append to the Routes.js file | No |
| `generate` | A function which accepts the array of arguments given to the `hammer` command. Returns an array of an array of arguments that would be passed to the Generate function in the same order the commands would be sent in from a command line call to `hammer generate` | No |
| `files` | A function which accepts the array of arguments given to the `redwood` command. Returns an object containing filenames and contents of those files to be created | No |
| `routes` | A function which accepts the array of arguments given to the `redwood` command. Returns an array of `<Route>` tags to append to the Routes.js file | No |
| `generate` | A function which accepts the array of arguments given to the `redwood` command. Returns an array of an array of arguments that would be passed to the Generate function in the same order the commands would be sent in from a command line call to `redwood generate` | No |

An example generator's return:

```javascript
{
name: "Page",
command: "page",
description: "Generates a Hammer page component",
description: "Generates a page component",
files: name => ({
'pages/FooPage/FooPage.js': 'const FooPage = () => { ... }'
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/Generate/generators/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ const files = (args) => {
export default {
name: 'Cell',
command: 'cell',
description: 'Generates a Hammer cell component',
description: 'Generates a cell component',
files: (args) => files(args),
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/Generate/generators/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ const files = (args) => {
export default {
name: 'Layout',
command: 'layout',
description: 'Generates a Hammer layout component',
description: 'Generates a layout component',
files: (args) => files(args),
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/Generate/generators/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const routes = ([pageName, ..._rest]) => {
export default {
name: 'Page',
command: 'page',
description: 'Generates a Hammer page component',
description: 'Generates a page component',
files: (args) => files(args),
routes: (args) => routes(args),
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/Generate/generators/sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const generate = (args) => {
export default {
name: 'SDL',
command: 'sdl',
description: 'Generates a GraphQL SDL file and Hammer service object',
description: 'Generates a GraphQL SDL file and service object',
files: async (args) => await files(args),
generate: (args) => generate(args),
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/Generate/generators/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ const files = (args) => {
export default {
name: 'Service',
command: 'service',
description: 'Generates a Hammer service object',
description: 'Generates a service object',
files: (args) => files(args),
}
2 changes: 1 addition & 1 deletion packages/cli/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { version } from '../../package.json'
export default (props) => (
<Box {...props}>
<Color hex="#FFD900">
<Text bold>⚒ Hammer</Text> - Build something. (https://example.org)
<Text bold>Redwood</Text> - Build something. (https://redwoodjs.com)
</Color>{' '}
<Color hex="#999">| v{version}</Color>
</Box>
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path'

import requireDir from 'require-dir'
import parse from 'yargs-parser'
import { getHammerConfig } from '@redwoodjs/core'
import lodash from 'lodash/string'

export const templateRoot = path.join(
Expand Down Expand Up @@ -43,8 +42,6 @@ export const writeFile = (

export const bytes = (contents) => Buffer.byteLength(contents, 'utf8')

export const hammerBaseDir = () => getHammerConfig().baseDir

const validateCommandExports = ({ commandProps, ...rest }) => {
if (typeof rest.default !== 'function') {
throw 'you must export a default function'
Expand Down
8 changes: 4 additions & 4 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The Hammer Core
# The Core

This package searches for and parses the `hammer.toml` configuration
file. The `hammer.toml` file is used to designate the base
directory of a hammer app.
This package searches for and parses the `redwood.toml` configuration
file. The `redwood.toml` file is used to designate the base
directory of a Redwood app.
22 changes: 10 additions & 12 deletions packages/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import path from 'path'
import findUp from 'findup-sync'
import toml from 'toml'

const HAMMER_CONFIG_FILE = 'hammer.toml'
const CONFIG_FILE_NAME = 'redwood.toml'

export const getHammerConfigPath = (): string => {
const configPath = findUp(HAMMER_CONFIG_FILE)
export const getConfigPath = (): string => {
const configPath = findUp(CONFIG_FILE_NAME)
if (!configPath) {
throw new Error(
`Could not find a "${HAMMER_CONFIG_FILE}" file, are you in a hammer project?`
`Could not find a "${CONFIG_FILE_NAME}" file, are you sure you're in a Redwood project?`
)
}
return configPath
}

export const getHammerBaseDir = (
configPath: string = getHammerConfigPath()
): string => {
export const getBaseDir = (configPath: string = getConfigPath()): string => {
return path.dirname(configPath)
}

export interface HammerConfig {
export interface ConfigInterface {
baseDir: string
web: {
port: number
Expand All @@ -38,13 +36,13 @@ export interface HammerConfig {
}
}

export const getHammerConfig = (): HammerConfig => {
const configPath = getHammerConfigPath()
const baseDir = getHammerBaseDir(configPath)
export const getConfig = (): ConfigInterface => {
const configPath = getConfigPath()
const baseDir = getBaseDir(configPath)
try {
const config = toml.parse(
fs.readFileSync(configPath, 'utf8')
) as HammerConfig
) as ConfigInterface

return {
...config,
Expand Down
6 changes: 3 additions & 3 deletions packages/dev-server/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The Development Server

The hamer dev server looks for "lambda functions" in the directory
(default: `./api/src/functions`) specified in your `hammer.toml`
The dev server looks for "lambda functions" in the directory
(default: `./api/src/functions`) specified by your `redwood.toml`
configuration file.

Each lambda function is mapped to a URI based on their filename, as
Expand All @@ -12,7 +12,7 @@ The `./api` directory is watched for modifications, when they are
detected the modules are reimported.

A lambda function must export a `handler`. You can execute the
supplied callback function:
supplied callback function to return a response:

```js
export const handler = (event, context, callback) => {
Expand Down
18 changes: 9 additions & 9 deletions packages/dev-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'

import { Response, Request } from 'express'
import { APIGatewayProxyResult, APIGatewayProxyEvent } from 'aws-lambda'
import { getHammerConfig } from '@redwoodjs/core'
import { getConfig } from '@redwoodjs/core'
import express from 'express'
// @ts-ignore
import expressLogging from 'express-logging'
Expand All @@ -15,30 +15,30 @@ import chokidar from 'chokidar'
// @ts-ignore
import babelRegister from '@babel/register'

const hammerConfig = getHammerConfig()
const hammerApiDir = path.join(hammerConfig.baseDir, 'api')
const config = getConfig()
const API_DIR = path.join(config.baseDir, 'api')

babelRegister({
extends: path.join(hammerApiDir, '.babelrc.js'),
extends: path.join(API_DIR, '.babelrc.js'),
extensions: ['.js', '.ts'],
only: [hammerApiDir],
only: [API_DIR],
ignore: ['node_modules'],
})

// TODO: Convert to yargs.
args
.option('port', '', hammerConfig.api.port)
.option('port', '', config.api.port)
.option(
'path',
'The path to your lambda functions',
hammerConfig.api.paths.functions
config.api.paths.functions
)
const { port: PORT, path: PATH } = args.parse(process.argv)
const HOSTNAME = `http://localhost:${PORT}`

const showHeader = (lambdas: Record<string, any>) => {
console.log(`◌ Listening on ${HOSTNAME}`)
console.log(`◌ Watching ${hammerApiDir}`)
console.log(`◌ Watching ${API_DIR}`)
console.log('\nNow serving\n')
console.log(
Object.keys(lambdas)
Expand Down Expand Up @@ -190,7 +190,7 @@ const startServer = () => app.listen(PORT, () => showHeader(lambdaFunctions))
const server = startServer()
server.setTimeout(10 * 1000)

const watcher = chokidar.watch(hammerApiDir, {
const watcher = chokidar.watch(API_DIR, {
ignored: (path: string) => path.includes('node_modules'),
})

Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// Hammer's ESLint configuration is a mixture between ESLint's recommended
// Our ESLint configuration is a mixture between ESLint's recommended
// rules [^1], React's recommended rules [^2], and a bit of our own stylistic
// flair:
// - no semicolons
Expand Down Expand Up @@ -46,7 +45,7 @@ module.exports = {
globals: {
gql: 'readonly',
React: 'readonly',
__HAMMER__: 'readonly',
__REDWOOD__: 'readonly',
},
rules: {
'prettier/prettier': 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is Hammer's routing mechanism. It takes inspiration from both Ruby on
// This is Redwood's routing mechanism. It takes inspiration from both Ruby on
// Rails' routing approach and from both React Router and Reach Router (the
// latter of which has closely inspired some of this code).

Expand Down
10 changes: 4 additions & 6 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const Dotenv = require('dotenv-webpack')
const { getHammerConfig } = require('@redwoodjs/core')
const { getConfig } = require('@redwoodjs/core')

const hammerConfig = getHammerConfig()
const BASE_DIR = hammerConfig.baseDir
const config = getConfig()
const BASE_DIR = config.baseDir

// I've borrowed and learnt extensively from the `create-react-app`
// repo: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js
Expand Down Expand Up @@ -76,9 +76,7 @@ module.exports = (webpackEnv) => {
gql: ['@redwoodjs/web', 'gql'],
}),
new webpack.DefinePlugin({
'__HAMMER__.apiProxyPath': JSON.stringify(
hammerConfig.web.apiProxyPath
),
'__REDWOOD__.apiProxyPath': JSON.stringify(config.web.apiProxyPath),
__filename: webpack.DefinePlugin.runtimeValue((runtimeValue) => {
// absolute path of imported file
return JSON.stringify(runtimeValue.module.resource)
Expand Down
Loading

0 comments on commit 1974421

Please sign in to comment.