mirror of
https://github.com/strapi/strapi.git
synced 2025-12-05 03:21:22 +00:00
Remove the CLI
This commit is contained in:
parent
96c2407d69
commit
489e95f1e7
@ -1,28 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const program = require('commander');
|
||||
|
||||
/**
|
||||
* Monkey-patch commander
|
||||
*/
|
||||
|
||||
// Allow us to display `help()`, but omit the wildcard (`*`) command.
|
||||
program.Command.prototype.usageMinusWildcard = program.usageMinusWildcard = function () {
|
||||
program.commands = _.reject(program.commands, {
|
||||
_name: '*'
|
||||
});
|
||||
program.help();
|
||||
};
|
||||
|
||||
// Force commander to display version information.
|
||||
program.Command.prototype.versionInformation = program.versionInformation = function () {
|
||||
program.emit('version');
|
||||
};
|
||||
|
||||
module.exports = program;
|
||||
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var spawn = require('child_process').spawn;
|
||||
var args = [ __dirname + '/strapi.js' ].concat(process.argv.slice(2));
|
||||
|
||||
spawn(process.argv[0], ['--harmony'].concat(args), {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
@ -1,61 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Public node modules.
|
||||
const winston = require('winston');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi config`
|
||||
*
|
||||
* Read or create the RC file a $HOME to
|
||||
* use custom generators.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
const HOME = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
|
||||
fs.access(path.resolve(HOME, '.strapirc'), fs.F_OK | fs.R_OK | fs.W_OK, function (err) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
fs.writeFile(path.resolve(HOME, '.strapirc'), JSON.stringify({generators: {}}, null, '\t'), function (err) {
|
||||
if (err) {
|
||||
logger.error('Impossible to write the `.strapirc` file at `' + HOME + '`');
|
||||
logger.error('Please check read/write permissions before execute `$ strapi config`');
|
||||
logger.error('You can manually create the file at `' + HOME + '`');
|
||||
} else {
|
||||
logger.info('Global configuration file successfully created at `' + HOME + '`');
|
||||
logger.info('Please read http://strapi.io/documentation/customization to learn more');
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
} else if (err.code === 'EACCES') {
|
||||
logger.error('Impossible to access the `.strapirc` file at `' + HOME + '`');
|
||||
logger.error('Please check read/write permissions before execute `$ strapi config`');
|
||||
logger.error('You can manually create the file at `' + HOME + '`');
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
logger.warn('Looks like the configuration file already exists at `' + HOME + '`');
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,73 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const REPL = require('repl');
|
||||
const cluster = require('cluster');
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const winston = require('winston');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const server = require('../lib/server');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi console`
|
||||
*
|
||||
* Enter the interactive console (aka REPL) for the application
|
||||
* in our working directory.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
// Now load up the Strapi framework for real.
|
||||
const strapi = server();
|
||||
|
||||
// Only log if the process is a master.
|
||||
if (cluster.isMaster) {
|
||||
strapi.log.info('Starting the application in interactive mode...');
|
||||
}
|
||||
|
||||
strapi.start({}, function (err) {
|
||||
|
||||
// Log and exit the REPL in case there is an error
|
||||
// while we were trying to start the server.
|
||||
if (err) {
|
||||
logger.error('Could not load the Strapi framework.');
|
||||
logger.error('Are you using the latest stable version?');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Open the Node.js REPL.
|
||||
if ((cluster.isMaster && _.isEmpty(cluster.workers)) || cluster.worker.id === 1) {
|
||||
const repl = REPL.start(strapi.config.name + ' > ' || 'strapi > ');
|
||||
repl.on('exit', function (err) {
|
||||
|
||||
// Log and exit the REPL in case there is an error
|
||||
// while we were trying to open the REPL.
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,100 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const path = require('path');
|
||||
|
||||
// Public node modules.
|
||||
const winston = require('winston');
|
||||
|
||||
// Master of ceremonies for generators.
|
||||
const generate = require('strapi-generate');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const packageJSON = require('../package.json');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi generate`
|
||||
*
|
||||
* Scaffolding for the application in our working directory.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
// Pass the original CLI arguments down to the generator
|
||||
// (but first, remove commander's extra argument).
|
||||
// Also peel off the `generatorType` arg.
|
||||
const cliArguments = Array.prototype.slice.call(arguments);
|
||||
cliArguments.pop();
|
||||
|
||||
// Build initial scope.
|
||||
const scope = {
|
||||
rootPath: process.cwd(),
|
||||
strapiRoot: path.resolve(__dirname, '..'),
|
||||
generatorType: cliArguments.shift(),
|
||||
generatorName: process.argv[2],
|
||||
args: cliArguments,
|
||||
strapiPackageJSON: packageJSON
|
||||
};
|
||||
|
||||
// Check that we're in a valid Strapi project.
|
||||
if (scope.generatorType !== 'new') {
|
||||
const pathToPackageJSON = path.resolve(scope.rootPath, 'package.json');
|
||||
let invalidPackageJSON;
|
||||
|
||||
try {
|
||||
require(pathToPackageJSON);
|
||||
} catch (e) {
|
||||
invalidPackageJSON = true;
|
||||
}
|
||||
|
||||
if (invalidPackageJSON) {
|
||||
return logger.error('This command can only be used inside an Strapi project.');
|
||||
}
|
||||
}
|
||||
|
||||
// Show usage if no generator type is defined.
|
||||
if (!scope.generatorType) {
|
||||
return logger.error('Write `$ strapi generate [something]` instead.');
|
||||
}
|
||||
|
||||
// Return the scope and the response (`error` or `success`).
|
||||
return generate(scope, {
|
||||
|
||||
// Log and exit the REPL in case there is an error
|
||||
// while we were trying to generate the requested generator.
|
||||
error: function returnError(msg) {
|
||||
logger.error(msg);
|
||||
process.exit(1);
|
||||
},
|
||||
|
||||
// Log and exit the REPL in case of success
|
||||
// but first make sure we have all the info we need.
|
||||
success: function returnSuccess() {
|
||||
if (!scope.outputPath && scope.filename && scope.destDir) {
|
||||
scope.outputPath = scope.destDir + scope.filename;
|
||||
}
|
||||
|
||||
if (scope.generatorType !== 'new') {
|
||||
logger.info('Generated a new ' + scope.generatorType + ' `' + scope.humanizeId + '` at ' + scope.humanizedPath + '.');
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,124 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const dns = require('dns');
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const request = require('request');
|
||||
const winston = require('winston');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi link`
|
||||
*
|
||||
* Link an existing application to the Strapi Studio
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
const HOME = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
const pathToPackageJSON = path.resolve(process.cwd(), 'package.json');
|
||||
const pathToStudioJSON = path.resolve(process.cwd(), 'config', 'studio.json');
|
||||
const appPkg = JSON.parse(fs.readFileSync(pathToPackageJSON));
|
||||
const studioConfig = JSON.parse(fs.readFileSync(pathToStudioJSON));
|
||||
let invalidPackageJSON;
|
||||
|
||||
// First, check if we are in a Strapi project.
|
||||
try {
|
||||
require(pathToPackageJSON);
|
||||
} catch (err) {
|
||||
invalidPackageJSON = true;
|
||||
}
|
||||
|
||||
if (invalidPackageJSON) {
|
||||
logger.error('This command can only be used inside an Strapi project.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check the internet connectivity.
|
||||
dns.resolve('google.com', function (noInternetAccess) {
|
||||
if (noInternetAccess) {
|
||||
logger.warn('No internet access...');
|
||||
logger.warn('Your application can not be linked to the Strapi Studio.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Read the `.strapirc` configuration file at $HOME.
|
||||
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
||||
if (noRcFile) {
|
||||
logger.warn('You do not have a `.strapirc` file at `' + HOME + '`.');
|
||||
logger.warn('First, you need to create an account on http://studio.strapi.io/');
|
||||
logger.warn('Then, execute `$ strapi login` to start the experience.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse the config file.
|
||||
config = JSON.parse(config);
|
||||
|
||||
// Make sure the developer is logged in.
|
||||
if (_.isEmpty(config.email) || _.isEmpty(config.token)) {
|
||||
logger.error('You are not logged in.');
|
||||
logger.error('Execute `$ strapi login` to start the experience.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create a new application on the Strapi Studio.
|
||||
request({
|
||||
method: 'POST',
|
||||
preambleCRLF: true,
|
||||
postambleCRLF: true,
|
||||
json: true,
|
||||
uri: 'http://studio.strapi.io/app',
|
||||
body: {
|
||||
name: appPkg.name,
|
||||
token: config.token,
|
||||
appToDelete: studioConfig.studio.appId
|
||||
}
|
||||
},
|
||||
|
||||
// Callback.
|
||||
function (err, res) {
|
||||
|
||||
// Log and exit if no internet access.
|
||||
if (err) {
|
||||
logger.warn('Impossible to access the Strapi Studio.');
|
||||
logger.warn('Your application is not linked to the Strapi Studio.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse the RC file.
|
||||
const currentJSON = JSON.parse(fs.readFileSync(path.resolve('config', 'studio.json'), 'utf8'));
|
||||
const newJSON = JSON.stringify(_.merge(currentJSON, {studio: {appId: res.body.appId}}), null, ' ');
|
||||
|
||||
// Write the new `./config/studio.json` with credentials.
|
||||
fs.writeFile(path.resolve('config', 'studio.json'), newJSON, 'utf8', function (err) {
|
||||
if (err) {
|
||||
logger.error('Impossible to write the `appId`.');
|
||||
process.exit(1);
|
||||
} else {
|
||||
logger.info('Your application has successfully been linked to the Studio.');
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -1,130 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const dns = require('dns');
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const prompt = require('prompt');
|
||||
const request = require('request');
|
||||
const winston = require('winston');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi login`
|
||||
*
|
||||
* Connect your account to the Strapi Studio.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
// First, check the internet connectivity.
|
||||
dns.resolve('google.com', function (err) {
|
||||
if (err) {
|
||||
logger.error('No internet access...');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Then, start the prompt with custom options.
|
||||
prompt.start();
|
||||
prompt.colors = false;
|
||||
prompt.message = 'your Strapi ';
|
||||
prompt.delimiter = '';
|
||||
|
||||
// Get email address and password.
|
||||
prompt.get({
|
||||
properties: {
|
||||
email: {
|
||||
description: 'email address',
|
||||
pattern: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
password: {
|
||||
description: 'password',
|
||||
type: 'string',
|
||||
hidden: true,
|
||||
required: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Callback.
|
||||
function (err, result) {
|
||||
|
||||
// Just in case there is an error.
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Make the request to the Studio with the email and password
|
||||
// from the prompt.
|
||||
request({
|
||||
method: 'POST',
|
||||
preambleCRLF: true,
|
||||
postambleCRLF: true,
|
||||
json: true,
|
||||
uri: 'http://studio.strapi.io/auth/local',
|
||||
body: {
|
||||
identifier: result.email,
|
||||
password: result.password
|
||||
}
|
||||
},
|
||||
|
||||
// Callback.
|
||||
function (err, res, body) {
|
||||
const HOME = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
|
||||
// Stop if there is an error.
|
||||
if (err && err.code === 'ECONNREFUSED') {
|
||||
logger.error('Impossible to establish a connection with the Strapi Studio.');
|
||||
logger.error('Please try again in a few minutes...');
|
||||
process.exit(1);
|
||||
} else if (res.statusCode === 400) {
|
||||
logger.error('Wrong credentials.');
|
||||
logger.error('You are not logged in.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Try to access the `.strapirc` at $HOME.
|
||||
fs.access(path.resolve(HOME, '.strapirc'), fs.F_OK | fs.R_OK | fs.W_OK, function (err) {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
fs.writeFileSync(path.resolve(HOME, '.strapirc'), JSON.stringify({
|
||||
email: body.user.email,
|
||||
token: body.token
|
||||
}), 'utf8');
|
||||
logger.info('You are successfully logged in as ' + body.user.email);
|
||||
process.exit(1);
|
||||
} else {
|
||||
const currentJSON = fs.readFileSync(path.resolve(HOME, '.strapirc'), 'utf8');
|
||||
const newJSON = _.merge(JSON.parse(currentJSON), {
|
||||
email: body.user.email,
|
||||
token: body.token
|
||||
});
|
||||
|
||||
fs.writeFileSync(path.resolve(HOME, '.strapirc'), JSON.stringify(newJSON), 'utf8');
|
||||
logger.info('You are successfully logged in as ' + body.user.email);
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Public node modules.
|
||||
const winston = require('winston');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi logout`
|
||||
*
|
||||
* Logout your account from the Strapi Studio.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
const HOME = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
|
||||
// Try to access the `.strapirc` at $HOME.
|
||||
fs.access(path.resolve(HOME, '.strapirc'), fs.F_OK | fs.R_OK | fs.W_OK, function (err) {
|
||||
if (err) {
|
||||
logger.error('You are not logged in.');
|
||||
} else {
|
||||
const config = JSON.parse(fs.readFileSync(path.resolve(HOME, '.strapirc'), 'utf8'));
|
||||
|
||||
delete config.email;
|
||||
delete config.token;
|
||||
|
||||
fs.writeFileSync(path.resolve(HOME, '.strapirc'), JSON.stringify(config), 'utf8');
|
||||
logger.info('Your machine is not linked to the Strapi Studio anymore.');
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,144 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const dns = require('dns');
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const request = require('request');
|
||||
const winston = require('winston');
|
||||
|
||||
// Master of ceremonies for generators.
|
||||
const generate = require('strapi-generate');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const packageJSON = require('../package.json');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi new`
|
||||
*
|
||||
* Generate a new Strapi application.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
// Pass the original CLI arguments down to the generator.
|
||||
const cliArguments = Array.prototype.slice.call(arguments);
|
||||
|
||||
// Build initial scope.
|
||||
const scope = {
|
||||
rootPath: process.cwd(),
|
||||
strapiRoot: path.resolve(__dirname, '..'),
|
||||
generatorType: 'new',
|
||||
args: cliArguments,
|
||||
strapiPackageJSON: packageJSON
|
||||
};
|
||||
|
||||
// Save the `dry` option inside the scope.
|
||||
if (scope.args[1] && scope.args[1].dry) {
|
||||
scope.dry = true;
|
||||
} else {
|
||||
scope.dry = false;
|
||||
}
|
||||
|
||||
// Pass the original CLI arguments down to the generator
|
||||
// (but first, remove commander's extra argument)
|
||||
cliArguments.pop();
|
||||
scope.args = cliArguments;
|
||||
scope.generatorType = 'new';
|
||||
|
||||
// Return the scope and the response (`error` or `success`).
|
||||
return generate(scope, {
|
||||
|
||||
// Log and exit the REPL in case there is an error
|
||||
// while we were trying to generate the new app.
|
||||
error: function returnError(err) {
|
||||
logger.error(err);
|
||||
process.exit(1);
|
||||
},
|
||||
|
||||
// Log and exit the REPL in case of success
|
||||
// but first make sure we have an internet access
|
||||
// and we have all the info we need.
|
||||
success: function returnSuccess() {
|
||||
const HOME = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
|
||||
dns.resolve('google.com', function (noInternetAccess) {
|
||||
if (noInternetAccess) {
|
||||
logger.warn('No internet access...');
|
||||
logger.warn('Your application can not be linked to the Strapi Studio.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Read the `.strapirc` configuration file at $HOME.
|
||||
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
||||
if (noRcFile) {
|
||||
logger.warn('You do not have a `.strapirc` file at `' + HOME + '`.');
|
||||
logger.warn('First, you need to create an account on http://studio.strapi.io/');
|
||||
logger.warn('Then, execute `$ strapi login` to start the experience.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse the config file.
|
||||
config = JSON.parse(config);
|
||||
|
||||
// Create a new application on the Strapi Studio.
|
||||
request({
|
||||
method: 'POST',
|
||||
preambleCRLF: true,
|
||||
postambleCRLF: true,
|
||||
json: true,
|
||||
uri: 'http://studio.strapi.io/app',
|
||||
body: {
|
||||
name: cliArguments[0],
|
||||
token: config.token
|
||||
}
|
||||
},
|
||||
|
||||
// Callback.
|
||||
function (err, res) {
|
||||
|
||||
// Log and exit if no internet access.
|
||||
if (err) {
|
||||
logger.warn('Impossible to access the Strapi Studio.');
|
||||
logger.warn('Your application is not linked to the Strapi Studio.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse the RC file.
|
||||
const currentJSON = JSON.parse(fs.readFileSync(path.resolve('config', 'studio.json'), 'utf8'));
|
||||
const newJSON = JSON.stringify(_.merge(currentJSON, {studio: {appId: res.body.appId}}), null, ' ');
|
||||
|
||||
// Write the new `./config/studio.json` with credentials.
|
||||
fs.writeFile(path.resolve('config', 'studio.json'), newJSON, 'utf8', function (err) {
|
||||
if (err) {
|
||||
logger.error('Impossible to write the `appId`.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,68 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const path = require('path');
|
||||
|
||||
// Public node modules.
|
||||
const winston = require('winston');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const strapi = require('../lib/server');
|
||||
const packageJSON = require('../package.json');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ 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 current directory as application path.
|
||||
const appPath = process.cwd();
|
||||
|
||||
// Use the app's local `strapi` in `node_modules` if it's existant and valid.
|
||||
const localStrapiPath = path.resolve(appPath, 'node_modules', 'strapi');
|
||||
if (strapi.isLocalStrapiValid(localStrapiPath, appPath)) {
|
||||
const localStrapi = require(localStrapiPath);
|
||||
localStrapi.start(scope, afterwards);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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.
|
||||
const globalStrapi = strapi();
|
||||
globalStrapi.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);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1,86 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const winston = require('winston');
|
||||
|
||||
// Logger.
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({
|
||||
level: 'debug',
|
||||
colorize: 'level'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* `$ strapi update`
|
||||
*
|
||||
* Pull latest update from custom generators
|
||||
* readed from the RC file at $HOME.
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
const HOME = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
|
||||
fs.access(path.resolve(HOME, '.strapirc'), fs.F_OK | fs.R_OK | fs.W_OK, function (err) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
logger.error('No `.strapirc` file detected at `' + HOME + '`.');
|
||||
logger.error('Execute `$ strapi config` to create one.');
|
||||
} else if (err.code === 'EACCES') {
|
||||
logger.error('Impossible to access the `.strapirc` file at `' + HOME + '`.');
|
||||
logger.error('Please check read/write permissions before execute `$ strapi update`.');
|
||||
}
|
||||
process.exit(1);
|
||||
} else {
|
||||
const config = JSON.parse(fs.readFileSync(path.resolve(HOME, '.strapirc')));
|
||||
_.forEach(config.generators, function (info, name) {
|
||||
try {
|
||||
process.chdir(path.resolve(__dirname, '..', 'node_modules', 'strapi-generate-' + name));
|
||||
logger.debug('Pulling the latest updates of `strapi-generate-' + name + '`.');
|
||||
exec('git pull ' + info.remote + ' ' + info.branch, function (err) {
|
||||
if (err) {
|
||||
logger.error('Impossible to update `strapi-generate-' + name + '`.');
|
||||
} else {
|
||||
logger.info('Successfully updated `strapi-generate-' + name + '`.');
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
process.chdir(path.resolve(__dirname, '..', 'node_modules'));
|
||||
logger.debug('Cloning the `strapi-generate-' + name + '` repository for the first time...');
|
||||
exec('git clone ' + info.repository + ' strapi-generate-' + name, function (err) {
|
||||
if (err) {
|
||||
logger.error('Impossible to clone the `strapi-generate-' + name + '` repository.');
|
||||
console.log(err);
|
||||
} else {
|
||||
logger.info('Successfully cloned the `strapi-generate-' + name + '` repository.');
|
||||
process.chdir(path.resolve(__dirname, '..', 'node_modules', 'strapi-generate-' + name));
|
||||
logger.debug('Installing dependencies for `strapi-generate-' + name + '`...');
|
||||
exec('npm install', function (err) {
|
||||
if (err) {
|
||||
logger.error('Impossible to install dependencies for `strapi-generate-' + name + '`.');
|
||||
console.log(err);
|
||||
} else {
|
||||
logger.info('Successfully installed dependencies for `strapi-generate-' + name + '`.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
134
bin/strapi.js
134
bin/strapi.js
@ -1,134 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const program = require('./_commander');
|
||||
const packageJSON = require('../package.json');
|
||||
|
||||
// Needed.
|
||||
const NOOP = function () {};
|
||||
let cmd;
|
||||
|
||||
/**
|
||||
* Normalize version argument
|
||||
*
|
||||
* `$ strapi -v`
|
||||
* `$ strapi -V`
|
||||
* `$ strapi --version`
|
||||
* `$ strapi version`
|
||||
*/
|
||||
|
||||
// Expose version.
|
||||
program.version(packageJSON.version, '-v, --version');
|
||||
|
||||
// Make `-v` option case-insensitive.
|
||||
process.argv = _.map(process.argv, function (arg) {
|
||||
return (arg === '-V') ? '-v' : arg;
|
||||
});
|
||||
|
||||
// `$ strapi version` (--version synonym)
|
||||
cmd = program.command('version');
|
||||
cmd.description('output your version of Strapi');
|
||||
cmd.action(program.versionInformation);
|
||||
|
||||
/**
|
||||
* Basic commands
|
||||
*/
|
||||
|
||||
// `$ strapi new <name>`
|
||||
cmd = program.command('new');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('create a new application ');
|
||||
cmd.action(require('./strapi-new'));
|
||||
cmd.option('-d, --dry', 'naked Strapi application');
|
||||
|
||||
// `$ strapi start`
|
||||
cmd = program.command('start');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('start your Strapi application');
|
||||
cmd.action(require('./strapi-start'));
|
||||
|
||||
// `$ strapi generate <generatorName>`
|
||||
cmd = program.command('generate');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('generate templates from a generator');
|
||||
cmd.action(require('./strapi-generate'));
|
||||
|
||||
// `$ strapi console`
|
||||
cmd = program.command('console');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('open the Strapi framework console');
|
||||
cmd.action(require('./strapi-console'));
|
||||
|
||||
/**
|
||||
* Commands for the Strapi Studio
|
||||
*/
|
||||
|
||||
// `$ strapi link`
|
||||
cmd = program.command('link');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('link an existing application to the Strapi Studio');
|
||||
cmd.action(require('./strapi-link'));
|
||||
|
||||
// `$ strapi login`
|
||||
cmd = program.command('login');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('connect your account to the Strapi Studio');
|
||||
cmd.action(require('./strapi-login'));
|
||||
|
||||
// `$ strapi logout`
|
||||
cmd = program.command('logout');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('logout your account from the Strapi Studio');
|
||||
cmd.action(require('./strapi-logout'));
|
||||
|
||||
/**
|
||||
* Customization commands
|
||||
*/
|
||||
|
||||
// `$ strapi config`
|
||||
cmd = program.command('config');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('extend the Strapi framework with custom generators');
|
||||
cmd.action(require('./strapi-config'));
|
||||
|
||||
// `$ strapi update`
|
||||
cmd = program.command('update');
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description('pull the latest updates of your custom generators');
|
||||
cmd.action(require('./strapi-update'));
|
||||
|
||||
/**
|
||||
* Normalize help argument
|
||||
*/
|
||||
|
||||
// `$ strapi help` (--help synonym)
|
||||
cmd = program.command('help');
|
||||
cmd.description('output the help');
|
||||
cmd.action(program.usageMinusWildcard);
|
||||
|
||||
// `$ strapi <unrecognized_cmd>`
|
||||
// Mask the '*' in `help`.
|
||||
cmd = program.command('*');
|
||||
cmd.action(program.usageMinusWildcard);
|
||||
|
||||
// Don't balk at unknown options.
|
||||
program.unknownOption = NOOP;
|
||||
|
||||
/**
|
||||
* `$ strapi`
|
||||
*/
|
||||
|
||||
program.parse(process.argv);
|
||||
const NO_COMMAND_SPECIFIED = program.args.length === 0;
|
||||
if (NO_COMMAND_SPECIFIED) {
|
||||
program.usageMinusWildcard();
|
||||
}
|
||||
@ -24,14 +24,11 @@
|
||||
"websockets"
|
||||
],
|
||||
"directories": {
|
||||
"bin": "./bin",
|
||||
"lib": "./lib"
|
||||
},
|
||||
"main": "./lib",
|
||||
"bin": "./bin/_spawn.js",
|
||||
"dependencies": {
|
||||
"async": "~1.5.0",
|
||||
"commander": "~2.9.0",
|
||||
"consolidate": "~0.13.1",
|
||||
"fs-extra": "~0.26.2",
|
||||
"grant-koa": "~3.5.3",
|
||||
@ -61,7 +58,6 @@
|
||||
"lodash": "~3.10.1",
|
||||
"node-rsa": "~0.2.26",
|
||||
"node-schedule": "~0.6.0",
|
||||
"prompt": "~0.2.14",
|
||||
"request": "~2.67.0",
|
||||
"socket.io": "~1.3.7",
|
||||
"socket.io-client": "~1.3.7",
|
||||
@ -100,7 +96,6 @@
|
||||
"_"
|
||||
],
|
||||
"ignores": [
|
||||
"bin/_spawn.js",
|
||||
"node_modules/**",
|
||||
"bower_components/**",
|
||||
"coverage/**",
|
||||
@ -160,6 +155,5 @@
|
||||
"node": ">= 4.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"preferGlobal": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user