Ejemplo n.º 1
0
            self._valid = True
            return value
        f = self._prefix.join('node_modules', self._name, 'package.json')
        if not f.exists:
            self._value = None
            self._valid = False
            return None
        with open(str(f), 'rb') as f:
            data = f.read()
        value = checksum(data)
        self._value = value
        self._valid = True
        return value


factory.register(NpmPackageNodeSignature)


def install(pkg, prefix=None, update=True):
    # TODO: support version
    # TODO: defer update of the package to 'update' task
    # but only if version was not given (otherwise, this does not make much sense)
    if prefix is None:
        prefix = ctx.builddir
    if not isinstance(prefix, str):
        prefix = str(prefix)
    Directory(prefix).mkdir('node_modules')
    cmdline_prefix = _make_prefix(prefix)
    return shell('{npm} --prefix {prefix} install {package}')\
        .use(package=pkg, prefix=cmdline_prefix)\
        .produce(package(pkg, prefix=prefix))\
Ejemplo n.º 2
0
    def run(self):
        yield copy(self.source, self.destination)

    def to_json(self):
        d = super().to_json()
        d['source'] = self.source.path
        d['destionation'] = self.destination.path
        return d

    @classmethod
    def from_json(cls, d):
        ret = cls(source=d['source'], destination=d['destionation'], restored=True)
        return ret


factory.register(DummyGenerator)


@wasp.command('generator-test')
def generator_test():
    pass


def test_generator():
    if curdir.join('test-dir').exists:
        curdir.join('test-dir').remove(recursive=True)
    testdir = curdir.mkdir('test-dir')
    with open(testdir.join('test.txt').path, 'w') as f:
        f.write('foobar')
    os.chdir(curdir.path)
    # startup