How to use cleanPaths method in storybook-root

Best JavaScript code snippet using storybook-root

workflow-build.js

Source:workflow-build.js Github

copy

Full Screen

1// -----------------------------------------------------2// WORKFLOW -- "BUILD" PHASE3// -----------------------------------------------------4/*5*/6// =======7// Config Settings for Module8// =======9var yaml = require('yamljs');10var config = yaml.load('src/config.yml');11var build_order = config['build-order'];12var build = config['build-steps'];13//var moveFiles = require('move');14// =======15// Dependencies16// =======17var gulp = require('gulp');18var changed = require('gulp-changed');19var browserSync = require('browser-sync');20var notify = require("gulp-notify");21var runSequence = require('run-sequence');22var gulpWatch = require('gulp-watch');23var concat = require('gulp-concat-util');24var gulpif = require('gulp-if');25var notify = require('gulp-notify');26var del = require('del');27var copy = require('recursive-copy');28var isGlob = require('is-glob');29var path = require('path');30// =======31// Task Functionality:32// We abstract our tasks to functions so we can require the meeat & bones elsewhere if necessary33// =======34var buildChain = function() {35 cleanOut // clean36 .then(function () {37 buildProject(); // build38 })39 .then(function() {40 serveProject();41 })42 .then(function(){43 watchForChanges(); // watch44 });;45}46// =========================================================================================================================47// Clean Out the Build folder:48// delete all our previous build files, they're yesterday's news. Its time to build again!49// =======50var clean = function() {51 var cleanPaths = [];52 // loop through to extract all files we need to clean53 for (var i in build_order) {54 var name = build_order[i]; // get the name of this thing, eg "Stylesheets"55 var move = build[name]['move'];56 var tasks = build[name].tasks;57 if(move && move.clean !== false){ // do nothing if "clean" is set to false58 if(move.clean === undefined || move.clean === null) {59 if(move.to) { cleanPaths = cleanPaths.concat(move.to); }60 } else {61 cleanPaths = cleanPaths.concat(move.clean);62 }63 }64 if(tasks) {65 for (i in tasks) {66 var task = config[tasks[i]];67 if(task.clean !== false) { // do nothing if "clean" is set to false68 if(task.clean === undefined || task.clean === null) {69 if(task.dest) { cleanPaths = cleanPaths.concat(task.dest); }70 } else {71 cleanPaths = cleanPaths.concat(task.clean);72 }73 //cleanPaths = cleanPaths.concat(task.clean);74 }75 }76 }77 }78 //console.log(cleanPaths);79 return del(cleanPaths);80}81var cleanOut = clean();82// =========================================================================================================================83// "The Build"84// Loop through each step: run any necessary tasks in sequence, than move files if the build steps calls for it.85// =======86var buildProject = function() {87 //console.log('build!');88 for (var i in build_order) {89 name = build_order[i];90 tasks = build[name].tasks;91 move = build[name].move;92 if(tasks) {93 // if there are tasks, run the them in sequence, than move files as afterwards (callback)94 runSequence(tasks, function(move){95 if(move) {96 moveFiles(move.from,move.to);97 //console.log(move.to + ': ' + eval(path.extname(move.to)));98 //console.log(move.to);99 //console.log(path.extname(move.to));100 }101 });102 } else if (move) {103 moveFiles(move.from,move.to);104 //console.log(move.to + ': ' + eval(path.extname(move.to)));105 //console.log(move.to);106 }107 }108}109// =========================================================================================================================110// Move Files111// the ability to move files is a core part of the workflow's build step. Here are the functions to move the files and watch112// for changes.113// =======114// move them inititally115var moveFiles = function(from,to) {116 fileExt = path.extname(to);117 if(fileExt === "") {118 //console.log('directory');119 dirName = to;120 } else {121 // console.log('file');122 shouldConcat = true;123 dirName = path.dirname(to);124 fileName = path.basename(to);125 }126 if (isGlob(from)) {127 // console.log(from + 'is a glob');128 return gulp.src(from)129 //.pipe(concat('combined.js'))130 .pipe(gulpif(shouldConcat, concat(fileName)))131 .pipe(gulp.dest(dirName));132 //.pipe(gulpif(shouldConcat, concat('combined.js')));133 } else {134 copy(from, to, function (err) {135 if (err) {136 console.log(from);137 console.log(to);138 return console.error(err);139 }140 //console.log('Completed moving ' + from);141 });142 }143}144// watch for changes to move them145var moveFilesWatch = function(src,dest) {146 for (var i in build_order) {147 watchThis = null;148 name = build_order[i];149 move = build[name].move;150 watch = build[name].watch;151 // make sure the "move" property is actually set152 if(move !== undefined) {153 // Set the watch files.154 // if Watch is false than don't watch, skip it155 // if watch is not set or null that we use the "move: to;""156 if(move.watch !== false) {157 if(move.watch === null || move.watch === undefined) {158 if(move.from) { watchThis = move.from; }159 } else {160 watchThis = move.watch;161 }162 }163 // Determine if the watched file should be concat or just simply moved164 // this is tested later based on "shouldConcat"165 fileExt = path.extname(move.to);166 if(fileExt === "") {167 shouldConcat = false;168 dirName = move.to;169 fileName = undefined;170 } else {171 shouldConcat = true;172 dirName = path.dirname(move.to);173 fileName = path.basename(move.to);174 }175 if(watchThis) {176 // go through and set the actual watch src string so it matches our glob requirements:177 // it needs to be a glob - eg /** or /*.js178 if(typeof(watchThis) === 'object') {179 for (ii in watchThis) {180 if(isGlob(watchThis[ii]) === false) {181 if(watchThis[ii].slice(-1) === "/") {182 watchThis[ii] = watchThis[ii] + "**";183 } else {184 watchThis[ii] = watchThis[ii] + "/**";185 }186 }187 }188 } else if(typeof(watchThis) === 'string') {189 if(isGlob(watchThis) === false) {190 if(watchThis.slice(-1) === "/") {191 watchThis = watchThis + "**";192 } else {193 watchThis = watchThis + "/**";194 }195 }196 }197 // run watch task for each198 (function(watchThis,shouldConcat,dirName,fileName, name) {199 gulpWatch(watchThis, function() {200 //console.log('Should Concat? ' + shouldConcat);201 //console.log('filename: ' + fileName);202 //console.log(watchThis + " to: " + dirName);203 return gulp.src(watchThis)204 .pipe(gulpif(shouldConcat === false, changed(dirName)))205 .pipe(gulpif(shouldConcat, concat(fileName)))206 .pipe(gulp.dest(dirName))207 .pipe(browserSync.reload({stream:true}))208 .pipe( notify({209 message: "Processed a move for: " + name210 }));211 });212 })(watchThis,shouldConcat,dirName,fileName, name);213 }214 }215 }216}217// =========================================================================================================================218// Watch for changes219// =======220var watchForChanges = function() {221 //console.log('hey');222 var watchConfig = Array();223 for (var i in build_order) {224 name = build_order[i];225 tasks = build[name].tasks;226 watch = build[name].watch;227 // determine which task files should be watched228 for (var ii in tasks) {229 theFiles = null; // clear out theFiles. This is an iterative working variable230 taskName = tasks[ii];231 watchFiles = config[tasks[ii]].watch;232 srcFiles = config[tasks[ii]].src;233 // make sure watching isn't explicityl disabled234 if(watchFiles !== false) {235 if(watchFiles === null || watchFiles === undefined) {236 // watching the source by default because watch is not set237 if (srcFiles) {238 theFiles = srcFiles;239 }240 } else {241 // watch is set, so lets watch those files242 theFiles = watchFiles;243 }244 }245 // if there are files to watch then we add this246 if(theFiles) {247 watchConfig.push({248 task: taskName,249 files: theFiles250 });251 }252 }253 }254 // watch for changes amongst all the enabled tasks255 watchConfig.forEach(function(watchThis) {256 //console.log('watch: ' + watchThis.files + ' and run: ' + watchThis.task);257 gulpWatch(watchThis.files, function () {258 console.log(watchThis.task + " watch event");259 require('./' + watchThis.task)()260 });261 });262 // watch for changes amongst all the moved files263 moveFilesWatch();264}265var serveProject = function() {266 runSequence('browserSync');267}268// =========================================================================================================================269// Gulp Tasks270// =======271gulp.task('build', buildChain);272gulp.task('build-clean', clean);...

