mirror of
https://github.com/strapi/strapi.git
synced 2025-08-15 20:27:23 +00:00
54 lines
1.3 KiB
JavaScript
Executable File
54 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
// Node.js core.
|
|
const path = require('path');
|
|
|
|
// Local Strapi dependencies.
|
|
const strapi = require('../lib/server');
|
|
const packageJSON = require('../package.json');
|
|
|
|
// Logger.
|
|
const logger = require('strapi-utils').logger;
|
|
|
|
/**
|
|
* `$ strapi start`
|
|
*
|
|
* Expose method which starts the appropriate instance of Strapi
|
|
* (fire up the application in our working directory).
|
|
*/
|
|
|
|
module.exports = function () {
|
|
|
|
// Build initial scope.
|
|
const scope = {
|
|
rootPath: process.cwd(),
|
|
strapiPackageJSON: packageJSON
|
|
};
|
|
|
|
// Use the app's local `strapi` in `node_modules` if it's existant and valid.
|
|
const localStrapiPath = path.resolve(scope.rootPath, 'node_modules', 'strapi');
|
|
|
|
if (strapi.isLocalStrapiValid(localStrapiPath, scope.rootPath)) {
|
|
return require(localStrapiPath).start(scope, afterwards);
|
|
}
|
|
|
|
// Otherwise, if no workable local `strapi` module exists,
|
|
// run the application using the currently running version
|
|
// of `strapi`. This is probably always the global install.
|
|
strapi().start(scope, afterwards);
|
|
|
|
function afterwards(err, strapi) {
|
|
if (err) {
|
|
const message = err.stack ? err.stack : err;
|
|
logger.error(message);
|
|
strapi ? strapi.stop() : process.exit(1);
|
|
}
|
|
}
|
|
};
|