Skip to content

Commit fb42f64

Browse files
authored
feat: typescript and babel (#15)
1 parent 9025c62 commit fb42f64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+309
-135
lines changed

.babelrc.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
module.exports = {
22
presets: [
3-
[
4-
"@babel/env",
5-
{
6-
targets: {
7-
node: "current",
8-
},
9-
},
10-
],
3+
// Compile to environments listed in .browserslistrc
4+
"@babel/env",
115
"@babel/typescript",
126
],
137
plugins: [

.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
maintained node versions

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
# create-exposed-app
22

3-
App generator with everything exposed for maximum tweaking.
4-
5-
---
6-
73
Like zero-config? Get out!
84

9-
Config files are exposed and ready to edit, not hidden away in one-of-those `node_modules` directories.
10-
11-
Scripts are in your face and tweakable, not tucked away behind a black box.
5+
Generate a flexible starting point for your app, where config files and scripts are in-your-face and ready to adapt to your needs.
126

13-
Because every app is unique.
7+
_Because every app is unique._
148

159
Go for it:
1610

@@ -23,12 +17,9 @@ npm init exposed-app
2317
![command structure](docs/assets/demo-structure.png)
2418

2519
- Tools configured with sensible defaults
26-
- [Jest](https://jestjs.io/), [ESLint](https://eslint.org/), and more
27-
- Optional [TypeScript](https://www.typescriptlang.org/) support
28-
- Nothing hidden or abstracted, easy to override and customize
29-
- Useful `npm run` scripts
30-
- `test`, `lint`, `format`, `upgrade`, `reinstall`, and `reset`
31-
- Powered by [iamturns-scripts](https://github.com/iamturns/iamturns-scripts)
20+
- Powered by [TypeScript](https://www.typescriptlang.org/), [Babel](https://babeljs.io/), [Jest](https://jestjs.io/), [ESLint](https://eslint.org/), and more
21+
- Useful `npm run` scripts including `test`, `lint`, `format`, `build`, `validate`, `upgrade`, `reinstall`, and `reset`
22+
- Powered by [iamturns-scripts](https://github.com/iamturns/iamturns-scripts), [nodemon](https://nodemon.io/), [npm-run-all](https://www.npmjs.com/package/npm-run-all), and more
3223
- Format (beautify) files
3324
- Powered by [Prettier](https://prettier.io/), [import-sort](https://github.com/renke/import-sort), [prettier-package-json](https://github.com/cameronhunter/prettier-package-json)
3425
- CI/CD

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
3-
moduleFileExtensions: ["js", "jsx", "json", "ts", "tsx"],
3+
moduleFileExtensions: ["js", "ts", "tsx", "json", "jsx"],
44
testEnvironment: "node",
55
testMatch: [
66
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",

package-lock.json

Lines changed: 17 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-exposed-app",
3-
"description": "App generator with everything exposed for maximum tweaking",
3+
"description": "App generator with everything exposed for maximum control",
44
"license": "MIT",
55
"author": "Matt Turnbull <matt@iamturns.com> (https://iamturns.com)",
66
"homepage": "https://github.com/iamturns/create-exposed-app",
@@ -26,6 +26,7 @@
2626
"build:watch": "onchange 'src/**/*' --initial --kill --delay 1000 -- npm run build",
2727
"dev": "nodemon --ext js,jsx,ts,tsx --delay 1 --exec npm run dev:onchange",
2828
"dev:onchange": "babel-node --extensions .js,.jsx,.ts,.tsx src/create-exposed-app.ts",
29+
"display-browser-support": "browserslist --stats && echo '' && browserslist --coverage && echo '' && echo 'See more at https://browserl.ist/'",
2930
"format": "run-s format:developing format:package format:imports format:prettier format:eslint",
3031
"format:developing": "doctoc --maxlevel 3 --notitle ./DEVELOPING.md",
3132
"format:eslint": "eslint --cache --ext .js,.jsx,.ts,.tsx --fix ./ >/dev/null 2>&1 || true",
@@ -71,7 +72,9 @@
7172
"@types/debug": "0.0.31",
7273
"@types/ejs": "^2.6.1",
7374
"@types/inquirer": "0.0.43",
75+
"@types/jest": "^23.3.13",
7476
"babel-jest": "^23.6.0",
77+
"browserslist": "^4.4.1",
7578
"doctoc": "^1.3.1",
7679
"eslint-config-iamturns": "^1.0.0",
7780
"eslint-plugin-typescript": "^0.14.0",

src/create-app/copy.ts

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,61 @@ export interface CopyOperation {
1010
const templateSuffix = ".template"
1111

1212
const removeTemplateSuffix = (filePath: string): string =>
13-
filePath.substr(0, filePath.length - ".template".length)
13+
filePath.endsWith(templateSuffix)
14+
? filePath.substr(0, filePath.length - templateSuffix.length)
15+
: filePath
1416

15-
const toDestinationPath = (templatePath: string): string =>
16-
templatePath.endsWith(templateSuffix)
17-
? removeTemplateSuffix(templatePath)
18-
: templatePath
17+
const replaceFilepathVariable = (
18+
filePath: string,
19+
key: string,
20+
value: string,
21+
): string => filePath.replace(`{${key}}`, value)
22+
23+
const replaceFilepathViewData = (
24+
filePath: string,
25+
viewData: Record<string, string>,
26+
) =>
27+
Object.entries(viewData).reduce(
28+
(filePathProcessed, viewDataItem) =>
29+
replaceFilepathVariable(
30+
filePathProcessed,
31+
viewDataItem[0],
32+
viewDataItem[1],
33+
),
34+
filePath,
35+
)
36+
37+
const toDestinationPath = (
38+
templatePath: string,
39+
viewData: Record<string, string>,
40+
): string => {
41+
const noSuffix = removeTemplateSuffix(templatePath)
42+
const withViewData = replaceFilepathViewData(noSuffix, viewData)
43+
return withViewData
44+
}
1945

2046
const onCopyComplete = (copyOperation: CopyOperation) =>
2147
debug("Copied %s", copyOperation.dest)
2248

2349
const onCopyError = (copyOperation: CopyOperation) =>
2450
logError(copyOperation.dest)
2551

26-
const recuriveCopyOptions = {
27-
overwrite: true,
28-
dot: true,
29-
rename: (filePath: string) => {
30-
const destinationPath = toDestinationPath(filePath)
31-
debug("Filepath %s to %s", filePath, destinationPath)
32-
return destinationPath
33-
},
34-
}
52+
export const copy = (
53+
sourcePath: string,
54+
destPath: string,
55+
viewData: Record<string, string>,
56+
): CopyOperation[] => {
57+
const recuriveCopyOptions = {
58+
overwrite: true,
59+
dot: true,
60+
rename: (filePath: string) => {
61+
const destinationPath = toDestinationPath(filePath, viewData)
62+
debug("Copy %s to %s", filePath, destinationPath)
63+
return destinationPath
64+
},
65+
}
3566

36-
export const copy = (sourcePath: string, destPath: string): CopyOperation[] =>
37-
recursiveCopy(sourcePath, destPath, recuriveCopyOptions)
67+
return recursiveCopy(sourcePath, destPath, recuriveCopyOptions)
3868
.on(recursiveCopy.events.COPY_FILE_COMPLETE, onCopyComplete)
3969
.on(recursiveCopy.events.ERROR, onCopyError)
70+
}

src/create-app/create-app.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import { askSetupQuestions, askSetupSemanticRelease } from "./ask"
99
import { CopyOperation, copy } from "./copy"
1010
import { setupGit } from "./git"
1111

12-
const templatesPath = path.resolve(__dirname, "..", "templates")
12+
const templatesPath = path.resolve(__dirname, "..", "..", "templates")
1313
debug("Templates path: %s", templatesPath)
1414

1515
const destinationPath = process.cwd()
1616
debug("Destination path: %s", destinationPath)
1717

18-
const doCopy = async (templatePath: string): Promise<CopyOperation[]> => {
18+
const doCopy = async (
19+
templatePath: string,
20+
viewData: Record<string, string>,
21+
): Promise<CopyOperation[]> => {
1922
try {
20-
const copyResults = await copy(templatePath, destinationPath)
23+
const copyResults = await copy(templatePath, destinationPath, viewData)
2124
logMessage(`${copyResults.length} file(s) copied`)
2225
return copyResults
2326
} catch (e) {
@@ -44,7 +47,7 @@ const copyAndRender = async (
4447
templatePath: string,
4548
viewData: Record<string, string>,
4649
) => {
47-
const copyResults = await doCopy(templatePath)
50+
const copyResults = await doCopy(templatePath, viewData)
4851
const filePaths = getFilePaths(copyResults)
4952
const renderViews = filePaths.map(filePath => renderView(filePath, viewData))
5053
await Promise.all(renderViews)
@@ -59,10 +62,7 @@ export const createApp = async () => {
5962
const baseTemplatePath = path.resolve(templatesPath, "1-base")
6063
await copyAndRender(baseTemplatePath, setupAnswers)
6164

62-
if (setupAnswers.side === "server") {
63-
const serverSideTemplatePath = path.resolve(templatesPath, "2-server-side")
64-
await copyAndRender(serverSideTemplatePath, setupAnswers)
65-
} else if (setupAnswers.side === "client") {
65+
if (setupAnswers.side === "client") {
6666
const clientSideTemplatePath = path.resolve(templatesPath, "2-client-side")
6767
await copyAndRender(clientSideTemplatePath, setupAnswers)
6868
}

src/templates/1-base/.eslintrc.js.template

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/templates/1-base/package.json.template

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)