Skip to content

Commit

Permalink
ADD faster reset script
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Jun 5, 2019
1 parent 5441456 commit 55a7bf1
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 28 deletions.
7 changes: 5 additions & 2 deletions addons/storyshots/storyshots-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
"@storybook/router": "5.1.0-rc.5",
"core-js": "^3.0.1",
"jest-image-snapshot": "^2.8.2",
"puppeteer": "^1.12.2",
"regenerator-runtime": "^0.12.1"
},
"optionalDependencies": {
"puppeteer": "^1.12.2"
},
"peerDependencies": {
"@storybook/addon-storyshots": "5.1.0-rc.0"
"@storybook/addon-storyshots": "5.1.0-rc.0",
"puppeteer": "^1.12.2"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
"sort-package-json": "^1.21.0",
"svelte": "^3.4.1",
"svelte-jest": "^0.2.0",
"trash": "^6.0.0",
"ts-jest": "^24.0.2",
"typescript": "^3.4.1",
"weak": "^1.0.1"
Expand Down
89 changes: 69 additions & 20 deletions scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,24 @@ const spawn = (command, options = {}) => {
};

const main = program
.version('3.0.0')
.version('5.0.0')
.option('--all', `Bootstrap everything ${chalk.gray('(all)')}`);

const createTask = ({ defaultValue, option, name, check = () => true, command, pre = [] }) => ({
const createTask = ({
defaultValue,
option,
name,
check = () => true,
command,
pre = [],
order,
}) => ({
value: false,
defaultValue: defaultValue || false,
option: option || undefined,
name: name || 'unnamed task',
check: check || (() => true),
order,
command: () => {
// run all pre tasks
pre
Expand All @@ -63,29 +72,44 @@ const createTask = ({ defaultValue, option, name, check = () => true, command, p
});

const tasks = {
core: createTask({
name: `Core, Dll & Examples ${chalk.gray('(core)')}`,
defaultValue: true,
option: '--core',
command: () => {
log.info(prefix, 'yarn workspace');
},
pre: ['install', 'build', 'dll'],
order: 1,
}),
reset: createTask({
name: `Clean and re-install dependencies ${chalk.red('(reset)')}`,
defaultValue: false,
option: '--reset',
command: () => {
log.info(prefix, 'git clean');
spawn('git clean -fdx --exclude=".vscode" --exclude=".idea"');
log.info(prefix, 'yarn install');
spawn('yarn install');
},
order: 0,
}),
core: createTask({
name: `Core, Dll & Examples ${chalk.gray('(core)')}`,
defaultValue: true,
option: '--core',
install: createTask({
name: `install dependencies ${chalk.gray('(install)')}`,
defaultValue: false,
option: '--install',
command: () => {
spawn('yarn install --ignore-optional --no-scripts');
},
order: 1,
}),
build: createTask({
name: `Core, Dll & Examples ${chalk.gray('(build)')}`,
defaultValue: false,
option: '--build',
command: () => {
log.info(prefix, 'yarn workspace');
spawn('yarn install');
log.info(prefix, 'prepare');
spawn('lerna run prepare');
log.info(prefix, 'dll');
spawn('lerna run createDlls --scope "@storybook/ui"');
},
order: 2,
}),
dll: createTask({
name: `Generate DLL ${chalk.gray('(dll)')}`,
Expand All @@ -95,6 +119,7 @@ const tasks = {
log.info(prefix, 'dll');
spawn('lerna run createDlls --scope "@storybook/ui"');
},
order: 3,
}),
docs: createTask({
name: `Documentation ${chalk.gray('(docs)')}`,
Expand All @@ -103,6 +128,7 @@ const tasks = {
command: () => {
spawn('yarn bootstrap:docs');
},
order: 6,
}),
packs: createTask({
name: `Build tarballs of packages ${chalk.gray('(build-packs)')}`,
Expand All @@ -112,6 +138,7 @@ const tasks = {
spawn('yarn build-packs');
},
check: () => getDirectories(join(__dirname, '..', 'packs')).length > 0,
order: 5,
}),
registry: createTask({
name: `Run local registry ${chalk.gray('(reg)')}`,
Expand All @@ -120,9 +147,16 @@ const tasks = {
command: () => {
spawn('./scripts/run-registry.js');
},
order: 11,
}),
};

const groups = {
main: ['core', 'docs'],
subtasks: ['install', 'build', 'dll', 'packs'],
devtasks: ['registry', 'reset'],
};

Object.keys(tasks)
.reduce((acc, key) => acc.option(tasks[key].option, tasks[key].name), main)
.parse(process.argv);
Expand All @@ -131,6 +165,21 @@ Object.keys(tasks).forEach(key => {
tasks[key].value = program[tasks[key].option.replace('--', '')] || program.all;
});

const createSeperator = input => `- ${input}${' ---------'.substr(0, 12)}`;

const choices = Object.values(groups)
.map(l =>
l.map(key => ({
name: tasks[key].name,
checked: tasks[key].defaultValue,
}))
)
.reduce(
(acc, i, k) =>
acc.concat(new inquirer.Separator(createSeperator(Object.keys(groups)[k]))).concat(i),
[]
);

let selection;
if (
!Object.keys(tasks)
Expand All @@ -141,12 +190,10 @@ if (
.prompt([
{
type: 'checkbox',
message: 'Select which packages to bootstrap',
message: 'Select the bootstrap activities',
name: 'todo',
choices: Object.keys(tasks).map(key => ({
name: tasks[key].name,
checked: tasks[key].defaultValue,
})),
pageSize: Object.keys(tasks).length + Object.keys(groups).length,
choices,
},
])
.then(({ todo }) =>
Expand Down Expand Up @@ -186,9 +233,11 @@ selection
if (list.length === 0) {
log.warn(prefix, 'Nothing to bootstrap');
} else {
list.forEach(key => {
key.command();
});
list
.sort((a, b) => a.order - b.order)
.forEach(key => {
key.command();
});
process.stdout.write('\x07');
}
})
Expand Down
41 changes: 41 additions & 0 deletions scripts/reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from 'fs';
import { spawn, exec } from 'child_process';
import trash from 'trash';

fs.writeFileSync('reset.log', '');

// let results = [];
const cleaningProcess = spawn('git', [
'clean',
'-xdf',
'-n',
'--exclude=".vscode"',
'--exclude=".idea"',

This comment has been minimized.

Copy link
@Hypnosphi

Hypnosphi Oct 13, 2019

Member

Looks like this argument doesn't get applied for some reason. I just ran yarn bootstrap --reset and lost my IDEA project =(

This comment has been minimized.

Copy link
@Hypnosphi

Hypnosphi Oct 13, 2019

Member

UPD: OK, it wasn't deleted, only moved to trash. But why is it needed?

This comment has been minimized.

Copy link
@ndelangen

ndelangen Oct 14, 2019

Author Member

It's a bug, it should not delete nor trash these files.

]);

cleaningProcess.stdout.on('data', data => {
if (data && data.toString()) {
const l = data
.toString()
.split(/\n/)
.forEach(i => {
const [, uri] = i.match(/Would remove (.*)$/) || [];

if (uri) {
trash(uri);
}
});
}
fs.appendFile('reset.log', data, err => {
if (err) {
throw err;
}
});
});
cleaningProcess.on('exit', code => {
if (code === 0) {
console.log('all went well, files are being trashed now');
} else {
console.error(code);
}
});
Loading

0 comments on commit 55a7bf1

Please sign in to comment.