forked from scandipwa/scandipwa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge master into ts-migration branch
- Loading branch information
Showing
14 changed files
with
1,489 additions
and
1,522 deletions.
There are no files selected for viewing
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
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
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
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,26 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
export const getAllFilesFromPath = (pathname: string): string[] => { | ||
const files = fs.readdirSync(pathname); | ||
|
||
return files.reduce((acc, file) => { | ||
if (/node_modules/gm.test(file)) { | ||
// ^^^ ignore node_modules | ||
return acc; | ||
} | ||
|
||
const filePath = path.join(pathname, file); | ||
|
||
if (!fs.statSync(filePath).isDirectory()) { | ||
if (!(/\.[tj]sx?$/gm.test(file))) { | ||
// ^^^ Ignore non-js files | ||
return acc; | ||
} | ||
|
||
return [...acc, filePath]; | ||
} | ||
|
||
return [...acc, ...getAllFilesFromPath(filePath)]; | ||
}, [] as string[]); | ||
}; |
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,51 @@ | ||
import { getMosaicConfig } from '@tilework/mosaic-dev-utils/mosaic-config'; | ||
import { getPackageJson } from '@tilework/mosaic-dev-utils/package-json'; | ||
|
||
import { getAllFilesFromPath } from './all-files'; | ||
import { getPackagePath } from './package-path'; | ||
|
||
let visitedDeps: string[] = []; | ||
|
||
export const getAllExtensions = (pathname: string = process.cwd(), _isFirst = true): string[] => { | ||
if (_isFirst) { | ||
visitedDeps = []; | ||
} | ||
|
||
if (visitedDeps.indexOf(pathname) !== -1) { | ||
return []; | ||
} | ||
|
||
visitedDeps.push(pathname); | ||
|
||
try { | ||
const packageJson = getPackageJson(pathname); | ||
const { dependencies = {} } = packageJson; | ||
const { extensions = {} } = getMosaicConfig(pathname); | ||
const extensionFolders = Object.keys(extensions).map( | ||
(packageName) => getPackagePath(packageName) | ||
); | ||
|
||
return Array.from( | ||
Object.keys(dependencies).reduce( | ||
(acc, packageName: string) => { | ||
const packagePath = getPackagePath(packageName); | ||
const childExtensions = getAllExtensions(packagePath, false); | ||
childExtensions.forEach((ext) => acc.add(ext)); | ||
return acc; | ||
}, | ||
new Set(extensionFolders) | ||
) | ||
); | ||
} catch (e) { | ||
return []; | ||
} | ||
}; | ||
|
||
export const getAllExtensionsFiles = (sourcePath: string): string[] => { | ||
const extensions = getAllExtensions(sourcePath); | ||
|
||
return extensions.reduce((acc, extension) => ([ | ||
...acc, | ||
...getAllFilesFromPath(extension) | ||
]), [] as string[]); | ||
}; |
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,22 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
export const getPackagePath = (packageName: string, context: string = process.cwd()): string => { | ||
const possibleRelativePath = path.join( | ||
process.cwd(), | ||
packageName, | ||
'package.json' | ||
); | ||
|
||
const isPathReference = fs.existsSync(possibleRelativePath); | ||
|
||
if (isPathReference) { | ||
return path.join(possibleRelativePath, '..'); | ||
} | ||
|
||
// This is not a local package, path based extension -> try loading it as a package | ||
return path.join( | ||
require.resolve(`${ packageName }/package.json`, { paths: [context] }), | ||
'..' | ||
); | ||
}; |
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
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.