Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
};
});
}
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;
}
}
}
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()));
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.`);
}
}
Object.keys(devDeps).forEach(dep => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const depPackageJson = readPackageJson(path.join(rootPath, 'node_modules', dep))!;
if (dep.includes('just-stack') || (depPackageJson && depPackageJson.keywords && depPackageJson.keywords.includes('just-stack'))) {
stackDeps[dep] = devDeps[dep];
}
});
export function getAvailableStacks(rootPath: string) {
const packageJson = readPackageJson(rootPath);
if (!packageJson) {
throw new Error(`not able to read package.json from ${rootPath}`);
}
const stackDeps: { [key: string]: string } = {};
const devDeps = packageJson.devDependencies || {};
Object.keys(devDeps).forEach(dep => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const depPackageJson = readPackageJson(path.join(rootPath, 'node_modules', dep))!;
if (dep.includes('just-stack') || (depPackageJson && depPackageJson.keywords && depPackageJson.keywords.includes('just-stack'))) {
stackDeps[dep] = devDeps[dep];
}
});
export async function upgradeStackPackageJsonFile(
projectPath: string,
templateInstallationPath?: string
): Promise {
const packageJson = readPackageJson(projectPath);
if (packageJson && packageJson.just && packageJson.just.stack) {
const stack = packageJson.just.stack;
let stackPath: string | null = null;
if (!templateInstallationPath) {
stackPath = await downloadPackage(stack);
} else {
stackPath = path.join(templateInstallationPath, stack, 'template');
}
if (stackPath) {
upgradePackageDeps(stackPath, projectPath, packageJson);
} else {
logger.error(`Cannot read or retrieve the stack package.json for ${stack}`);
}