Full Screen

Full Screen

CleanTask.ts

Source:CleanTask.ts Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.2// See LICENSE in the project root for license information.3import { GulpTask } from './GulpTask';4import * as Gulp from 'gulp';5import { FileDeletionUtility } from '../utilities/FileDeletionUtility';6import { IBuildConfig } from './../IBuildConfig';7/**8 * The clean task is a special task which iterates through all registered9 * tasks and subtasks, collecting a list of patterns which should be deleted.10 * An instance of this task is automatically registered to the 'clean' command.11 * @public12 */13export class CleanTask extends GulpTask<void> {14 /**15 * Instantiates a new CleanTask with the name 'clean'16 */17 public constructor() {18 super('clean');19 }20 /**21 * The main function, which iterates through all uniqueTasks registered22 * to the build, and by calling the getCleanMatch() function, collects a list of23 * glob patterns which are then passed to the `del` plugin to delete them from disk.24 */25 public executeTask(gulp: typeof Gulp, completeCallback: (error?: string | Error) => void): void {26 const { distFolder, libFolder, libAMDFolder, tempFolder }: IBuildConfig = this.buildConfig;27 let cleanPaths: string[] = [distFolder, libFolder, tempFolder];28 if (libAMDFolder) {29 cleanPaths.push(libAMDFolder);30 }31 // Give each registered task an opportunity to add their own clean paths.32 for (const executable of this.buildConfig.uniqueTasks || []) {33 if (executable.getCleanMatch) {34 // Set the build config, as tasks need this to build up paths35 cleanPaths = cleanPaths.concat(executable.getCleanMatch(this.buildConfig));36 }37 }38 const uniquePaths: { [key: string]: string } = {};39 // Create dictionary of unique paths. (Could be replaced with ES6 set.)40 cleanPaths.forEach((cleanPath) => {41 if (cleanPath) {42 uniquePaths[cleanPath] = cleanPath;43 }44 });45 // Reset cleanPaths to only unique non-empty paths.46 cleanPaths = [];47 for (const uniquePath in uniquePaths) {48 if (uniquePaths.hasOwnProperty(uniquePath)) {49 cleanPaths.push(uniquePath);50 }51 }52 try {53 FileDeletionUtility.deletePatterns(cleanPaths);54 completeCallback();55 } catch (e) {56 completeCallback(e);57 }58 }...

