How to use just-scripts-utils - 10 common examples

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
return async function addPackage() {
    const args = argv();
    const rootPath = findMonoRepoRootPath();

    const name =
      args.name ||
      (await prompts({
        type: 'text',
        name: 'name',
        message: 'What is the name of the package?'
      })).name;

    logger.info(`Creating a package called: ${name}`);

    if (!rootPath) {
      logger.warn('Cannot determine the root path to the mono repo');
      return;
    }

    // TODO: do validation that the path is indeed a monorepo

    const installedStacks = findInstalledStacks(path.join(rootPath, 'scripts'));

    // 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 }))
github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
return async function addPackage() {
    const args = argv();
    const rootPath = findMonoRepoRootPath();

    const name =
      args.name ||
      (await prompts({
        type: 'text',
        name: 'name',
        message: 'What is the name of the package?'
      })).name;

    logger.info(`Creating a package called: ${name}`);

    if (!rootPath) {
      logger.warn('Cannot determine the root path to the mono repo');
      return;
    }

    // TODO: do validation that the path is indeed a monorepo
    const installedStacks = findInstalledStacks(rootPath);

    const response = args.stack
      ? { stack: args.stack }
      : 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 }))
github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
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)) {
        logger.info('\n' + prettyPrintMarkdown(fse.readFileSync(readmeFile).toString()));
      }
    }
  };
}
github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
});

      // 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)) {
        logger.info('\n' + prettyPrintMarkdown(fse.readFileSync(readmeFile).toString()));
      }
    }
  };
}
github microsoft / just / packages / just-scripts / src / tasks / upgradeRepoTask.ts View on Github external
await rushConfig.projects.reduce(async (currentPromise, project) => {
        await currentPromise;

        if (project.projectFolder !== 'scripts') {
          const projPackageJson = readPackageJson(path.join(rootPath, project.projectFolder));

          if (projPackageJson && projPackageJson.just && projPackageJson.just.stack) {
            const diffInfo = stackDiffs[projPackageJson.just.stack];

            // no diff info means that there isn't any diffs to apply
            if (diffInfo) {
              logger.info(
                `Upgrading ${project.packageName} from ${projPackageJson.just.stack} v${diffInfo.fromVersion} to v${diffInfo.toVersion}`
              );

              applyStackDiffs(path.join(rootPath, project.projectFolder), stackDiffs[projPackageJson.just.stack]);

              didUpgradeProjects = true;
            }
          }
        }
      }, Promise.resolve());
github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
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));

      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)) {
        logger.info('\n' + prettyPrintMarkdown(fse.readFileSync(readmeFile).toString()));
      }
    }
  };
}
github microsoft / just / packages / just-scripts / src / monorepo / findInstalledStacks.ts View on Github external
return stacks.map(([stack, stackPath]) => {
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    const packageJson = readPackageJson(stackPath)!; // already checked existence above
    return {
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
      description: packageJson.description!,
      name: stack,
      version: packageJson.version,
      path: stackPath
    };
  });
}
github microsoft / just / packages / just-scripts / src / tasks / upgradeRepoTask.ts View on Github external
await rushConfig.projects.reduce(async (currentPromise, project) => {
        await currentPromise;

        if (project.projectFolder !== 'scripts') {
          const projPackageJson = readPackageJson(path.join(rootPath, project.projectFolder));

          if (projPackageJson && projPackageJson.just && projPackageJson.just.stack) {
            const diffInfo = stackDiffs[projPackageJson.just.stack];

            // no diff info means that there isn't any diffs to apply
            if (diffInfo) {
              logger.info(
                `Upgrading ${project.packageName} from ${projPackageJson.just.stack} v${diffInfo.fromVersion} to v${diffInfo.toVersion}`
              );

              applyStackDiffs(path.join(rootPath, project.projectFolder), stackDiffs[projPackageJson.just.stack]);

              didUpgradeProjects = true;
            }
          }
        }
github microsoft / just / packages / just-scripts / src / tasks / addPackageTask.ts View on Github external
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));

      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)) {
        logger.info('\n' + prettyPrintMarkdown(fse.readFileSync(readmeFile).toString()));
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 {
    logger.info(`Package ${chalk.cyan(packageJson.name)} upgrade not needed.`);
  }
}