Skip to content

Commit

Permalink
feat(ngm): added --here option to link submodules to root project
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Dec 15, 2016
1 parent dd67956 commit 6a0735a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 153 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
@@ -0,0 +1,11 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
108 changes: 0 additions & 108 deletions src/ngm/bin/ngm-cli.todo.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/ngm/bin/ngm-cli.ts
Expand Up @@ -45,7 +45,8 @@ const cli = meow(`
-p DIRECTORY, Compile the project in the given directory
--project DIRECTORY
Optional options:
--no-deep By default local submodules will be linked to each other
--no-deep By default local submodules will be linked to each other
--here Links submodules to root package
----------------------------------------------------------------
publish - runs 'npm publish' in each dist submodule folders, how it works:
Expand Down Expand Up @@ -119,4 +120,4 @@ Promise
console.error(`\n` && err.stderr || '');
console.error(`\n`, err);
process.exit(1);
});
});
68 changes: 39 additions & 29 deletions src/npm-submodules/commands/link.command.ts
@@ -1,12 +1,11 @@
const Listr = require('listr');
import { findSubmodules } from '../utils';
import { npmLink } from '../tasks';
// import { TsmOptions } from '../types';

// todo: 'npm-link` doesn't track adding new files,
// so watch mode should be added

export function npmLinkCommand({project, local, deep, verbose, yarn}) {
export function npmLinkCommand({project, local, deep, verbose, yarn, here}) {
const noDeepLinking = deep === false;
// 1. clean dist folders
// 2.1 merge pkg json
Expand All @@ -15,36 +14,47 @@ export function npmLinkCommand({project, local, deep, verbose, yarn}) {
// 3. compile ts
return findSubmodules(project, {local})
.then((opts: TsmOptions[]) => new Listr([
{
title: 'Link all submodules',
task: () => {
const linkingTasks = new Listr(
opts.map(opt => ({
title: `npm link ${opt.pkg.name} (from: ${opt.dist})`,
task: () => npmLink({yarn, cwd: opt.dist})
}))
);
{
title: 'Link all submodules',
task: () => {
const linkingTasks = new Listr(
opts.map(opt => ({
title: `npm link ${opt.pkg.name} (from: ${opt.dist})`,
task: () => npmLink({yarn, cwd: opt.dist})
}))
);

if (noDeepLinking) {
return linkingTasks;
}

opts.filter(opt => opt.cross.length > 0)
.forEach(opt => opt.cross
.forEach(crossName => linkingTasks.add(
{
title: `npm link ${crossName} to ${opt.pkg.name} (${opt.src})`,
task: () => npmLink({yarn, cwd: opt.dist, module: crossName})
}
)));
return linkingTasks;
}
if (noDeepLinking) {
return linkingTasks;
}
], {renderer: verbose ? 'verbose' : 'default'}));

opts.filter(opt => opt.cross.length > 0)
.forEach(opt => opt.cross
.forEach(crossName => linkingTasks.add(
{
title: `npm link ${crossName} to ${opt.pkg.name} (${opt.src})`,
task: () => npmLink({yarn, cwd: opt.dist, module: crossName})
}
)));
return linkingTasks;
}
},
{
title: 'Link submodules to local project',
task: () => new Listr(
opts.map(opt => ({
title: `npm link ${opt.pkg.name}`,
task: () => npmLink({yarn, module: opt.pkg.name, cwd: '.'})
}))
),
skip: () => here !== true

}
], {renderer: verbose ? 'verbose' : 'default'}));
}

export function run(cli) {
const {project, verbose, local, deep, yarn} = cli.flags;
return npmLinkCommand({project, verbose, local, deep, yarn})
.then(tasks=> tasks.run());
const {project, verbose, local, deep, yarn, here} = cli.flags;
return npmLinkCommand({project, verbose, local, deep, yarn, here})
.then(tasks => tasks.run());
}
11 changes: 1 addition & 10 deletions src/npm-submodules/commands/publish.command.ts
Expand Up @@ -41,16 +41,7 @@ export function run(cli, {buildCommand}) {
},
{
title: 'Link submodules',
task: () => npmLinkCommand({project, local: true, deep: true, verbose, yarn}),
skip: () => yolo
},
{
title: 'Link submodules to local project',
task: () => new Listr(opts.map(opt => ({
title: `npm link ${opt.pkg.name}`,
task: () => npmLink({yarn, cwd: '.', module: opt.pkg.name})
}))
),
task: () => npmLinkCommand({project, local: true, deep: true, verbose, yarn, here: true}),
skip: () => yolo
},
// publish
Expand Down
7 changes: 3 additions & 4 deletions src/tsm/bin/tsm-cli.ts
Expand Up @@ -26,10 +26,8 @@ const cli = meow(`
--no-local Use version numbers from local submodules when building package.json,
usually needed only for publish command
-w, --watch Watch input files
--verbose Enable verbose mode
--clean Cleaning dist folders
It removes folder, so you will need to rerun commands like 'link', etc...
----------------------------------------------------------------
link - runs 'npm link' in each submodule dist folder
Expand All @@ -41,7 +39,8 @@ const cli = meow(`
-p DIRECTORY, Compile the project in the given directory
--project DIRECTORY
Optional options:
--no-deep By default local submodules will be linked to each other
--no-deep By default local submodules will be linked to each other
--here Links submodules to root package
----------------------------------------------------------------
publish - runs 'npm publish' in each dist submodule folders, how it works:
Expand Down Expand Up @@ -114,4 +113,4 @@ Promise
.catch(err => {
console.error(`\n`, err.stderr || err);
process.exit(1);
});
});

0 comments on commit 6a0735a

Please sign in to comment.