Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.2 KiB
138 lines
3.2 KiB
2 years ago
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.Npm = void 0;
|
||
|
|
||
|
function _fs() {
|
||
|
const data = _interopRequireDefault(require("fs"));
|
||
|
|
||
|
_fs = function () {
|
||
|
return data;
|
||
|
};
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
function _path() {
|
||
|
const data = _interopRequireDefault(require("path"));
|
||
|
|
||
|
_path = function () {
|
||
|
return data;
|
||
|
};
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
function _crossSpawn() {
|
||
|
const data = _interopRequireDefault(require("cross-spawn"));
|
||
|
|
||
|
_crossSpawn = function () {
|
||
|
return data;
|
||
|
};
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
function _logger() {
|
||
|
const data = _interopRequireDefault(require("@parcel/logger"));
|
||
|
|
||
|
_logger = function () {
|
||
|
return data;
|
||
|
};
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
var _promiseFromProcess = _interopRequireDefault(require("./promiseFromProcess"));
|
||
|
|
||
|
function _core() {
|
||
|
const data = require("@parcel/core");
|
||
|
|
||
|
_core = function () {
|
||
|
return data;
|
||
|
};
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
var _utils = require("./utils");
|
||
|
|
||
|
var _package = _interopRequireDefault(require("../package.json"));
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
// $FlowFixMe
|
||
|
const NPM_CMD = 'npm';
|
||
|
|
||
|
class Npm {
|
||
|
async install({
|
||
|
modules,
|
||
|
cwd,
|
||
|
packagePath,
|
||
|
saveDev = true
|
||
|
}) {
|
||
|
// npm doesn't auto-create a package.json when installing,
|
||
|
// so create an empty one if needed.
|
||
|
if (packagePath == null) {
|
||
|
await _fs().default.writeFile(_path().default.join(cwd, 'package.json'), '{}');
|
||
|
}
|
||
|
|
||
|
let args = ['install', '--json', saveDev ? '--save-dev' : '--save'].concat(modules.map(_utils.npmSpecifierFromModuleRequest)); // When Parcel is run by npm (e.g. via package.json scripts), several environment variables are
|
||
|
// added. When parcel in turn calls npm again, these can cause npm to behave stragely, so we
|
||
|
// filter them out when installing packages.
|
||
|
|
||
|
let env = {};
|
||
|
|
||
|
for (let key in process.env) {
|
||
|
if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
||
|
env[key] = process.env[key];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let installProcess = (0, _crossSpawn().default)(NPM_CMD, args, {
|
||
|
cwd,
|
||
|
env
|
||
|
});
|
||
|
let stdout = '';
|
||
|
installProcess.stdout.on('data', buf => {
|
||
|
stdout += buf.toString();
|
||
|
});
|
||
|
let stderr = [];
|
||
|
installProcess.stderr.on('data', buf => {
|
||
|
stderr.push(buf.toString().trim());
|
||
|
});
|
||
|
|
||
|
try {
|
||
|
await (0, _promiseFromProcess.default)(installProcess);
|
||
|
let results = JSON.parse(stdout);
|
||
|
let addedCount = results.added.length;
|
||
|
|
||
|
if (addedCount > 0) {
|
||
|
_logger().default.log({
|
||
|
origin: '@parcel/package-manager',
|
||
|
message: `Added ${addedCount} packages via npm`
|
||
|
});
|
||
|
} // Since we succeeded, stderr might have useful information not included
|
||
|
// in the json written to stdout. It's also not necessary to log these as
|
||
|
// errors as they often aren't.
|
||
|
|
||
|
|
||
|
for (let message of stderr) {
|
||
|
if (message.length > 0) {
|
||
|
_logger().default.log({
|
||
|
origin: '@parcel/package-manager',
|
||
|
message
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
} catch (e) {
|
||
|
throw new Error('npm failed to install modules: ' + e.message + ' - ' + stderr.join('\n'));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
exports.Npm = Npm;
|
||
|
(0, _core().registerSerializableClass)(`${_package.default.version}:Npm`, Npm);
|