Skip to content

Commit

Permalink
🏗♻️ Share extension generator implementation (#34002)
Browse files Browse the repository at this point in the history
Refactors the filesystem-read extension generator built for **Bento**, so that it can be used for **Classic** components.

- Moves templates in `bento/` to `template/bento/extensions/`.
  This follows: `template/${templateName}/${rootDirPath...}`.
  - Code rules can now be excluded from `template/**`
  - We now start from the root directory so we can generate an `examples/` file for Classic.
  - (It also means that we can use the generator for anything and not just extensions.)

- Moves some existing templates to `template/shared` which is used for both Bento and Classic.

- Rewrites Classic templates to match the new filesystem-read generator, into `template/classic`.

- The Classic generator would `prettier`-format, while Bento would not. Generated files are now always formatted.

- Adds a few tests.

New template directory structure:
```
build-system/tasks/make-extension/template
├── bento
│   └── extensions
│       └── amp-__component_name_hyphenated__
│           ├── OWNERS
│           └── __component_version__
│               ├── amp-__component_name_hyphenated__.js
│               ├── base-element.js
│               ├── component.js
│               ├── component.jss.js
│               ├── component.type.js
│               ├── storybook
│               │   ├── Basic.amp.js
│               │   └── Basic.js
│               └── test
│                   └── test-amp-__component_name_hyphenated__.js
├── classic
│   ├── examples
│   │   └── amp-__component_name_hyphenated__.html
│   └── extensions
│       └── amp-__component_name_hyphenated__
│           ├── OWNERS
│           └── __component_version__
│               ├── amp-__component_name_hyphenated__.js
│               └── test
│                   ├── test-amp-__component_name_hyphenated__.js
│                   └── __validator__-amp-__component_name_hyphenated__.html
└── shared
    └── extensions
        └── amp-__component_name_hyphenated__
            ├── __component_version__
            │   └── amp-__component_name_hyphenated__.css
            ├── amp-__component_name_hyphenated__.md
            └── __validator__-amp-__component_name_hyphenated__.protoascii
```
  • Loading branch information
alanorozco authored Apr 26, 2021
1 parent f044f52 commit 991e546
Show file tree
Hide file tree
Showing 32 changed files with 784 additions and 516 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ validator/export
build-system/babel-plugins/**/fixtures/**/*.js
build-system/babel-plugins/**/fixtures/**/*.mjs
build-system/server/app-index/test/*.js
build-system/tasks/make-extension/bento/amp-__component_name_hyphenated__/**/*
build-system/tasks/make-extension/template/**/*
build-system/tasks/visual-diff/snippets/*.js
extensions/amp-a4a/0.1/test/testdata/**
src/purifier/noop.js
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"options": {"parser": "json5"}
},
{
"files": "build-system/tasks/make-extension/bento/amp-__component_name_hyphenated__/**",
"files": "build-system/tasks/make-extension/template/**",
"options": {
"requirePragma": true
}
Expand Down
1 change: 1 addition & 0 deletions build-system/pr-check/build-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const targetMatchers = {
return (
file == 'build-system/tasks/ava.js' ||
file.startsWith('build-system/tasks/get-zindex/') ||
file.startsWith('build-system/tasks/make-extension/') ||
file.startsWith('build-system/tasks/markdown-toc/') ||
file.startsWith('build-system/tasks/prepend-global/')
);
Expand Down
1 change: 1 addition & 0 deletions build-system/tasks/ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function ava() {
// (see targetMatchers[Targets.AVA])
const testFiles = [
'build-system/tasks/get-zindex/get-zindex.test.js',
'build-system/tasks/make-extension/test/test.js',
'build-system/tasks/markdown-toc/test/test.js',
'build-system/tasks/prepend-global/prepend-global.test.js',
];
Expand Down
3 changes: 2 additions & 1 deletion build-system/tasks/make-extension/OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
// Outreach group maintains extension boilerplate/template.
{name: 'ampproject/wg-outreach'},

// Most new extensions are reviewed by this group. It's in their
// Most new extensions are reviewed by these groups. It's in their
// interest to maintain the extension generator.
{name: 'ampproject/wg-components'},
{name: 'ampproject/wg-bento'},
],
},
],
Expand Down
166 changes: 0 additions & 166 deletions build-system/tasks/make-extension/bento/index.js

This file was deleted.

29 changes: 29 additions & 0 deletions build-system/tasks/make-extension/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const {getOutput} = require('../../common/process');

/**
* @param {Array<string>} files
* @return {Object}
*/
function format(files) {
return getOutput(`npx prettier --ignore-unknown --write ${files.join(' ')}`);
}

module.exports = {
format,
};
Loading

0 comments on commit 991e546

Please sign in to comment.