component2duo
convert your component project into a duo project
Last updated 3 years ago by timaschew .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install component2duo 
SYNC missed versions from official npm registry.

compoonent2duo

convert your component app into duo app

Duo doesn't have any concept of local components. This tool rewrites your require paths for local components by analyzing your root component and all your locals and scripts which are listed in your component.json files.

Limitation / not implemented yet

  • root component should have only one element in the paths array
  • lookup paths of local components will be ignore, only the root component paths is used
  • only files which are listed in the .scripts property of your component.json files are analyzed

install

npm install component2duo

usage

var Converter = require('component2duo');
var c = new Converter('rootComponentPath', Converter.ABSOLUTE, {simulate:true});
var result = c.start();
console.log(result);

API

Converter(path, mode, opt)

  • path to the root component.json
  • mode Converter.ABSOLUTE or Converter.RELATIVE
  • opt options object
    • simulate - boolean, if true: don't rewrite changes to filesystem, return the changes as result of start(), default false
    • debug - boolean, if true: print each require path transformation to stdout
    • localManifest filename of the local components manifest, default component.json

Mode

Converter.ABSOLUTE will rewrite require paths relative to the root component with a leading slash, for instance: /lib/local.

Converter.RELATIVE will rewrite require paths relative to each local component, for instance: ../local.

CLI

node_modules/.bin/component2duo ~/myApp/component.json 0 true
  • first argument: path to root component
  • second argument: mode; 0 = ABSOLUTE, 1 = RELATIVE
  • third argument (optional): simulate and print require transformation to stdout

example

Assume you have this directory structure

myApp
├── component.json
└── lib
    ├── bar
    │   ├── component.json
    │   ├── index.js
    │   └── qux.js
    └── foo
        ├── component.json
        ├── index.js
        ├── script.js
        └── sub
            └── baz.js

Your root component is located at myApp/component.json with this content:

{
    "name": "myApp",
    "paths": ["lib"],
    "locals": ["foo"]
}

myApp/foo/component.json:

{
    "locals": ["bar"],
    "scripts": [
        "index.js",
        "script.js",
        "sub/baz.js"
    ],
    "main": "index.js"
}

With component you can write require('bar') in the scripts of foo. With this tool you can choose if you want to rewrite it into an absolute require('/lib/bar') or relative require('../bar') path.

example CLI output

If you checkout this project (and make a npm install) you can run:

$ ./bin/cli test/fixtures/simple/component.json 0 true

then you get this result:

lib/foo/script.js: 'bar' -> '/lib/bar'
lib/foo/script.js: 'bar/qux' -> '/lib/bar/qux'

Development

git clone https://github.com/timaschew/component2duo.git
cd component2duo
npm install
npm test

Currently I'm not using any generator functions, but I will, so currently just ignore the build-generator directory. If you don't want use CoffeeScript you can use the build/index.js.

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |