Skip to content

Commit

Permalink
Add scripts for generating sample list (#963)
Browse files Browse the repository at this point in the history
* init project

* init .gitignore

* Add main scripts

* Add prefetch script

* Add extension-apis.json

* Add README.md

* Update comments

* Add newline to .gitignore

* Update type definition

* Update extension api json loading.

* Update README.md

* Update deps

* Pin deps versions

* Update extension-apis.json

* Update prefetch script

* Update script

* Remove type definitions prefix

* Add comment to auto generated json

* Split utils

* Update types

* Add manifest utils

* refactor

* Reject if there is a babel error.

* Add parallel support

* Remove redundant import

* loadExtensionApis execute synchronously

* Add test deps

* Fix unexpected result

* Add test scripts

* Update type definition

* Add start function

* Rename api variable

* Fix test

* Update getApiType method

* Remove singularize

* Fix loadExtensionApis return signature

* Remove parallel controller

* Update type definition

* Add comments

* Update types

* Update api detector

* Fix api test

* Add more test cases

* Remove `$special` key

* Fix typo

* Simplify code

* Rename `apiType` to `type`

* Add warning if no api found

* Rename variable

* Update getFullMemberExpression

* Remove the special case for `chrome.storage`.

* Add getManifest function

* Revoke changes

* Fix crash caused by incorrect folder detection

* Remove redundant import

* Check property type with typedoc

* Add action

* Fix wrong node version

* Update code

* Rename variable

* Remove unnecessary Map

* Update README

* Fix typo

* Remove unnecessary output

* Add comments

* Remove the judgment on storage API.

* Update test case

* Update comments

* Extract `getAllJsFile()` into the filesystem util

* Explain how to run the tests in README

* Pin deps

* Extract variable

* Extract `isDirectory()` into the filesystem util

* Remove assertion

* Update the parameter of `extractApiCalls()`

* Update tests

* Remove action
  • Loading branch information
daidr authored Aug 1, 2023
1 parent 6f2e616 commit 9d92728
Show file tree
Hide file tree
Showing 15 changed files with 6,461 additions and 0 deletions.
1 change: 1 addition & 0 deletions .repo/sample-list-generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension-samples.json
153 changes: 153 additions & 0 deletions .repo/sample-list-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Sample List Generator

## Overview

It's a script that generates `./extension-samples.json` with the list of all the samples available. Currently, this JSON will be provided to [developer.chrome.com](https://developer.chrome.com) for generating a list page containing all the samples. This allows developers to quickly find the sample they want to reference.

## How to use

### Install dependencies

```bash
npm install
```

### Run prefetch script (optional)

The prefetch script will generate a list of all the available extension apis on [developer.chrome.com](https://developer.chrome.com/docs/extensions/reference) and save it to `./extension-apis.json`.

The file `./extension-apis.json` will be committed so you don't need to run this script unless you want to update the list.

```bash
npm run prepare-chrome-types
```

### Run the generator

```bash
npm start
```

### Run the tests

```bash
npm test
```

## Types

```ts
type ApiTypeResult = 'event' | 'method' | 'property' | 'type' | 'unknown';

interface ApiItem {
type: ApiTypeResult;
namespace: string;
propertyName: string;
}

interface SampleItem {
type: 'API_SAMPLE' | 'FUNCTIONAL_SAMPLE';
name: string;
title: string;
description: string;
repo_link: string;
apis: ApiItem[];
permissions: string[];
}

// the type of extension-samples.json file is SampleItem[]
```

## Example

Here is an example of the generated `extension-samples.json` file:

```json
[
{
"type": "API_SAMPLE",
"name": "alarms",
"title": "Alarms API Demo",
"description": "",
"repo_link": "https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/api-samples/alarms",
"permissions": ["alarms"],
"apis": [
{
"type": "event",
"namespace": "runtime",
"propertyName": "onInstalled"
},
{
"type": "event",
"namespace": "action",
"propertyName": "onClicked"
},
{
"type": "event",
"namespace": "alarms",
"propertyName": "onAlarm"
},
{
"type": "type",
"namespace": "runtime",
"propertyName": "OnInstalledReason"
},
{
"type": "method",
"namespace": "alarms",
"propertyName": "create"
},
{
"type": "method",
"namespace": "tabs",
"propertyName": "create"
},
{
"type": "method",
"namespace": "alarms",
"propertyName": "clear"
},
{
"type": "method",
"namespace": "alarms",
"propertyName": "clearAll"
},
{
"type": "method",
"namespace": "alarms",
"propertyName": "getAll"
}
]
},
{
"type": "FUNCTIONAL_SAMPLE",
"name": "tutorial.getting-started",
"title": "Getting Started Example",
"description": "Build an Extension!",
"repo_link": "https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/tutorial.getting-started",
"permissions": ["storage", "activeTab", "scripting"],
"apis": [
{
"type": "event",
"namespace": "runtime",
"propertyName": "onInstalled"
},
{
"type": "property",
"namespace": "storage",
"propertyName": "sync"
},
{
"type": "method",
"namespace": "tabs",
"propertyName": "query"
},
{
"type": "method",
"namespace": "scripting",
"propertyName": "executeScript"
}
]
}
]
```
Loading

0 comments on commit 9d92728

Please sign in to comment.