Full Screen

Full Screen

clean.js

Source:clean.js Github

copy

Full Screen

1const del = require('del');2const cleanTask = (destinations = [], copy = {}) => {3 const cleanPaths = destinations.slice();4 copy.paths.map(item => {5 if (item.dest !== 'public' && cleanPaths.indexOf(item.dest) === -1) {6 cleanPaths.push(item.dest);7 }8 });9 return del(cleanPaths);10};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react';2import { cleanPaths } from 'storybook-root-decorator';3addDecorator(cleanPaths);4import { addDecorator } from '@storybook/react';5import { cleanPaths } from 'storybook-root-decorator';6import { withInfo } from '@storybook/addon-info';7addDecorator(cleanPaths);8addDecorator(withInfo);9import { addDecorator } from '@storybook/react';10import { cleanPaths } from 'storybook-root-decorator';11import { withInfo } from '@storybook/addon-info';12addDecorator(cleanPaths);13addDecorator(withInfo);14import { addDecorator } from '@storybook/react';15import { cleanPaths } from 'storybook-root-decorator';16import { withInfo } from '@storybook/addon-info';17addDecorator(cleanPaths);18addDecorator(withInfo);19import { addDecorator } from '@storybook/react';20import { cleanPaths } from 'storybook-root-decorator';21import { withInfo } from '@storybook/addon-info';22addDecorator(cleanPaths);23addDecorator(withInfo);24import { addDecorator } from '@storybook/react';25import { cleanPaths } from 'storybook-root-decorator';26import { withInfo } from '@storybook/addon-info';27addDecorator(cleanPaths);28addDecorator(withInfo);29import { addDecorator } from '@storybook/react';30import { cleanPaths } from 'storybook-root-decorator';31import { withInfo } from '@storybook/addon-info';32addDecorator(cleanPaths);33addDecorator(withInfo);34import { addDecorator } from '@storybook/react';35import { cleanPaths } from 'storybook-root-decorator';36import { withInfo } from '@storybook/addon-info';37addDecorator(cleanPaths);38addDecorator(withInfo);39import { addDecorator } from '@storybook/react';40import { cleanPaths } from 'storybook-root-decorator';41import { withInfo } from '@storybook/addon-info';42addDecorator(cleanPaths);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { cleanPaths } from 'storybook-root-decorator';2import { addDecorator } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4addDecorator(cleanPaths);5addDecorator(withInfo);6addParameters({7 info: {8 },9});10addDecorator(withGlobalStyles);11addDecorator(withStorybookStyles);12addDecorator(withStorybookLayout);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { cleanPaths } from 'storybook-root-decorator';2const paths = ['/', '/about', '/blog', '/contact'];3const cleanedPaths = cleanPaths(paths);4console.log(cleanedPaths);5import { cleanPaths } from 'storybook-root-decorator';6const paths = ['/', '/about', '/blog', '/contact'];7const cleanedPaths = cleanPaths(paths);8console.log(cleanedPaths);9import { cleanPaths } from 'storybook-root-decorator';10const paths = ['/', '/about', '/blog', '/contact'];11const cleanedPaths = cleanPaths(paths);12console.log(cleanedPaths);13import { cleanPaths } from 'storybook-root-decorator';14const paths = ['/', '/about', '/blog', '/contact'];15const cleanedPaths = cleanPaths(paths);16console.log(cleanedPaths);17import { cleanPaths } from 'storybook-root-decorator';18const paths = ['/', '/about', '/blog', '/contact'];19const cleanedPaths = cleanPaths(paths);20console.log(cleanedPaths);21import { cleanPaths } from 'storybook-root-decorator';22const paths = ['/', '/about', '/blog', '/contact'];23const cleanedPaths = cleanPaths(paths);24console.log(cleanedPaths);25import { cleanPaths } from 'storybook-root-decorator';26const paths = ['/', '/about', '/blog', '/contact'];27const cleanedPaths = cleanPaths(paths);28console.log(cleanedPaths);29import { cleanPaths } from 'storybook-root-decorator';30const paths = ['/', '/about', '/blog', '/contact'];31const cleanedPaths = cleanPaths(paths

