Ejemplo n.º 1
0
      .then(function () {
        const cwd = process.cwd();
        expect(cwd).to.not.match(/foo/, 'does not use app name for directory name');
        expect(!fs.pathExistsSync(path.join(cwd, 'foo')), 'does not create new directory with app name');

        expect(cwd).to.match(/bar/, 'uses given directory name');
        expect(fs.pathExistsSync(path.join(cwd, 'bar')), 'creates new directory with specified name');

        const pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
        expect(pkgJson.name).to.equal('foo', 'uses app name for package name');
      });
Ejemplo n.º 2
0
      .then(() => {
        const cwd = process.cwd();
        expect(cwd).not.toMatch(/foo/, 'does not use app name for directory name');
        expect(fs.pathExistsSync(path.join(cwd, 'foo'))).toBe(false, 'does not create new directory with app name');

        expect(cwd).toMatch(/bar/, 'uses given directory name');
        expect(fs.pathExistsSync(path.join(cwd, '..', 'bar'))).toBe(true, 'creates new directory with specified name');

        const pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
        expect(pkgJson.name).toBe('foo', 'uses app name for package name');
      })
Ejemplo n.º 3
0
      return Object.keys(this.definition!.subscriptions!).map(name => {
        const subscription = this.definition!.subscriptions![name]

        const url =
          typeof subscription.webhook === 'string'
            ? subscription.webhook
            : subscription.webhook.url
        const headers =
          typeof subscription.webhook === 'string'
            ? []
            : transformHeaders(subscription.webhook.headers)

        let query = subscription.query
        if (subscription.query.endsWith('.graphql')) {
          const queryPath = path.join(this.definitionDir, subscription.query)
          if (!fs.pathExistsSync(queryPath)) {
            throw new Error(
              `Subscription query ${queryPath} provided in subscription "${name}" in prisma.yml does not exist.`,
            )
          }
          query = fs.readFileSync(queryPath, 'utf-8')
        }

        return {
          name,
          query,
          headers,
          url,
        }
      })
 .then(() => {
   const testPath =
     path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts');
   expect(pathExistsSync(testPath)).toBe(true);
   const contents = readFileSync(testPath, 'utf8');
   expect(contents.indexOf('selector: \'test-mycomp\'') === -1).toBe(false);
 })
Ejemplo n.º 5
0
 plugins = plugins.concat((cli.plugins || []).map(name => {
   let pluginPath = path.join(this.config.root, 'node_modules', name)
   if (!fs.pathExistsSync(pluginPath)) {
     pluginPath = path.join(this.config.root, '../../', 'node_modules', name)
   }
   return new PluginPath({output: this.out, type: 'core', path: pluginPath})
 }))
Ejemplo n.º 6
0
export async function readDefinition(
  filePath: string,
  args: Args,
  out: IOutput = new Output(),
  envVars?: any,
): Promise<{ definition: PrismaDefinition; rawJson: any }> {
  if (!fs.pathExistsSync(filePath)) {
    throw new Error(`${filePath} could not be found.`)
  }
  const file = fs.readFileSync(filePath, 'utf-8')
  const json = yaml.safeLoad(file) as PrismaDefinition
  // we need this copy because populateJson runs inplace
  const jsonCopy = { ...json }

  const vars = new Variables(filePath, args, out, envVars)
  const populatedJson = await vars.populateJson(json)
  if (populatedJson.custom) {
    delete populatedJson.custom
  }
  const valid = validate(populatedJson)
  // TODO activate as soon as the backend sends valid yaml
  if (!valid) {
    debugger
    let errorMessage =
      `Invalid prisma.yml file` + '\n' + printErrors(validate.errors!)
    throw new Error(errorMessage)
  }

  cache[file] = populatedJson
  return {
    definition: populatedJson,
    rawJson: jsonCopy,
  }
}
Ejemplo n.º 7
0
  async seed(
    serviceName: string,
    stageName: string,
    reset: boolean = false,
    workspaceSlug?: string,
  ) {
    const seed = this.definition.definition!.seed
    if (!seed) {
      throw new Error(
        `In order to seed, you need to provide a "seed" property in your prisma.yml`,
      )
    }
    if (seed.import && seed.run) {
      throw new Error(
        `Please provider either seed.import or seed.run but not both at the same time`,
      )
    }

    if (seed.import) {
      const source = path.join(this.config.definitionDir, seed.import)

      debug(source)

      if (!source.endsWith('.zip') && !source.endsWith('.graphql')) {
        throw new Error(`Source must end with .zip or .graphql`)
      }

      if (!fs.pathExistsSync(source)) {
        throw new Error(`Path ${source} does not exist`)
      }

      const token = this.definition.getToken(serviceName, stageName)

      if (reset) {
        await this.reset(serviceName, stageName)
      }

      if (source.endsWith('.zip')) {
        await this.import(source, serviceName, stageName, token, workspaceSlug)
      } else if (source.endsWith('.graphql')) {
        await this.executeQuery(
          source,
          serviceName,
          stageName,
          token,
          workspaceSlug,
        )
      }
    }

    if (seed.run) {
      if (reset) {
        await this.reset(serviceName, stageName)
      }

      await this.run(seed.run)
    }
  }
Ejemplo n.º 8
0
      .then(() => {
        expect(fs.pathExistsSync(path.join(testPath, '+my-route/my-route.component.ts')))
          .to.equal(true);
        expect(fs.pathExistsSync(path.join(testPath, '+my-route/+my-other/my-other.component.ts')))
          .to.equal(true);
        expect(fs.pathExistsSync(path.join(testPath, '+my-route/+my-other/+my-third/my-third.component.ts')))
          .to.equal(true);

        const appContent = fs.readFileSync(path.join(testPath, 'foo.component.ts'), 'utf-8');
        const myRouteContent = fs.readFileSync(path.join(testPath, '+my-route/my-route.component.ts'), 'utf-8');
        const myOtherRouteContent = fs.readFileSync(path.join(testPath, '+my-route/+my-other/my-other.component.ts'), 'utf-8');
        const myThirdRouteContent = fs.readFileSync(path.join(testPath, '+my-route/+my-other/+my-third/my-third.component.ts'), 'utf-8');

        expect(appContent).to.match(/@Routes\(\[[\s\S]+\/\+my-route\/\.\.\.[\s\S]+\]\)/m);
        expect(myRouteContent).to.match(/@Routes\(\[[\s\S]+\/my-other\/\.\.\.[\s\S]+\]\)/m);
        expect(myOtherRouteContent).to.match(/@Routes\(\[[\s\S]+\/my-third[^\.][\s\S]+\]\)/m);
        expect(myThirdRouteContent).to.not.include('@Routes');
      });
        return ng(['generate', 'module', 'm', '--app', 'other']).then(() => {
          const expectedModule = path.join(appRoot, 'other', 'src', 'm', 'm.module.ts');
          expect(pathExistsSync(expectedModule)).toBe(true);

          return ng(['generate', 'component', 'm/c', '--app', 'other', '--module', 'm']).then(() => {
            expect(pathExistsSync(path.join(appRoot, 'other', 'src', 'm', 'c', 'c.component.ts'))).toBe(true);
            expect(readFileSync(expectedModule, 'utf-8')).toContain(`import { CComponent } from './c/c.component'`);
          });
        }).then(done, done.fail);
Ejemplo n.º 10
0
export function teardown(path: string) {
  process.chdir(root);

  if (fs.pathExistsSync(path)) {
    return fs.remove(path);
  } else {
    return Promise.resolve();
  }
};