Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
Ensure .gitignore when setup a new boilerplate
Browse files Browse the repository at this point in the history
- Use async instead of sync fs operations
  • Loading branch information
thangngoc89 committed Mar 21, 2016
1 parent 13ad6f2 commit 3f1c025
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions boilerplate/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
*.log
21 changes: 20 additions & 1 deletion npm/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@ const stat = require("fs").stat
const spawn = require("child_process").spawn
const join = require("path").join
const pkg = require("../package.json")

const fs = require("fs-extra")
// no need for th is step on CI
if (process.env.CI) {
process.exit(0)
}

const boilerplateDir = join(__dirname, "../boilerplate")

stat(join(boilerplateDir, ".npmignore"), function(err) {
if (err) {
console.log("No .npmignore in boilerplate to rename")
return true
}

fs.move(
join(boilerplateDir, ".npmignore"),
join(boilerplateDir, ".gitignore"),
function(err) {
if (err) {
throw new Error("Cannot rename .npmignore to .gitignore in boilerplate")
}
}
)
})

stat("lib", function(error, stats1) {
if (!error && stats1.isDirectory()) {
return true
Expand Down
17 changes: 5 additions & 12 deletions src/bin/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "babel-polyfill"

import color from "chalk"
import { join } from "path"
import fs from "fs-extra"
import fs from "fs-promise"

import { prompt } from "../utils/inquirer"
import questions, { defaultTestAnswers } from "../data/questions"
Expand All @@ -15,17 +15,10 @@ import {

export default async function setup(argv) {
const cwd = process.cwd()
const testMode = argv.test

try {
let answers
const testMode = argv.test

if (testMode) {
answers = defaultTestAnswers
}
else {
answers = await prompt(questions)
}
const answers = testMode ? defaultTestAnswers : await prompt(questions)
const { name, homepage, ...statinamic } = answers

const devDependencies = {
Expand All @@ -44,11 +37,11 @@ export default async function setup(argv) {
devDependencies,
}

fs.writeJsonSync(join(cwd, "package.json"), pkg)
await fs.writeJson(join(cwd, "package.json"), pkg)
console.log(color.green("Generated package.json file"))

const boilerplatePath = join(__dirname, "../../../boilerplate")
fs.copySync(boilerplatePath, cwd)
await fs.copy(boilerplatePath, cwd)
console.log(color.green("Copied boilerplate"))

console.log(
Expand Down

0 comments on commit 3f1c025

Please sign in to comment.