Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
feat(commands): add run:instructions command
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 1, 2017
1 parent 56834a8 commit 459d7c9
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const path = require('path')
const Commands = require('./src/Commands')
const commandNames = []
const needProviders = ['repl', 'route:list', 'install']
const needProviders = ['repl', 'route:list', 'install', 'run:instructions']

const ace = require('./lib/ace')

Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@adonisjs/ace": "^4.0.3",
"@adonisjs/ignitor": "^1.0.4",
"adonis-await-outside": "^1.0.0",
"boxen": "^1.2.1",
"cli-spinner": "^0.2.6",
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Install extends Command {
return `
install
{ module : Npm module name }
{ name? : Name of the module, required when installing from github or local file system }
{ --name=@value : Name of the module, required when installing from github or local file system }
{ --yarn: Use yarn over npm for installation }
{ -s, --skip-instructions: Do not run post install instructions }
`
Expand Down Expand Up @@ -76,7 +76,7 @@ class Install extends Command {
*
* @return {void}
*/
async handle ({ module: packageName, name }, { yarn, skipInstructions }) {
async handle ({ module: packageName }, { yarn, skipInstructions, name }) {
const acePath = path.join(process.cwd(), 'ace')
const exists = await this.pathExists(acePath)

Expand Down
112 changes: 112 additions & 0 deletions src/Commands/Instructions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use strict'

/*
* adonis-cli
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const path = require('path')
const steps = require('../Install/steps')
const Context = require('../Install/Context')
const { Command } = require('../../../lib/ace')
const FakeHelpers = require('@adonisjs/ignitor/src/Helpers')

const ERROR_HEADING = `
=============================================
Installation failed due to following error
=============================================`

class Instructions extends Command {
constructor (Helpers) {
super()
this.Helpers = Helpers || new FakeHelpers(process.cwd())
}

/**
* Injecting dependencies
*
* @method inject
*
* @return {Array}
*/
static get inject () {
return ['Adonis/Src/Helpers']
}

/**
* The command signature
*
* @method signature
*
* @return {String}
*/
static get signature () {
return `
run:instructions
{ directory : Directory path for which to run instructions }
{ --name=@value: Name of the module }
`
}

/**
* The command description
*
* @method description
*
* @return {String}
*/
static get description () {
return 'Run instructions for a given module'
}

/**
* Handle method executed by ace when command runs. It will
* install a module and run post install instructions
*
* @method handle
*
* @param {String} options.module
* @param {Boolean} options.yarn
* @param {Boolean} options.skipInstructions
*
* @return {void}
*/
async handle ({ directory }, { name }) {
const modulePath = path.isAbsolute(directory) ? directory : path.join(process.cwd(), directory)
name = name || path.basename(modulePath)
const ctx = new Context(this, this.Helpers)

try {
/**
* Step: 2
*
* Check if module has `instructions.js` file and
* run the instructions in that case
*/
await steps.runInstructions(ctx, modulePath)

/**
* Step: 3
*
* Check if module has `instructions.md` file and
* render the markdown as html.
*/
await steps.renderInstructions(
modulePath,
name,
this.readFile.bind(this),
this.writeFile.bind(this)
)
} catch (error) {
this.error(ERROR_HEADING)
console.log(error.message)
process.exit(1)
}
}
}

module.exports = Instructions
3 changes: 2 additions & 1 deletion src/Commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ module.exports = {
'repl': require('./Repl'),
'make:ehandler': require('./Make/ExceptionHandler'),
'make:seed': require('./Make/Seed'),
'route:list': require('./RouteList')
'route:list': require('./RouteList'),
'run:instructions': require('./Instructions')
}

0 comments on commit 459d7c9

Please sign in to comment.