-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move create command into dedicated package (#31)
* Move create into package * Add create-bgdk to snapshot script * copy example into create script on publish * fix path to examples * Create project with new package * Add change file
- Loading branch information
Showing
16 changed files
with
231 additions
and
52 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'bgdk': patch | ||
'create-bgdk': patch | ||
--- | ||
|
||
Move create command to create-bgdk |
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,40 +1,20 @@ | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import execa from 'execa'; | ||
import { log } from '../lib/log'; | ||
import chalk from 'chalk'; | ||
|
||
interface Options { | ||
appPath: string; | ||
} | ||
|
||
export async function main(options: Options) { | ||
let outputPath = path.resolve(options.appPath); | ||
let outputPathRelative = path.relative(process.cwd(), outputPath); | ||
let templatePath = path.resolve(__dirname, '../../../examples/basic'); | ||
log(`Command moved to create-bgdk package.`); | ||
log(`To bootstrap project run: | ||
log(`Creating app in ${outputPathRelative}`); | ||
$ ${chalk.whiteBright(`npm init bgdk`)} | ||
await fs.copy(templatePath, outputPath, { overwrite: true }); | ||
Or | ||
// Fix .gitignore. See [issue](https://github.com/npm/npm/issues/1862). | ||
try { | ||
await fs.move( | ||
path.resolve(outputPath, '.npmignore'), | ||
path.resolve(outputPath, '.gitignore'), | ||
{ overwrite: true }, | ||
); | ||
} catch (error) { | ||
log(`Failed creating gitignore, assuming this is local dev`); | ||
} | ||
$ ${chalk.whiteBright(`yarn create bgdk`)} | ||
`); | ||
|
||
log(`Installing deps`); | ||
|
||
await execa.command('yarn install', { | ||
stdio: 'inherit', | ||
cwd: outputPath, | ||
env: { | ||
// Dev dependencies are skipped when NODE_ENV === 'production' | ||
NODE_ENV: undefined, | ||
}, | ||
}); | ||
process.exit(1); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
require('v8-compile-cache'); | ||
require('./cli'); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"main": "dist/create-bgdk-cli.cjs.js" | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
../../examples |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "create-bgdk", | ||
"version": "0.0.0", | ||
"description": "Bootstrap apps with BGDK", | ||
"main": "dist/create-bgdk.cjs.js", | ||
"files": [ | ||
"bin.js", | ||
"/cli", | ||
"/dist", | ||
"/examples", | ||
"/examples/basic/.gitignore", | ||
"!/examples/*/yarn.yaml", | ||
"/templates/" | ||
], | ||
"preconstruct": { | ||
"entrypoints": [ | ||
"cli/index.ts" | ||
] | ||
}, | ||
"bin": "./bin.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"vanilla-extract", | ||
"bgdk" | ||
], | ||
"author": "Eamon Hyland", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ehyland/bgdk/issues" | ||
}, | ||
"homepage": "https://github.com/ehyland/bgdk#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:ehyland/bgdk.git", | ||
"directory": "packages/create-bgdk" | ||
}, | ||
"dependencies": { | ||
"chalk": "^4.1.2", | ||
"fs-extra": "^10.0.0", | ||
"sade": "^1.7.4", | ||
"v8-compile-cache": "^2.3.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sade from 'sade'; | ||
import { main } from '../create'; | ||
|
||
const prog = sade('create-bgdk <app-path>', true); | ||
|
||
// exit on unhandled promise | ||
process.on('unhandledRejection', (err) => { | ||
throw err; | ||
}); | ||
|
||
// exit on signals | ||
['SIGINT', 'SIGTERM'].forEach(function (sig) { | ||
process.on(sig, function () { | ||
process.exit(); | ||
}); | ||
}); | ||
|
||
const pkg = require('../../package.json'); | ||
|
||
prog.version(pkg.version); | ||
|
||
prog | ||
.describe('Create a new project with bgdk') | ||
.action(async (appPath: string) => { | ||
await main({ appPath }); | ||
}); | ||
|
||
prog.parse(process.argv); |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import { log } from './log'; | ||
import chalk from 'chalk'; | ||
|
||
interface Options { | ||
appPath: string; | ||
} | ||
|
||
export async function main(options: Options) { | ||
let outputPath = path.resolve(options.appPath); | ||
let outputPathRelative = path.relative(process.cwd(), outputPath); | ||
let templatePath = path.resolve(__dirname, '../../examples/basic'); | ||
|
||
log(`Creating app in ${outputPathRelative}`); | ||
|
||
if (await fs.pathExists(outputPath)) { | ||
const { isDirectory } = await fs.stat(outputPath); | ||
|
||
if (!isDirectory) { | ||
log(`File exists at output path ${outputPathRelative}`); | ||
process.exit(1); | ||
} | ||
|
||
const files = await fs.readdir(outputPath); | ||
|
||
if (files.length !== 0) { | ||
log(`${outputPathRelative} is not empty`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
await fs.copy(templatePath, outputPath, { overwrite: true }); | ||
|
||
// Fix .gitignore. See [issue](https://github.com/npm/npm/issues/1862). | ||
try { | ||
await fs.move( | ||
path.resolve(outputPath, '.npmignore'), | ||
path.resolve(outputPath, '.gitignore'), | ||
{ overwrite: true }, | ||
); | ||
} catch (error) { | ||
// assuming this is local dev | ||
} | ||
|
||
log(`App created! Next steps | ||
$ ${chalk.whiteBright(`cd ${outputPathRelative}`)} | ||
$ ${chalk.whiteBright(`yarn install`)} | ||
`); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import chalk from 'chalk'; | ||
|
||
export const log = (message: string) => { | ||
console.log(`🥦 ${chalk.blue(message)}`); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/*/* |