Full Screen

Using AI Code Generation

copy

Full Screen

1import { cleanPaths } from "storybook-root-alias";2import { configure } from "@storybook/react";3cleanPaths();4const req = require.context("../src", true, /\.stories\.js$/);5function loadStories() {6 req.keys().forEach(filename => req(filename));7}8configure(loadStories, module);9const path = require("path");10const rootPath = path.resolve(__dirname, "../");11module.exports = ({ config }) => {12 config.resolve.modules.push(rootPath);13 return config;14};15Now, you can import your components by their absolute path:16import { Button } from "components/Button";

Full Screen

Using AI Code Generation

copy

Full Screen

1import { cleanPaths } from 'storybook-root-decorator';2const paths = [__dirname, 'src'];3cleanPaths(paths);4import { storybookRootDecorator } from 'storybook-root-decorator';5storiesOf('Welcome', module).addDecorator(storybookRootDecorator).add('to Storybook', () => (6 <Welcome showApp={linkTo('Button')} />7));8import { storybookRootDecorator } from 'storybook-root-decorator';9storiesOf('Button', module).addDecorator(storybookRootDecorator).add('with text', () => (10 <Button onClick={action('clicked')}>Hello Button</Button>11));12import { storybookRootDecorator } from 'storybook-root-decorator';13storiesOf('Button', module).addDecorator(storybookRootDecorator).add('with some emoji', () => (14 <Button onClick={action('clicked')}>15));16import { storybookRootDecorator } from 'storybook-root-decorator';17storiesOf('Welcome', module).addDecorator(storybookRootDecorator).add('to Storybook', () => (18 <Welcome showApp={linkTo('Button')} />19));20import { storybookRootDecorator } from 'storybook-root-decorator';

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 storybook-root 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