Skip to content

Commit

Permalink
fix: fix script order
Browse files Browse the repository at this point in the history
  • Loading branch information
linbudu599 committed Mar 16, 2022
1 parent fa2fcb7 commit 256b757
Show file tree
Hide file tree
Showing 309 changed files with 40 additions and 28,744 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

tmp

# Runtime data
pids
*.pid
Expand Down
27 changes: 15 additions & 12 deletions scripts/cache-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,34 @@ export default function useCachePackage(cli: CAC) {
.command('cache', 'cache current workspace packages to cache directory')
.option('-p,--preserve', 'preserve when package cache directory exists')
.option('--no-preserve', 'override exist package cache')
.action(async (options: { preserve: boolean }) => {
.action(async ({ preserve = true }: { preserve: boolean }) => {
fs.ensureDirSync(CLIUtils.resolvedPackageRootDir);
const existPackages = CLIUtils.existPackages;

for (const p of existPackages) {
const projectSrcPath = CLIUtils.resolvePackageDir(p);
const projectDestPath = CLIUtils.resolveCachePackageDir(p);

if (fs.existsSync(projectDestPath) && options.preserve) {
if (fs.existsSync(projectDestPath) && preserve) {
consola.info(
`[Skip]Cached package ${chalk.green(p)} will be preserved.`
`[Skip] Cached package ${chalk.green(p)} will be preserved.`
);
continue;
}

fs.copySync(projectSrcPath, projectDestPath, {
recursive: true,
filter: (src, dest) => {
const filtered = ['node_modules', 'dist', 'tmp'].every(
(pattern) => !src.includes(pattern)
);
CLIUtils.copySyncWithFilter(projectSrcPath, projectDestPath);

return filtered;
},
});
const projectFixtureCachePath =
CLIUtils.resolveFixtureCachePackageDir(p);

CLIUtils.copySyncWithFilter(
projectSrcPath,
projectFixtureCachePath,
undefined,
{
overwrite: true,
}
);

consola.success(`Package ${chalk.green(p)} cached.`);
}
Expand Down
28 changes: 23 additions & 5 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import consola from 'consola';
import fs, { Mode } from 'fs-extra';
import fs, { CopyOptionsSync, Mode } from 'fs-extra';
import { EOL } from 'os';
import path from 'path';
import execa from 'execa';
Expand Down Expand Up @@ -34,6 +34,10 @@ export class Constants {
return path.resolve(Constants.cacheDir, 'packages');
}

public static get fixedPackagesCacheDir() {
return path.resolve(Constants.cacheDir, 'fixture-packages');
}

public static get internalRegistry() {
return 'https://registry.npmmirror.com';
}
Expand Down Expand Up @@ -80,10 +84,6 @@ export class Constants {
}
}

type Tmp<Name> = {
Name: string[];
};

export class CLIUtils {
public static get existPackages() {
return fs.readdirSync(
Expand Down Expand Up @@ -113,6 +113,10 @@ export class CLIUtils {
return path.resolve(__dirname, '../', Constants.packagesCacheDir, p);
}

public static resolveFixtureCachePackageDir(p: string) {
return path.resolve(__dirname, '../', Constants.fixedPackagesCacheDir, p);
}

public static existWorkspacePackageFilter(projects: string[], blur = false) {
const existPackages = CLIUtils.existPackages;

Expand All @@ -127,6 +131,20 @@ export class CLIUtils {
: matched;
}

public static copySyncWithFilter(
src: string,
dest: string,
pathFragmentsFilter: string[] = ['node_modules', 'dist', 'tmp'],
copyOptions: CopyOptionsSync = {}
) {
fs.copySync(src, dest, {
filter: (src, dest) =>
pathFragmentsFilter.every((pattern) => !src.includes(pattern)),
recursive: true,
...copyOptions,
});
}

public static findInfoFromKeywords(input: string) {
const inputFragment = input.split('-');
for (const info of Object.values(Constants.starterInfoMap)) {
Expand Down
17 changes: 0 additions & 17 deletions tmp/.LinbuduLab/packages/astro-docs-starter/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/.LinbuduLab/packages/astro-docs-starter/.npmrc

This file was deleted.

6 changes: 0 additions & 6 deletions tmp/.LinbuduLab/packages/astro-docs-starter/.stackblitzrc

This file was deleted.

169 changes: 0 additions & 169 deletions tmp/.LinbuduLab/packages/astro-docs-starter/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions tmp/.LinbuduLab/packages/astro-docs-starter/astro.config.mjs

This file was deleted.

24 changes: 0 additions & 24 deletions tmp/.LinbuduLab/packages/astro-docs-starter/package.json

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

11 changes: 0 additions & 11 deletions tmp/.LinbuduLab/packages/astro-docs-starter/sandbox.config.json

This file was deleted.

Loading

0 comments on commit 256b757

Please sign in to comment.