Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit a0d3422

Browse files
author
Matt Goo
committed
WIP: remove typescriptwhitelist
1 parent af44094 commit a0d3422

File tree

5 files changed

+96
-154
lines changed

5 files changed

+96
-154
lines changed

package-lock.json

Lines changed: 9 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"cz-conventional-changelog": "^2.0.0",
7171
"dart-sass": "^1.15.2",
7272
"debounce": "^1.1.0",
73-
"del": "^3.0.0",
7473
"del-cli": "^1.0.0",
7574
"detect-port": "^1.2.3",
7675
"dom-events": "^0.1.1",
@@ -80,7 +79,7 @@
8079
"express": "^4.16.3",
8180
"extract-text-webpack-plugin": "^3.0.0",
8281
"fibers": "^3.0.0",
83-
"fs-extra": "^7.0.0",
82+
"fs-extra": "^7.0.1",
8483
"glob": "^7.1.1",
8584
"google-closure-compiler": "^20181008.0.0",
8685
"gts": "^0.9.0",

scripts/rewrite-declation-statements-for-typescript.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,11 @@ const t = require('babel-types');
8080

8181
const THIRD_PARTY_PATH = 'mdc.thirdparty.';
8282

83-
main(process.argv);
84-
85-
function main(argv) {
86-
if (argv.length < 3) {
83+
function main(rootDir) {
84+
if (!rootDir) {
8785
console.error('Missing root directory path');
88-
process.exit(1);
8986
}
9087

91-
const rootDir = path.resolve(process.argv[2]);
9288
const srcFiles = glob.sync(`${rootDir}/**/*.{js,ts}`);
9389

9490
srcFiles.forEach((srcFile) => transform(srcFile, rootDir));
@@ -151,7 +147,7 @@ function rewriteDeclarationSource(node, srcFile, rootDir) {
151147
let source = node.source.value;
152148
const pathParts = source.split('/');
153149
const isMDCImport = pathParts[0] === '@material';
154-
150+
console.log('\n isMDCImport', isMDCImport, srcFile)
155151
// format `source` for @material/foo imports
156152
if (isMDCImport) {
157153
const modName = pathParts[1]; // @material/<modName>
@@ -212,3 +208,5 @@ function logProgress(msg) {
212208
logProgress.__prev_msg_length = msg.length;
213209
process.stdout.write('\r' + msg);
214210
}
211+
212+
module.exports = {main};

scripts/typescript-rewrite.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
*/
23+
const fs = require('fs');
24+
const fse = require('fs-extra');
25+
26+
const {main} = require('./rewrite-declation-statements-for-typescript');
27+
28+
const TYPESCRIPT_TMP = '.typescript-tmp';
29+
const TYPESCRIPT_PKGDIR = `${TYPESCRIPT_TMP}/packages`;
30+
const SOURCEDIR = './packages';
31+
32+
33+
function logProgress(msg) {
34+
if (logProgress.__prev_msg_length) {
35+
const lineClear = ' '.repeat(logProgress.__prev_msg_length + 10);
36+
process.stdout.write('\r' + lineClear);
37+
}
38+
logProgress.__prev_msg_length = msg.length;
39+
process.stdout.write('\r' + msg);
40+
}
41+
42+
function getAllPackageFiles() {
43+
return fs.readdirSync(SOURCEDIR).map((packages) => packages);
44+
}
45+
46+
function excludeCompiledDirectories(src) {
47+
if (!src.includes('/node_modules/') && !src.includes('dist')) {
48+
return true;
49+
}
50+
return false;
51+
}
52+
53+
function movePackagesToTypescriptTmp() {
54+
fs.mkdirSync(TYPESCRIPT_PKGDIR);
55+
const copyTasks = [];
56+
const removeTasks = [];
57+
58+
getAllPackageFiles().forEach((packageName) => {
59+
const packageSourcePath = `${SOURCEDIR}/${packageName}`;
60+
const packageDestinationPath = `${TYPESCRIPT_PKGDIR}/${packageName}`;
61+
62+
const packageCopyPromise = fse.copy(packageSourcePath, packageDestinationPath, {filter: excludeCompiledDirectories})
63+
.then(() => {
64+
logProgress(`Successfully copied ${packageName}`);
65+
}).catch((err) => console.log(err));
66+
67+
copyTasks.push(packageCopyPromise);
68+
});
69+
70+
const promises = [].concat(copyTasks, removeTasks);
71+
72+
Promise.all(promises).then(() => {
73+
console.log('Rewriting all import statements to be internal typescript compatible');
74+
main(TYPESCRIPT_PKGDIR);
75+
});
76+
}
77+
78+
console.log('Prepping typescript packages for JS rewrite');
79+
fse.emptyDir(TYPESCRIPT_TMP)
80+
.then(movePackagesToTypescriptTmp)
81+
.catch((err) => console.log(err));

scripts/typescript-rewrite.sh

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)