Skip to content

Commit e0165cd

Browse files
authored
Merge pull request #181 from twilio/dev
Dev
2 parents 017aeaa + d32d3e2 commit e0165cd

File tree

182 files changed

+8439
-1121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+8439
-1121
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Please provide the steps to reproduce this bug:
3131

3232
A clear and concise description of what you expected to happen.
3333

34-
### Screenhots
34+
### Screenshots
3535

3636
If applicable, add screenshots to help explain your problem.
3737

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ plugin-test/
7171
package-lock.json
7272

7373
.idea
74+
75+
.lerna_backup

.prettierrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"useTabs": false,
3-
"tabWidth": 4,
4-
"semi": true,
5-
"trailingComma": "es5",
6-
"singleQuote": true
2+
"useTabs": false,
3+
"tabWidth": 2,
4+
"semi": true,
5+
"trailingComma": "es5",
6+
"singleQuote": true
77
}

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ language: node_js
33
node_js:
44
- '8'
55

6+
before_install:
7+
- sudo apt-get update
8+
- sudo apt-get install -y libsecret-1-dev
9+
610
before_script:
711
- npm install
812

913
script:
1014
- npm run lint
11-
- npm run test
15+
- CI= npm run test
1216

1317
after_success:
1418
- codecov --token="$CODECOV_TOKEN"

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,22 @@
2525

2626
## Getting Started
2727

