How to use artifactFiles method in Best

Best JavaScript code snippet using best

fs.js

Source:fs.js Github

copy

Full Screen

1/* @flow */2import type Reporter from '../reporters/base-reporter.js';3import BlockingQueue from './blocking-queue.js';4import * as promise from './promise.js';5import {promisify} from './promise.js';6import map from './map.js';7const path = require('path');8const fs = require('fs');9const os = require('os');10export const lockQueue = new BlockingQueue('fs lock');11export const readFileBuffer = promisify(fs.readFile);12export const writeFile: (path: string, data: string) => Promise<void> = promisify(fs.writeFile);13export const readlink: (path: string, opts: void) => Promise<string> = promisify(fs.readlink);14export const realpath: (path: string, opts: void) => Promise<string> = promisify(fs.realpath);15export const readdir: (path: string, opts: void) => Promise<Array<string>> = promisify(fs.readdir);16export const rename: (oldPath: string, newPath: string) => Promise<void> = promisify(fs.rename);17export const access: (path: string, mode?: number) => Promise<void> = promisify(fs.access);18export const stat: (path: string) => Promise<fs.Stats> = promisify(fs.stat);19export const unlink: (path: string) => Promise<void> = promisify(require('rimraf'));20export const mkdirp: (path: string) => Promise<void> = promisify(require('mkdirp'));21export const exists: (path: string) => Promise<boolean> = promisify(fs.exists, true);22export const lstat: (path: string) => Promise<fs.Stats> = promisify(fs.lstat);23export const chmod: (path: string, mode: number | string) => Promise<void> = promisify(fs.chmod);24export const link: (path: string) => Promise<fs.Stats> = promisify(fs.link);25const CONCURRENT_QUEUE_ITEMS = 4;26const fsSymlink: (27 target: string,28 path: string,29 type?: 'dir' | 'file' | 'junction'30) => Promise<void> = promisify(fs.symlink);31const invariant = require('invariant');32const stripBOM = require('strip-bom');33const noop = () => {};34export type CopyQueueItem = {35 src: string,36 dest: string,37 onFresh?: ?() => void,38 onDone?: ?() => void,39};40type CopyQueue = Array<CopyQueueItem>;41type CopyFileAction = {42 type: 'file',43 src: string,44 dest: string,45 atime: number,46 mtime: number,47 mode: number48};49type LinkFileAction = {50 type: 'link',51 src: string,52 dest: string,53 removeDest: boolean,54};55type CopySymlinkAction = {56 type: 'symlink',57 dest: string,58 linkname: string,59};60type CopyActions = Array<CopyFileAction | CopySymlinkAction | LinkFileAction>;61type CopyOptions = {62 onProgress: (dest: string) => void,63 onStart: (num: number) => void,64 possibleExtraneous: Set<string>,65 ignoreBasenames: Array<string>,66 artifactFiles: Array<string>,67};68async function buildActionsForCopy(69 queue: CopyQueue,70 events: CopyOptions,71 possibleExtraneous: Set<string>,72 reporter: Reporter,73): Promise<CopyActions> {74 const artifactFiles: Set<string> = new Set(events.artifactFiles || []);75 const files: Set<string> = new Set();76 // initialise events77 for (const item of queue) {78 const onDone = item.onDone;79 item.onDone = () => {80 events.onProgress(item.dest);81 if (onDone) {82 onDone();83 }84 };85 }86 events.onStart(queue.length);87 // start building actions88 const actions: CopyActions = [];89 // custom concurrency logic as we're always executing stacks of CONCURRENT_QUEUE_ITEMS queue items90 // at a time due to the requirement to push items onto the queue91 while (queue.length) {92 const items = queue.splice(0, CONCURRENT_QUEUE_ITEMS);93 await Promise.all(items.map(build));94 }95 // simulate the existence of some files to prevent considering them extraenous96 for (const file of artifactFiles) {97 if (possibleExtraneous.has(file)) {98 reporter.verbose(reporter.lang('verboseFilePhantomExtraneous', file));99 possibleExtraneous.delete(file);100 }101 }102 for (const loc of possibleExtraneous) {103 if (files.has(loc)) {104 possibleExtraneous.delete(loc);105 }106 }107 return actions;108 //109 async function build(data): Promise<void> {110 const {src, dest} = data;111 const onFresh = data.onFresh || noop;112 const onDone = data.onDone || noop;113 files.add(dest);114 if (events.ignoreBasenames.indexOf(path.basename(src)) >= 0) {115 // ignored file116 return;117 }118 const srcStat = await lstat(src);119 let srcFiles;120 if (srcStat.isDirectory()) {121 srcFiles = await readdir(src);122 }123 if (await exists(dest)) {124 const destStat = await lstat(dest);125 const bothSymlinks = srcStat.isSymbolicLink() && destStat.isSymbolicLink();126 const bothFolders = srcStat.isDirectory() && destStat.isDirectory();127 const bothFiles = srcStat.isFile() && destStat.isFile();128 if (srcStat.mode !== destStat.mode) {129 try {130 await access(dest, srcStat.mode);131 } catch (err) {132 // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving133 // us modes that aren't valid. investigate this, it's generally safe to proceed.134 }135 }136 if (bothFiles && srcStat.size === destStat.size && +srcStat.mtime === +destStat.mtime) {137 // we can safely assume this is the same file138 onDone();139 reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.size, +srcStat.mtime));140 return;141 }142 if (bothSymlinks) {143 const srcReallink = await readlink(src);144 if (srcReallink === await readlink(dest)) {145 // if both symlinks are the same then we can continue on146 onDone();147 reporter.verbose(reporter.lang('verboseFileSkipSymlink', src, dest, srcReallink));148 return;149 }150 }151 if (bothFolders) {152 // mark files that aren't in this folder as possibly extraneous153 const destFiles = await readdir(dest);154 invariant(srcFiles, 'src files not initialised');155 for (const file of destFiles) {156 if (srcFiles.indexOf(file) < 0) {157 const loc = path.join(dest, file);158 possibleExtraneous.add(loc);159 if ((await lstat(loc)).isDirectory()) {160 for (const file of await readdir(loc)) {161 possibleExtraneous.add(path.join(loc, file));162 }163 }164 }165 }166 }167 }168 if (srcStat.isSymbolicLink()) {169 onFresh();170 const linkname = await readlink(src);171 actions.push({172 type: 'symlink',173 dest,174 linkname,175 });176 onDone();177 } else if (srcStat.isDirectory()) {178 reporter.verbose(reporter.lang('verboseFileFolder', dest));179 await mkdirp(dest);180 const destParts = dest.split(path.sep);181 while (destParts.length) {182 files.add(destParts.join(path.sep));183 destParts.pop();184 }185 // push all files to queue186 invariant(srcFiles, 'src files not initialised');187 let remaining = srcFiles.length;188 if (!remaining) {189 onDone();190 }191 for (const file of srcFiles) {192 queue.push({193 onFresh,194 src: path.join(src, file),195 dest: path.join(dest, file),196 onDone: () => {197 if (--remaining === 0) {198 onDone();199 }200 },201 });202 }203 } else if (srcStat.isFile()) {204 onFresh();205 actions.push({206 type: 'file',207 src,208 dest,209 atime: srcStat.atime,210 mtime: srcStat.mtime,211 mode: srcStat.mode,212 });213 onDone();214 } else {215 throw new Error(`unsure how to copy this: ${src}`);216 }217 }218}219async function buildActionsForHardlink(220 queue: CopyQueue,221 events: CopyOptions,222 possibleExtraneous: Set<string>,223 reporter: Reporter,224): Promise<CopyActions> {225 const artifactFiles: Set<string> = new Set(events.artifactFiles || []);226 const files: Set<string> = new Set();227 // initialise events228 for (const item of queue) {229 const onDone = item.onDone;230 item.onDone = () => {231 events.onProgress(item.dest);232 if (onDone) {233 onDone();234 }235 };236 }237 events.onStart(queue.length);238 // start building actions239 const actions: CopyActions = [];240 // custom concurrency logic as we're always executing stacks of CONCURRENT_QUEUE_ITEMS queue items241 // at a time due to the requirement to push items onto the queue242 while (queue.length) {243 const items = queue.splice(0, CONCURRENT_QUEUE_ITEMS);244 await Promise.all(items.map(build));245 }246 // simulate the existence of some files to prevent considering them extraenous247 for (const file of artifactFiles) {248 if (possibleExtraneous.has(file)) {249 reporter.verbose(reporter.lang('verboseFilePhantomExtraneous', file));250 possibleExtraneous.delete(file);251 }252 }253 for (const loc of possibleExtraneous) {254 if (files.has(loc)) {255 possibleExtraneous.delete(loc);256 }257 }258 return actions;259 //260 async function build(data): Promise<void> {261 const {src, dest} = data;262 const onFresh = data.onFresh || noop;263 const onDone = data.onDone || noop;264 files.add(dest);265 if (events.ignoreBasenames.indexOf(path.basename(src)) >= 0) {266 // ignored file267 return;268 }269 const srcStat = await lstat(src);270 let srcFiles;271 if (srcStat.isDirectory()) {272 srcFiles = await readdir(src);273 }274 const destExists = await exists(dest);275 if (destExists) {276 const destStat = await lstat(dest);277 const bothSymlinks = srcStat.isSymbolicLink() && destStat.isSymbolicLink();278 const bothFolders = srcStat.isDirectory() && destStat.isDirectory();279 const bothFiles = srcStat.isFile() && destStat.isFile();280 if (srcStat.mode !== destStat.mode) {281 try {282 await access(dest, srcStat.mode);283 } catch (err) {284 // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving285 // us modes that aren't valid. investigate this, it's generally safe to proceed.286 reporter.verbose(err);287 }288 }289 // correct hardlink290 if (bothFiles && (srcStat.ino !== null) && (srcStat.ino === destStat.ino)) {291 onDone();292 reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.ino));293 return;294 }295 if (bothSymlinks) {296 const srcReallink = await readlink(src);297 if (srcReallink === await readlink(dest)) {298 // if both symlinks are the same then we can continue on299 onDone();300 reporter.verbose(reporter.lang('verboseFileSkipSymlink', src, dest, srcReallink));301 return;302 }303 }304 if (bothFolders) {305 // mark files that aren't in this folder as possibly extraneous306 const destFiles = await readdir(dest);307 invariant(srcFiles, 'src files not initialised');308 for (const file of destFiles) {309 if (srcFiles.indexOf(file) < 0) {310 const loc = path.join(dest, file);311 possibleExtraneous.add(loc);312 if ((await lstat(loc)).isDirectory()) {313 for (const file of await readdir(loc)) {314 possibleExtraneous.add(path.join(loc, file));315 }316 }317 }318 }319 }320 }321 if (srcStat.isSymbolicLink()) {322 onFresh();323 const linkname = await readlink(src);324 actions.push({325 type: 'symlink',326 dest,327 linkname,328 });329 onDone();330 } else if (srcStat.isDirectory()) {331 reporter.verbose(reporter.lang('verboseFileFolder', dest));332 await mkdirp(dest);333 const destParts = dest.split(path.sep);334 while (destParts.length) {335 files.add(destParts.join(path.sep));336 destParts.pop();337 }338 // push all files to queue339 invariant(srcFiles, 'src files not initialised');340 let remaining = srcFiles.length;341 if (!remaining) {342 onDone();343 }344 for (const file of srcFiles) {345 queue.push({346 onFresh,347 src: path.join(src, file),348 dest: path.join(dest, file),349 onDone: () => {350 if (--remaining === 0) {351 onDone();352 }353 },354 });355 }356 } else if (srcStat.isFile()) {357 onFresh();358 actions.push({359 type: 'link',360 src,361 dest,362 removeDest: destExists,363 });364 onDone();365 } else {366 throw new Error(`unsure how to copy this: ${src}`);367 }368 }369}370export function copy(src: string, dest: string, reporter: Reporter): Promise<void> {371 return copyBulk([{src, dest}], reporter);372}373export async function copyBulk(374 queue: CopyQueue,375 reporter: Reporter,376 _events?: {377 onProgress?: ?(dest: string) => void,378 onStart?: ?(num: number) => void,379 possibleExtraneous: Set<string>,380 ignoreBasenames?: Array<string>,381 artifactFiles?: Array<string>,382 },383): Promise<void> {384 const events: CopyOptions = {385 onStart: (_events && _events.onStart) || noop,386 onProgress: (_events && _events.onProgress) || noop,387 possibleExtraneous: _events ? _events.possibleExtraneous : new Set(),388 ignoreBasenames: (_events && _events.ignoreBasenames) || [],389 artifactFiles: (_events && _events.artifactFiles) || [],390 };391 const actions: CopyActions = await buildActionsForCopy(392 queue,393 events,394 events.possibleExtraneous,395 reporter,396 );397 events.onStart(actions.length);398 const fileActions: Array<CopyFileAction> = (actions.filter((action) => action.type === 'file'): any);399 const currentlyWriting: { [dest: string]: Promise<void> } = {};400 await promise.queue(fileActions, async (data): Promise<void> => {401 let writePromise: Promise<void>;402 while (writePromise = currentlyWriting[data.dest]) {403 await writePromise;404 }405 const cleanup = () => delete currentlyWriting[data.dest];406 return currentlyWriting[data.dest] = new Promise((resolve, reject) => {407 const readStream = fs.createReadStream(data.src);408 const writeStream = fs.createWriteStream(data.dest, {mode: data.mode});409 reporter.verbose(reporter.lang('verboseFileCopy', data.src, data.dest));410 readStream.on('error', reject);411 writeStream.on('error', reject);412 writeStream.on('open', function() {413 readStream.pipe(writeStream);414 });415 writeStream.once('finish', function() {416 fs.utimes(data.dest, data.atime, data.mtime, function(err) {417 if (err) {418 reject(err);419 } else {420 events.onProgress(data.dest);421 cleanup();422 resolve();423 }424 });425 });426 }).then((arg) => {427 cleanup();428 return arg;429 }).catch((arg) => {430 cleanup();431 throw arg;432 });433 }, CONCURRENT_QUEUE_ITEMS);434 // we need to copy symlinks last as they could reference files we were copying435 const symlinkActions: Array<CopySymlinkAction> = (actions.filter((action) => action.type === 'symlink'): any);436 await promise.queue(symlinkActions, (data): Promise<void> => {437 const linkname = path.resolve(path.dirname(data.dest), data.linkname);438 reporter.verbose(reporter.lang('verboseFileSymlink', data.dest, linkname));439 return symlink(linkname, data.dest);440 });441}442export async function hardlinkBulk(443 queue: CopyQueue,444 reporter: Reporter,445 _events?: {446 onProgress?: ?(dest: string) => void,447 onStart?: ?(num: number) => void,448 possibleExtraneous: Set<string>,449 artifactFiles?: Array<string>,450 },451): Promise<void> {452 const events: CopyOptions = {453 onStart: (_events && _events.onStart) || noop,454 onProgress: (_events && _events.onProgress) || noop,455 possibleExtraneous: _events ? _events.possibleExtraneous : new Set(),456 artifactFiles: (_events && _events.artifactFiles) || [],457 ignoreBasenames: [],458 };459 const actions: CopyActions = await buildActionsForHardlink(460 queue,461 events,462 events.possibleExtraneous,463 reporter,464 );465 events.onStart(actions.length);466 const fileActions: Array<LinkFileAction> = (actions.filter((action) => action.type === 'link'): any);467 await promise.queue(fileActions, async (data): Promise<void> => {468 reporter.verbose(reporter.lang('verboseFileLink', data.src, data.dest));469 if (data.removeDest) {470 await unlink(data.dest);471 }472 await link(data.src, data.dest);473 }, CONCURRENT_QUEUE_ITEMS);474 // we need to copy symlinks last as they could reference files we were copying475 const symlinkActions: Array<CopySymlinkAction> = (actions.filter((action) => action.type === 'symlink'): any);476 await promise.queue(symlinkActions, (data): Promise<void> => {477 const linkname = path.resolve(path.dirname(data.dest), data.linkname);478 reporter.verbose(reporter.lang('verboseFileSymlink', data.dest, linkname));479 return symlink(linkname, data.dest);480 });481}482function _readFile(loc: string, encoding: string): Promise<any> {483 return new Promise((resolve, reject) => {484 fs.readFile(loc, encoding, function(err, content) {485 if (err) {486 reject(err);487 } else {488 resolve(content);489 }490 });491 });492}493export function readFile(loc: string): Promise<string> {494 return _readFile(loc, 'utf8').then(normalizeOS);495}496export function readFileRaw(loc: string): Promise<Buffer> {497 return _readFile(loc, 'binary');498}499export async function readFileAny(files: Array<string>): Promise<?string> {500 for (const file of files) {501 if (await exists(file)) {502 return readFile(file);503 }504 }505 return null;506}507export async function readJson(loc: string): Promise<Object> {508 return (await readJsonAndFile(loc)).object;509}510export async function readJsonAndFile(loc: string): Promise<{511 object: Object,512 content: string,513}> {514 const file = await readFile(loc);515 try {516 return {517 object: map(JSON.parse(stripBOM(file))),518 content: file,519 };520 } catch (err) {521 err.message = `${loc}: ${err.message}`;522 throw err;523 }524}525export async function find(filename: string, dir: string): Promise<string | false> {526 const parts = dir.split(path.sep);527 while (parts.length) {528 const loc = parts.concat(filename).join(path.sep);529 if (await exists(loc)) {530 return loc;531 } else {532 parts.pop();533 }534 }535 return false;536}537export async function symlink(src: string, dest: string): Promise<void> {538 try {539 const stats = await lstat(dest);540 if (stats.isSymbolicLink() && await exists(dest)) {541 const resolved = await realpath(dest);542 if (resolved === src) {543 return;544 }545 }546 await unlink(dest);547 } catch (err) {548 if (err.code !== 'ENOENT') {549 throw err;550 }551 }552 try {553 if (process.platform === 'win32') {554 // use directory junctions if possible on win32, this requires absolute paths555 await fsSymlink(src, dest, 'junction');556 } else {557 // use relative paths otherwise which will be retained if the directory is moved558 const relative = path.relative(fs.realpathSync(path.dirname(dest)), fs.realpathSync(src));559 await fsSymlink(relative, dest);560 }561 } catch (err) {562 if (err.code === 'EEXIST') {563 // race condition564 await symlink(src, dest);565 } else {566 throw err;567 }568 }569}570export type WalkFiles = Array<{571 relative: string,572 absolute: string,573 basename: string,574 mtime: number,575}>;576export async function walk(577 dir: string,578 relativeDir?: ?string,579 ignoreBasenames?: Set<string> = new Set(),580): Promise<WalkFiles> {581 let files = [];582 let filenames = await readdir(dir);583 if (ignoreBasenames.size) {584 filenames = filenames.filter((name) => !ignoreBasenames.has(name));585 }586 for (const name of filenames) {587 const relative = relativeDir ? path.join(relativeDir, name) : name;588 const loc = path.join(dir, name);589 const stat = await lstat(loc);590 files.push({591 relative,592 basename: name,593 absolute: loc,594 mtime: +stat.mtime,595 });596 if (stat.isDirectory()) {597 files = files.concat(await walk(loc, relative, ignoreBasenames));598 }599 }600 return files;601}602export async function getFileSizeOnDisk(loc: string): Promise<number> {603 const stat = await lstat(loc);604 const {size, blksize: blockSize} = stat;605 return (Math.ceil(size / blockSize) * blockSize);606}607export function normalizeOS(body: string): string {608 return body.replace(/\r\n/g, '\n');609}610const cr = new Buffer('\r', 'utf8')[0];611const lf = new Buffer('\n', 'utf8')[0];612async function getEolFromFile(path: string) : Promise<string | void> {613 if (!(await exists(path))) {614 return undefined;615 }616 const buffer = await readFileBuffer(path);617 for (let i = 0; i < buffer.length; ++i) {618 if (buffer[i] === cr) {619 return '\r\n';620 }621 if (buffer[i] === lf) {622 return '\n';623 }624 }625 return undefined;626}627export async function writeFilePreservingEol(path: string, data: string) : Promise<void> {628 const eol = (await getEolFromFile(path)) || os.EOL;629 if (eol !== '\n') {630 data = data.replace(/\n/g, eol);631 }632 await promisify(fs.writeFile)(path, data);633}634export async function hardlinksWork(dir: string): Promise<boolean> {635 const filename = 'test-file' + Math.random();636 const file = path.join(dir, filename);637 const fileLink = path.join(dir, filename + '-link');638 try {639 await writeFile(file, 'test');640 await link(file, fileLink);641 } catch (err) {642 return false;643 } finally {644 await unlink(file);645 await unlink(fileLink);646 }647 return true;648}649// not a strict polyfill for Node's fs.mkdtemp650export async function makeTempDir(prefix?: string): Promise<string> {651 const dir = path.join(652 os.tmpdir(),653 `yarn-${prefix || ''}-${Date.now()}-${Math.random()}`,654 );655 await unlink(dir);656 await mkdirp(dir);657 return dir;...

Full Screen

Full Screen

artifact-files.ts

Source:artifact-files.ts Github

copy

Full Screen

1import fs from 'fs-extra';2import path from 'path';3import R from 'ramda';4import { BitId } from '../../../bit-id';5import ShowDoctorError from '../../../error/show-doctor-error';6import logger from '../../../logger/logger';7import { Scope } from '../../../scope';8import ScopeComponentsImporter from '../../../scope/component-ops/scope-components-importer';9import { Source } from '../../../scope/models';10import { Ref } from '../../../scope/objects';11import { pathNormalizeToLinux } from '../../../utils';12import { ExtensionDataList } from '../../config';13import Component from '../consumer-component';14import { ArtifactVinyl } from './artifact';15export type ArtifactRef = { relativePath: string; ref: Ref; url?: string };16export type ArtifactModel = { relativePath: string; file: string; url?: string };17export type ArtifactSource = { relativePath: string; source: Source; url?: string };18export type ArtifactObject = {19 name: string;20 description?: string;21 generatedBy: string;22 storage: string;23 task: {24 id: string; // aspect-id25 name?: string;26 };27 files: ArtifactFiles;28};29type ArtifactFilesObject = {30 paths?: string[];31 vinyls?: ArtifactVinyl[];32 refs?: ArtifactRef[];33};34/**35 * Artifacts utilize lazy loading mechanism. As such, when loading them from the objects, they are36 * not converted to ArtifactVinyl[]. Instead, they are loaded as ArtifactRef[].37 * Later, when they're needed, the `getVinylsAndImportIfMissing` method is used to load them and if38 * needed, to import them from a remote.39 *40 * the workflow of an artifact during the tag is as follows:41 * 1. First, it got created on a capsule and saved to the ConsumerComponent as ArtifactVinyl.42 * 2. On tag, it is transformed to ArtifactSource in order to save the Sources (BitObjects) in the objects.43 * 3. Finally, once the Version object is saved, it needs to save only the hash of the artifacts, hence ArtifactModel.44 */45export class ArtifactFiles {46 constructor(public paths: string[] = [], public vinyls: ArtifactVinyl[] = [], public refs: ArtifactRef[] = []) {}47 clone() {48 const vinyls = this.vinyls.map((vinyl) => vinyl.clone());49 const refs = this.refs.map((ref) => ({ ...ref }));50 return new ArtifactFiles({ ...this.paths }, vinyls, refs);51 }52 populateRefsFromSources(sources: ArtifactSource[]) {53 this.refs = sources.map((source) => ({54 relativePath: source.relativePath,55 ref: source.source.hash(),56 url: source.url,57 }));58 }59 populateVinylsFromPaths(rootDir: string) {60 this.vinyls = this.paths.map(61 (file) => new ArtifactVinyl({ path: file, contents: fs.readFileSync(path.join(rootDir, file)) })62 );63 }64 getExistingVinyls() {65 return this.vinyls;66 }67 isEmpty() {68 return !this.vinyls.length && !this.refs.length && !this.paths.length;69 }70 static fromModel(artifactModels: ArtifactModel[] = []) {71 const refs: ArtifactRef[] = artifactModels.map((artifactModel) => ({72 relativePath: artifactModel.relativePath,73 ref: Ref.from(artifactModel.file),74 url: artifactModel.url,75 }));76 return new ArtifactFiles([], [], refs);77 }78 static fromObject(obj: ArtifactFilesObject) {79 const refs = obj.refs?.map((ref) => {80 const artifactRef: ArtifactRef = {81 relativePath: ref.relativePath,82 url: ref.url,83 ref: new Ref(ref.ref.hash),84 };85 return artifactRef;86 });87 return new ArtifactFiles(obj.paths, obj.vinyls, refs);88 }89 static fromVinylsToSources(vinyls: ArtifactVinyl[]): ArtifactSource[] {90 return vinyls.map((artifact) => {91 return {92 relativePath: pathNormalizeToLinux(artifact.relative),93 source: artifact.toSourceAsLinuxEOL(),94 url: artifact.url,95 };96 });97 }98 async getVinylsAndImportIfMissing(id: BitId, scope: Scope): Promise<ArtifactVinyl[]> {99 if (this.isEmpty()) return [];100 if (this.vinyls.length) return this.vinyls;101 const allHashes = this.refs.map((artifact) => artifact.ref.hash);102 const scopeComponentsImporter = ScopeComponentsImporter.getInstance(scope);103 const lane = await scope.getCurrentLaneObject();104 const isIdOnLane = lane?.toBitIds().hasWithoutVersion(id);105 const scopeName = isIdOnLane ? (lane?.scope as string) : (id.scope as string);106 await scopeComponentsImporter.importManyObjects({ [scopeName]: allHashes });107 const getOneArtifact = async (artifact: ArtifactRef) => {108 const content = (await artifact.ref.load(scope.objects)) as Source;109 if (!content) throw new ShowDoctorError(`failed loading file ${artifact.relativePath} from the model`);110 return new ArtifactVinyl({111 base: '.',112 path: artifact.relativePath,113 contents: content.contents,114 url: artifact.url,115 });116 };117 this.vinyls = await Promise.all(this.refs.map((artifact) => getOneArtifact(artifact)));118 return this.vinyls;119 }120}121export async function importMultipleDistsArtifacts(scope: Scope, components: Component[]) {122 logger.debug(123 `importMultipleDistsArtifacts: ${components.length} components: ${components124 .map((c) => c.id.toString())125 .join(', ')}`126 );127 const extensionsNamesForDistArtifacts = 'teambit.compilation/compiler';128 const lane = await scope.getCurrentLaneObject();129 const laneIds = lane?.toBitIds();130 const groupedHashes: { [scopeName: string]: string[] } = {};131 await Promise.all(132 components.map(async (component) => {133 const artifactsFiles = getArtifactFilesByExtension(component.extensions, extensionsNamesForDistArtifacts);134 const scopeName = (await scope.isIdOnLane(component.id, lane, laneIds))135 ? (lane?.scope as string)136 : (component.scope as string);137 artifactsFiles.forEach((artifactFiles) => {138 if (!artifactFiles) return;139 if (!(artifactFiles instanceof ArtifactFiles)) {140 artifactFiles = deserializeArtifactFiles(artifactFiles);141 }142 if (artifactFiles.isEmpty()) return;143 if (artifactFiles.vinyls.length) return;144 const allHashes = artifactFiles.refs.map((artifact) => artifact.ref.hash);145 (groupedHashes[scopeName] ||= []).push(...allHashes);146 });147 })148 );149 const scopeComponentsImporter = ScopeComponentsImporter.getInstance(scope);150 await scopeComponentsImporter.importManyObjects(groupedHashes);151 logger.debug(`importMultipleDistsArtifacts: ${components.length} components. completed successfully`);152}153export function refsToModelObjects(refs: ArtifactRef[]): ArtifactModel[] {154 return refs.map((artifact) => {155 return {156 relativePath: artifact.relativePath,157 file: artifact.ref.hash,158 url: artifact.url,159 };160 });161}162export function getRefsFromExtensions(extensions: ExtensionDataList): Ref[] {163 const artifactsFiles = getArtifactsFiles(extensions);164 const refs = artifactsFiles.map((artifactFiles) => artifactFiles.refs.map((r) => r.ref));165 return R.flatten(refs).filter((ref) => ref);166}167export function getArtifactFilesByExtension(extensions: ExtensionDataList, extensionName: string): ArtifactFiles[] {168 const buildArtifacts = getBuildArtifacts(extensions);169 return buildArtifacts.filter((artifact) => artifact.task.id === extensionName).map((artifact) => artifact.files);170}171export function convertBuildArtifactsToModelObject(extensions: ExtensionDataList) {172 const buildArtifacts = getBuildArtifacts(extensions);173 buildArtifacts.forEach((artifact) => {174 // @ts-ignore175 artifact.files = refsToModelObjects(artifact.files.refs);176 });177}178export function convertBuildArtifactsFromModelObject(extensions: ExtensionDataList) {179 const artifactObjects = getBuildArtifacts(extensions);180 artifactObjects.forEach((artifactObject) => {181 // @ts-ignore182 artifactObject.files = ArtifactFiles.fromModel(artifactObject.files);183 });184}185export function getArtifactsFiles(extensions: ExtensionDataList): ArtifactFiles[] {186 const buildArtifacts = getBuildArtifacts(extensions);187 return buildArtifacts.map((artifacts) => artifacts.files);188}189export function reStructureBuildArtifacts(extensions: ExtensionDataList) {190 const buildArtifacts = getBuildArtifacts(extensions);191 buildArtifacts.forEach((artifacts) => {192 artifacts.files = deserializeArtifactFiles(artifacts.files);193 });194}195export function deserializeArtifactFiles(obj: { paths: string[]; vinyls: ArtifactVinyl[]; refs: ArtifactRef[] }) {196 const refs = obj.refs.map((ref) => ({197 relativePath: ref.relativePath,198 ref: new Ref(ref.ref.hash),199 url: ref.url,200 }));201 return new ArtifactFiles(obj.paths, obj.vinyls, refs);202}203function getBuildArtifacts(extensions: ExtensionDataList): ArtifactObject[] {204 return extensions.findExtension('teambit.pipelines/builder')?.data?.artifacts || [];...

Full Screen

Full Screen

uploadArtifacts.ts

Source:uploadArtifacts.ts Github

copy

Full Screen

1import { create } from '@actions/artifact';2import { debug, info } from '@actions/core';3import fs from 'fs-extra';4import path from 'path';5import { artifactApi } from './artifactApi';6import { cacheDir } from './constants';7export async function uploadArtifacts() {8 const list = await artifactApi.listArtifacts();9 const existingArtifacts = (list.artifacts || []).map(10 (artifact) => artifact.name11 );12 const client = create();13 const files = fs.readdirSync(cacheDir);14 const artifactFiles = files.filter((filename) => filename.endsWith('.gz'));15 debug(`artifact files: ${JSON.stringify(artifactFiles, null, 2)}`);16 const artifactsToUpload = artifactFiles17 .map((artifactFilename) => {18 const artifactId = path.basename(19 artifactFilename,20 path.extname(artifactFilename)21 );22 return { artifactFilename, artifactId };23 })24 .filter(({ artifactId }) => !existingArtifacts.includes(artifactId));25 if (artifactsToUpload.length) {26 info(`Gonna upload ${artifactsToUpload.length} artifacts:`);27 info(28 JSON.stringify(29 artifactsToUpload.map(({ artifactId }) => artifactId),30 null,31 232 )33 );34 } else {35 info(`There is nothing to upload.`);36 }37 await Promise.all(38 artifactsToUpload.map(async ({ artifactFilename, artifactId }) => {39 info(`Uploading ${artifactFilename}`);40 await client.uploadArtifact(41 artifactId,42 [path.join(cacheDir, artifactFilename)],43 cacheDir44 );45 info(`Uploaded ${artifactFilename} successfully`);46 })47 );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var artifactFiles = require('best-practices').artifactFiles;2var files = artifactFiles('test4.js');3console.log(files);4var artifactFiles = require('best-practices').artifactFiles;5var files = artifactFiles('test5.js');6console.log(files);7var artifactFiles = require('best-practices').artifactFiles;8var files = artifactFiles('test6.js');9console.log(files);10var artifactFiles = require('best-practices').artifactFiles;11var files = artifactFiles('test7.js');12console.log(files);13var artifactFiles = require('best-practices').artifactFiles;14var files = artifactFiles('test8.js');15console.log(files);16var artifactFiles = require('best-practices').artifactFiles;17var files = artifactFiles('test9.js');18console.log(files);19var artifactFiles = require('best-practices').artifactFiles;20var files = artifactFiles('test10.js');21console.log(files);22var artifactFiles = require('best-practices').artifactFiles;23var files = artifactFiles('test11.js');24console.log(files);25var artifactFiles = require('best-practices').artifactFiles;26var files = artifactFiles('test12.js');27console.log(files);28var artifactFiles = require('best-practices').artifactFiles;29var files = artifactFiles('test13.js');30console.log(files);31var artifactFiles = require('best-practices').artifactFiles;32var files = artifactFiles('test14.js');33console.log(files);

Full Screen

Using AI Code Generation

copy

Full Screen

1var bpt = require('best-practice-test');2var fs = require('fs');3bpt.artifactFiles('test4.js', function(err, files) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Files: ' + files);8 }9});10var bpt = require('best-practice-test');11var fs = require('fs');12bpt.artifactFiles('test4.js', function(err, files) {13 if (err) {14 console.log('Error: ' + err);15 } else {16 console.log('Files: ' + files);17 }18});19var bpt = require('best-practice-test');20var fs = require('fs');21bpt.artifactFiles('test4.js', function(err, files) {22 if (err) {23 console.log('Error: ' + err);24 } else {25 console.log('Files: ' + files);26 }27});28var bpt = require('best-practice-test');29var fs = require('fs');30bpt.artifactFiles('test4.js', function(err, files) {31 if (err) {32 console.log('Error: ' + err);33 } else {34 console.log('Files: ' + files);35 }36});37var bpt = require('best-practice-test');38var fs = require('fs');39bpt.artifactFiles('test4.js', function(err, files) {40 if (err) {41 console.log('Error: ' + err);42 } else {43 console.log('Files: ' + files);44 }45});46var bpt = require('best-practice-test');47var fs = require('fs');48bpt.artifactFiles('test4.js', function(err, files) {49 if (err) {50 console.log('Error: ' + err);51 } else {52 console.log('Files: ' + files);53 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var bp = require('bestpractice');2bp.artifactFiles('test4.js', function (err, files) {3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('files: ' + files);7 }8});9var bp = require('bestpractice');10bp.artifactFiles('test5.js', function (err, files) {11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log('files: ' + files);15 }16});17var bp = require('bestpractice');18bp.artifactFiles('test6.js', function (err, files) {19 if (err) {20 console.log('Error: ' + err);21 } else {22 console.log('files: ' + files);23 }24});25var bp = require('bestpractice');26bp.artifactFiles('test7.js', function (err, files) {27 if (err) {28 console.log('Error: ' + err);29 } else {30 console.log('files: ' + files);31 }32});33var bp = require('bestpractice');34bp.artifactFiles('test8.js', function (err, files) {35 if (err) {36 console.log('Error: ' + err);37 } else {38 console.log('files: ' + files);39 }40});41var bp = require('bestpractice');42bp.artifactFiles('test9.js', function (err, files) {43 if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var artifactFiles = require('bestpractice').artifactFiles;2var files = artifactFiles('builds/1.0.0');3files.forEach(function(file){4 console.log(file);5});6var artifactFiles = require('bestpractice').artifactFiles;7var files = artifactFiles('builds/1.0.0', 'builds/1.0.1');8files.forEach(function(file){9 console.log(file);10});11var artifactFiles = require('bestpractice').artifactFiles;12var files = artifactFiles('builds/1.0.0', 'builds/1.0.1', 'builds/1.0.2');13files.forEach(function(file){14 console.log(file);15});16var artifactFiles = require('bestpractice').artifactFiles;17var files = artifactFiles('builds/1.0.0', 'builds/1.0.1', 'builds/1.0.2', 'builds/1.0.3');18files.forEach(function(file){19 console.log(file);20});21var artifactFiles = require('bestpractice').artifactFiles;22var files = artifactFiles('builds/1.0.0', 'builds/1.0.1', 'builds/1.0.2', 'builds/1.0.3', 'builds/1.0.4');23files.forEach(function(file){24 console.log(file);25});26var artifactFiles = require('bestpractice').artifactFiles;27var files = artifactFiles('builds/1.0.0', 'builds/1.0.1', 'builds/1.0.2', 'builds/1.0.3', 'builds/1.0.4', 'builds/1.0.5');28files.forEach(function(file){29 console.log(file);30});

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPractice = require('./bestpractice');2var bestPractice = new BestPractice();3var options = {4};5bestPractice.run(options, function (err, results) {6 if (err) {7 console.log(err);8 }9 console.log(results);10});11var BestPractice = require('./bestpractice');12var bestPractice = new BestPractice();13var options = {14 {15 },16 {17 },18 {19 }20};21bestPractice.run(options, function (err, results) {22 if (err) {23 console.log(err);24 }25 console.log(results);26});27var BestPractice = require('./bestpractice');28var bestPractice = new BestPractice();29var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var artifactFiles = require('best-practice-4');2artifactFiles.zipFiles('testData.zip', 'testData');3artifactFiles.tarFiles('testData.tar', 'testData');4artifactFiles.tarGzFiles('testData.tar.gz', 'testData');5artifactFiles.tarGzFiles('testData.tar.gz', 'testData', 'password');6artifactFiles.tarGzFiles('testData.tar.gz', 'testData', 'password', 'testData/test2.txt');7artifactFiles.tarGzFiles('testData.tar.gz', 'testData', 'password', 'testData/test2.txt', function(err) {8 if (err) {9 console.log(err);10 }11});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful