How to use the just-scripts-utils.applyTemplate function in just-scripts-utils

To help you get started, we’ve selected a few just-scripts-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
// TODO: autosuggest just-stack-* packages from npmjs.org
    let response = await prompts({
      type: 'select',
      name: 'stack',
      message: 'What type of package to add to the repo?',
      choices: installedStacks.map(stack => ({ title: stack.description, value: stack.name }))
    });

    const selectedStack = installedStacks.find(stack => stack.name === response.stack)!;

    const packagePath = path.join(rootPath, 'packages', name);
    const templatePath = path.join(selectedStack.path, 'template');

    if (templatePath) {
      applyTemplate(templatePath, packagePath, {
        name
      });

      // Remove some files that aren't relevant for an individual project within a monorepo
      fse.removeSync(path.join(packagePath, '.gitignore'));
      fse.removeSync(path.join(packagePath, '.gitattributes'));
      fse.removeSync(path.join(packagePath, '.vscode'));

      rushAddPackage(name, rootPath);
      logger.info('Running rush update');
      rushUpdate(rootPath);

      logger.info('All Set!');

      const readmeFile = path.join(packagePath, 'README.md');
      if (fse.existsSync(readmeFile)) {
github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
choices: installedStacks.map(stack => ({ title: stack.description, value: stack.name }))
      });

    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    const selectedStack = installedStacks.find(stack => stack.name === response.stack)!;

    if (!selectedStack) {
      logger.warn('Cannot add package if no stack is selected');
      return;
    }

    const packagePath = path.join(rootPath, 'packages', name);
    const templatePath = path.join(selectedStack.path, 'template');

    if (templatePath) {
      applyTemplate(templatePath, packagePath, {
        name
      });

      // Remove some files that aren't relevant for an individual project within a monorepo
      fse.removeSync(path.join(packagePath, '.gitignore'));
      fse.removeSync(path.join(packagePath, '.gitattributes'));
      fse.removeSync(path.join(packagePath, '.vscode'));

      // Remove devDep entry that is not appropriate inside individual project
      const pkgJson = readPackageJson(packagePath);

      if (pkgJson && pkgJson.devDependencies && pkgJson.just && pkgJson.just.stack) {
        delete pkgJson.devDependencies[pkgJson.just.stack];
      }

      fse.writeFileSync(path.join(packagePath, 'package.json'), JSON.stringify(pkgJson, null, 2));
github microsoft / just / packages / just-scripts / src / tasks / upgradeStackTask.ts View on Github external
function upgradePackageDeps(stackPath: string, projectPath: string, packageJson: PackageJson) {
  const templatePath = paths.tempPath(packageJson.name);
  applyTemplate(stackPath, templatePath, { name: packageJson.name });

  // Update package.json deps
  const stackPackageJson = readPackageJson(templatePath);
  if (!stackPackageJson) {
    logger.error(`Cannot find or read stack's package.json under ${stackPath}`);
    return;
  }

  const newPackageJson = mergePackageJson(packageJson, stackPackageJson);

  // If modified, the reference would be different
  logger.info(`Checking if package ${packageJson.name} should be upgraded...`);
  if (newPackageJson !== packageJson) {
    logger.info(`Package ${chalk.cyan(packageJson.name)} is being upgraded.`);
    fse.writeJsonSync(path.join(projectPath, 'package.json'), newPackageJson, { spaces: 2 });
  } else {
github microsoft / just / packages / just-stack-monorepo / template.spec.js View on Github external
beforeAll(() => {
    applyTemplate(templatePath, snapshotPath, { name: 'testproject' });
    jsonFiles = glob.sync('**/*.json', { cwd: snapshotPath });
  });