28-
---
29-
**NOTE**
30-
31-
Flex plugin builder v3 is available in beta. Docs are available on the [dev branch](https://github.com/twilio/flex-plugin-builder/tree/dev). For more information please visit [Twilio Docs - Flex Plugin Builder](https://www.twilio.com/docs/flex/plugin-builder#plugin-builder-v3)
32-
33-
---
34-
3528
This is a monorepo project managed by [lerna](https://github.com/lerna/lerna) for creating Twilio Flex plugins.
3629

3730
- [create-flex-plugin](packages/create-flex-plugin): The CLI tool to start a new Flex plugin project
3831
- [flex-plugin](packages/flex-plugin): Runtime dependency for Flex plugins
32+
- [flex-plugin-scripts](packages/flex-plugin-scripts): The scripts used for building, testing, and deploying your plugin
3933
- [craco-config-flex-plugin](packages/craco-config-flex-plugin): Config override for [Create React App](https://github.com/facebook/create-react-app) using [craco](https://github.com/sharegate/craco)
4034

4135
## User Guide
4236

4337
* [Creating a new plugin](packages/create-flex-plugin/README.md)
4438
* [Overriding configuration](packages/craco-config-flex-plugin/README.md)
39+
* [Available Scripts](packages/flex-plugin-scripts/README.md)
4540

4641
## Changelog
4742

48-
Major changelogs can be found in the [changelog directory](/changelog/CHANGELOG.md).
43+
Major changelogs can be found in the [changelog directory](/changelog).
4944

5045
## Contributing
5146

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = {
33
"@babel/env",
44
"@babel/typescript"
55
]
6-
}
6+
};

bin/docs-generator.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env node
2+
3+
const glob = require('glob');
4+
const fs = require('fs');
5+
const path = require('path');
6+
const pipe = require('@k88/pipe-compose').pipe;
7+
8+
const inlineCommentsRegex = /<!--[\S\s]*-->/;
9+
const includeRegex = /docs-generator:include\(['"]?([\w\/.]*)['"]?\)/;
10+
const docStartRegex = /docs-generator:start/;
11+
const docEndRegex = /docs-generator:end/;
12+
13+
const docStartComment = '<!-- docs-generator:start - Do not remove or modify this section -->';
14+
const docEndComment = '<!-- docs-generator:end - Do not remove or modify this section -->';
15+
16+
const rootDir = path.dirname(__dirname);
17+
const pattern = `${rootDir}/packages/**/docs.config.js`;
18+
const packages = glob.sync(pattern, { ignore: '**/node_modules/**' });
19+
20+
/**
21+
* Validates the configuration format
22+
*
23+
* @param config
24+
* @returns boolean
25+
*/
26+
const validateConfig = (config) => config.main && config.output;
27+
28+
/**
29+
* Flattens array
30+
*
31+
* @param arr
32+
* @returns {*[]}
33+
*/
34+
const flatten = (arr) => [].concat.apply([], arr);
35+
36+
/**
37+
* Reads the file
38+
*
39+
* @param filePath the file path
40+
* @returns {string} the file content
41+
*/
42+
const readFile = (filePath) => fs.readFileSync(filePath, 'utf8');
43+
44+
/**
45+
* Looks up for `<!-- docs-generator:include('/path') --!>` and includes the content
46+
*
47+
* @param dir
48+
* @returns {function(*): *[]}
49+
*/
50+
const addInclude = (dir) => {
51+
return lines => {
52+
const newLines = lines.map(line => {
53+
if (!inlineCommentsRegex.test(line)) {
54+
return line;
55+
}
56+
57+
const match = line.match(includeRegex);
58+
if (!match || !match.length) {
59+
return line;
60+
}
61+
62+
const file = readFile(path.join(dir, match[1]));
63+
const newLine = [
64+
line,
65+
docStartComment,
66+
file.split('\n'),
67+
docEndComment,
68+
];
69+
70+
return flatten(newLine);
71+
});
72+
73+
return flatten(newLines);
74+
}
75+
};
76+
77+
/**
78+
* Cleans up/removes all the auto-generated lines
79+
* @param lines
80+
* @returns {*}
81+
*/
82+
const cleanGeneratedLines = (lines) => {
83+
const docStartLines = [];
84+
const docEndLines = [];
85+
86+
lines.forEach((line, index) => {
87+
if (!inlineCommentsRegex.test(line)) {
88+
return;
89+
}
90+
91+
if (docStartRegex.test(line)) {
92+
docStartLines.push(index);
93+
}
94+
95+
if (docEndRegex.test(line)) {
96+
docEndLines.push(index);
97+
}
98+
});
99+
100+
if (docEndLines.length !== docStartLines.length) {
101+
console.error('Found unmatched docs-generator blocks');
102+
return lines;
103+
}
104+
105+
while (docStartLines.length) {
106+
const startIndex = docStartLines.pop();
107+
const endIndex = docEndLines.pop();
108+
109+
lines.splice(startIndex, endIndex - startIndex + 1);
110+
}
111+
112+
return lines;
113+
};
114+
115+
/**
116+
* Main script generator
117+
* @param dir
118+
*/
119+
const generate = (dir) => {
120+
const config = require(path.join(dir, 'docs.config.js'));
121+
if (!validateConfig(config)) {
122+
console.error('Configuration for %s is invalid', dir);
123+
return;
124+
}
125+
126+
const main = readFile(path.join(dir, config.main));
127+
const output = path.join(dir, config.output);
128+
129+
const lines = main.split('\n');
130+
const formattedLines = pipe(lines, cleanGeneratedLines, addInclude(dir));
131+
132+
fs.writeFileSync(output, formattedLines.join('\n'));
133+
};
134+
135+
packages
136+
.map(path.dirname)
137+
.forEach(generate);

bin/publish

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function run_script() {
2121

2222
# Cleanup
2323
run_script $LERNA clean -y
24+
run_script $LERNA run clean
2425
run_script rm -rf node_modules
2526

2627
# Install
@@ -35,7 +36,13 @@ run_script npm run build
3536

3637
# Publish
3738
if [ "$1" == "public" ] ; then
39+
echo -e "\n------------------------------------"
40+
echo "-- Publishing as a public release --"
41+
echo -e "------------------------------------\n"
3842
run_script $LERNA publish
3943
else
44+
echo -e "\n-----------------------------------------"
45+
echo "-- Publishing as a beta (next) release --"
46+
echo -e "-----------------------------------------\n"
4047
run_script $LERNA publish --dist-tag next
4148
fi
File renamed without changes.

jest.config.base.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ module.exports = {
77
testEnvironment: 'jsdom',
88
collectCoverageFrom: [
99
'<rootDir>/packages/**/src/**/*.ts',
10+
'!<rootDir>/packages/**/src/**/*.d.ts',
1011
'!<rootDir>/packages/**/src/**/*.test.ts',
1112
'!<rootDir>/packages/**/src/index.ts',
1213
'!<rootDir>/packages/**/templates/**/*.ts',
14+
'!<rootDir>/packages/**/prints/**/*.ts',
1315
],
1416
testMatch: [
1517
'<rootDir>/packages/**/*.test.ts'
@@ -22,5 +24,8 @@ module.exports = {
2224
],
2325
coveragePathIgnorePatterns: [
2426
'/node_modules/',
27+
],
28+
modulePathIgnorePatterns: [
29+
'<rootDir>/packages/create-flex-plugin/templates/'
2530
]
2631
};

0 commit comments

Comments
 (0)