@appsignal/cli
Advanced tools
Comparing version 1.1.18 to 1.2.0
# AppSignal CLI changelog | ||
## 1.2.0 | ||
### Added | ||
- [7492997](https://github.com/appsignal/appsignal-javascript/commit/74929977f8c961180fd1077363cd19fba085af87) minor - Installer writes appsignal.js configuration file | ||
## 1.1.18 | ||
@@ -4,0 +10,0 @@ |
@@ -47,3 +47,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pkg, integration, error_1; | ||
var integration, error_1; | ||
return __generator(this, function (_a) { | ||
@@ -53,11 +53,2 @@ switch (_a.label) { | ||
console.log("🚀 Alright! Let's install AppSignal to your project!"); | ||
try { | ||
console.log("🔭 Checking for your package.json..."); | ||
pkg = require("".concat(process.cwd(), "/package.json")); | ||
console.log("✅ Found it!"); | ||
} | ||
catch (e) { | ||
console.error("Couldn't find a package.json in your current working directory"); | ||
throw e; | ||
} | ||
_a.label = 1; | ||
@@ -84,3 +75,3 @@ case 1: | ||
if (!(integration === "nodejs")) return [3, 4]; | ||
return [4, (0, node_1.installNode)(pkg)]; | ||
return [4, (0, node_1.installNode)(process.cwd())]; | ||
case 3: | ||
@@ -87,0 +78,0 @@ _a.sent(); |
@@ -1,4 +0,2 @@ | ||
export declare function installNode(pkg: { | ||
[key: string]: any; | ||
}): Promise<void>; | ||
export declare function installNode(dir: string): Promise<void>; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,27 +61,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -74,82 +72,102 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var core_1 = require("@appsignal/core"); | ||
var constants_1 = require("../../constants"); | ||
var fs = __importStar(require("fs")); | ||
var path = __importStar(require("path")); | ||
var demo_1 = require("../../commands/demo"); | ||
var displayOutroMessage = function (pushApiKey, name) { return "\n\uD83C\uDF89 ".concat(chalk_1.default.greenBright("Great news!"), " You've just installed AppSignal to your project!\n\nThe next step is adding your Push API key to your project. The best way to do this is with an environment variable:\n\n").concat(chalk_1.default.bold("export APPSIGNAL_PUSH_API_KEY=\"".concat(pushApiKey, "\"")), "\n\nIf you're using a cloud provider such as Heroku etc., seperate instructions on how to add these environment variables are available in our documentation:\n\n\uD83D\uDD17 https://docs.appsignal.com/nodejs/configuration\n\nThen, you'll need to initalize AppSignal in your app. Please ensure that this is done in the entrypoint of your application, ").concat(chalk_1.default.cyan("before all other dependencies are imported!"), "\n\n").concat(chalk_1.default.bold("const { Appsignal } = require(\"@appsignal/nodejs\");\n\nconst appsignal = new Appsignal({\n active: true,\n name: \"".concat(name, "\"\n});")), "\n\nSome integrations require additional setup. See https://docs.appsignal.com/nodejs/integrations/ for more information.\n\nNeed any further help? Feel free to ask a human at ").concat(chalk_1.default.bold("support@appsignal.com"), "!\n"); }; | ||
function installNode(pkg) { | ||
function installNode(dir) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cwd, _a, pushApiKey, name, isUsingYarn, modules, shouldInstallNow, mods; | ||
var _a, pushApiKey, name, isUsingYarn, method, filename, overwrite, configExists, useConfigFile; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
cwd = process.cwd(); | ||
return [4, inquirer_1.default.prompt([ | ||
{ | ||
type: "input", | ||
name: "pushApiKey", | ||
message: "What's your Push API Key?", | ||
validate: validateApiKey | ||
}, | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What should we call your application?", | ||
default: "My App" | ||
} | ||
])]; | ||
case 0: return [4, inquirer_1.default.prompt([ | ||
{ | ||
type: "input", | ||
name: "pushApiKey", | ||
message: "What's your Push API Key?", | ||
validate: validateApiKey | ||
}, | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "What should we call your application?", | ||
default: "My App" | ||
} | ||
])]; | ||
case 1: | ||
_a = _b.sent(), pushApiKey = _a.pushApiKey, name = _a.name; | ||
isUsingYarn = (0, fs_1.existsSync)("".concat(cwd, "/yarn.lock")); | ||
modules = Object.keys(pkg.dependencies || {}) | ||
.map(function (dep) { return constants_1.SUPPORTED_NODEJS_INTEGRATIONS[dep]; }) | ||
.filter(function (dep) { return dep; }); | ||
console.log(); | ||
if (modules.length > 0) { | ||
console.log("We found ".concat(chalk_1.default.cyan(modules.length), " integration").concat(modules.length !== 1 ? "s" : "", " for the modules that you currently have installed:")); | ||
console.log(); | ||
modules.forEach(function (mod) { return console.log("".concat(mod)); }); | ||
isUsingYarn = (0, fs_1.existsSync)("".concat(dir, "/yarn.lock")); | ||
if (isUsingYarn) { | ||
(0, child_process_1.spawnSync)("yarn", ["add", "@appsignal/nodejs"], { | ||
cwd: dir, | ||
stdio: "inherit" | ||
}); | ||
} | ||
else { | ||
console.log("We couldn't find any integrations for the modules you currently have installed."); | ||
(0, child_process_1.spawnSync)("npm", ["install", "--save", "@appsignal/nodejs"], { | ||
cwd: dir, | ||
stdio: "inherit" | ||
}); | ||
} | ||
console.log(); | ||
(0, demo_1.spawnDemo)({ | ||
APPSIGNAL_APP_ENV: "development", | ||
APPSIGNAL_APP_NAME: name, | ||
APPSIGNAL_PUSH_API_KEY: pushApiKey | ||
}); | ||
return [4, inquirer_1.default.prompt([ | ||
{ | ||
type: "list", | ||
name: "method", | ||
message: "Which method of configuring AppSignal in your project do you prefer?", | ||
choices: [ | ||
"Using an appsignal.cjs configuration file.", | ||
"Using system environment variables." | ||
], | ||
default: "Using an appsignal.cjs configuration file." | ||
} | ||
])]; | ||
case 2: | ||
method = (_b.sent()).method; | ||
filename = configurationFilename(dir); | ||
overwrite = false; | ||
configExists = fs.existsSync(path.join(dir, filename)); | ||
useConfigFile = method == "Using an appsignal.cjs configuration file."; | ||
if (!configExists) return [3, 4]; | ||
; | ||
return [4, inquirer_1.default.prompt([ | ||
{ | ||
type: "confirm", | ||
name: "shouldInstallNow", | ||
message: modules.length > 0 | ||
? "Do you want to install these now?" | ||
: "Continue installing just the core @appsignal/nodejs package?", | ||
default: true | ||
name: "overwrite", | ||
message: "${filename} already exists. Overwrite?" | ||
} | ||
])]; | ||
case 2: | ||
shouldInstallNow = (_b.sent()).shouldInstallNow; | ||
case 3: | ||
(overwrite = (_b.sent()).overwrite); | ||
_b.label = 4; | ||
case 4: | ||
if (!configExists || (configExists && overwrite)) { | ||
console.log(); | ||
console.log("Writing ".concat(filename, " configuration file.")); | ||
fs.writeFileSync(path.join(dir, filename), "const { Appsignal } = require(\"@appsignal/nodejs\");\n\n" + | ||
"new Appsignal({\n" + | ||
" active: true,\n" + | ||
" name: \"".concat(name, "\",\n") + | ||
(useConfigFile ? " pushApiKey: \"".concat(pushApiKey, "\",\n") : "") + | ||
"});\n"); | ||
} | ||
console.log(); | ||
modules.unshift("@appsignal/nodejs"); | ||
if (shouldInstallNow) { | ||
if (isUsingYarn) { | ||
(0, child_process_1.spawnSync)("yarn", __spreadArray(["add"], __read(modules), false), { | ||
cwd: cwd, | ||
stdio: "inherit" | ||
}); | ||
} | ||
else { | ||
(0, child_process_1.spawnSync)("npm", __spreadArray(["install", "--save"], __read(modules), false), { | ||
cwd: cwd, | ||
stdio: "inherit" | ||
}); | ||
} | ||
(0, demo_1.spawnDemo)({ | ||
APPSIGNAL_APP_ENV: "development", | ||
APPSIGNAL_APP_NAME: name, | ||
APPSIGNAL_PUSH_API_KEY: pushApiKey | ||
}); | ||
if (configExists && !overwrite) { | ||
console.log("Not writing appsignal.cjs configuration file. Exiting."); | ||
} | ||
else { | ||
mods = modules.join(" "); | ||
console.log("\uD83D\uDC4D OK! We won't install anything right now. You can add these packages later by running:"); | ||
console.log("\uD83C\uDF89 ".concat(chalk_1.default.greenBright("Great news!"), " You've just installed AppSignal to your project!")); | ||
console.log(); | ||
console.log(chalk_1.default.bold(isUsingYarn ? "yarn add ".concat(mods) : "npm install --save ".concat(mods))); | ||
console.log("Now, you can run your application like you normally would, but use the --require flag to load AppSignal's instrumentation before any other library:"); | ||
console.log(); | ||
console.log(" node --require './".concat(filename, "' index.js")); | ||
if (!useConfigFile) { | ||
console.log(); | ||
console.log("You've chosen to use environment variables to configure AppSignal:\n\n export APPSIGNAL_PUSH_API_KEY=\"".concat(pushApiKey, "\"\n\nIf you're using a cloud provider such as Heroku etc., seperate instructions on how to add these environment variables are available in our documentation:\n\n \uD83D\uDD17 https://docs.appsignal.com/nodejs/configuration")); | ||
} | ||
console.log(); | ||
console.log("Some integrations require additional setup. See https://docs.appsignal.com/nodejs/integrations/ for more information.\n\nNeed any further help? Feel free to ask a human at ".concat(chalk_1.default.bold("support@appsignal.com"), "!")); | ||
} | ||
console.log(displayOutroMessage(pushApiKey, name)); | ||
return [2]; | ||
@@ -188,2 +206,11 @@ } | ||
} | ||
function configurationFilename(dir) { | ||
var src = path.join(dir, "src"); | ||
if (fs.existsSync(src) && fs.lstatSync(src).isDirectory()) { | ||
return "src/appsignal.cjs"; | ||
} | ||
else { | ||
return "appsignal.cjs"; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@appsignal/cli", | ||
"version": "1.1.18", | ||
"version": "1.2.0", | ||
"main": "./dist/index", | ||
@@ -16,3 +16,3 @@ "repository": { | ||
"link:yarn": "yarn link", | ||
"test": "jest --passWithNoTests", | ||
"test": "jest", | ||
"test:watch": "jest --watch" | ||
@@ -19,0 +19,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49926
36
499
11