-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26764 from storybookjs/shilman/portable-stories-s…
…tats Telemetry: Add portable stories
- Loading branch information
Showing
8 changed files
with
730 additions
and
317 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
code/core/src/telemetry/get-portable-stories-usage.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { getPortableStoriesFileCountUncached } from './get-portable-stories-usage'; | ||
|
||
describe('getPortableStoriesFileCountUncached', () => { | ||
it('should ignores node_modules, non-source files', async () => { | ||
const usage = await getPortableStoriesFileCountUncached(); | ||
// you can verify with: `git grep -m1 -c composeStor | wc -l` | ||
expect(usage).toMatchInlineSnapshot(`14`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { execaCommand } from 'execa'; | ||
|
||
import { createFileSystemCache, resolvePathInStorybookCache } from '../common'; | ||
|
||
const cache = createFileSystemCache({ | ||
basePath: resolvePathInStorybookCache('portable-stories'), | ||
ns: 'storybook', | ||
ttl: 24 * 60 * 60 * 1000, // 24h | ||
}); | ||
|
||
export const getPortableStoriesFileCountUncached = async () => { | ||
const { stdout } = await execaCommand(`git grep -m1 -c composeStor`, { | ||
cwd: process.cwd(), | ||
shell: true, | ||
}); | ||
return stdout.split('\n').filter(Boolean).length; | ||
}; | ||
|
||
const CACHE_KEY = 'portableStories'; | ||
export const getPortableStoriesFileCount = async () => { | ||
let cached = await cache.get(CACHE_KEY); | ||
if (!cached) { | ||
try { | ||
const count = await getPortableStoriesFileCountUncached(); | ||
cached = { count }; | ||
await cache.set(CACHE_KEY, cached); | ||
} catch (err: any) { | ||
// exit code 1 if no matches are found | ||
const count = err.exitCode === 1 ? 0 : null; | ||
cached = { count }; | ||
} | ||
} | ||
return cached.count; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...derers/react/template/stories/docgen-components/8428-js-static-prop-types/docgen.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rs/react/template/stories/docgen-components/9556-ts-react-default-exports/docgen.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.