-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
222 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
type Errors = $ReadOnly<{ | ||
dirNotFound: Error, | ||
}>; | ||
|
||
const errors: Errors = { | ||
dirNotFound: new Error('Invalid Directory: Not Found'), | ||
}; | ||
|
||
export default errors; |
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,57 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
// import type { Rule } from '@stylexjs/babel-plugin'; | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
import errors from './errors'; | ||
|
||
// gets the directory for compiled styles (creates it if it doesn't exist) | ||
export function makeCompiledDir(compiledDir: string): void { | ||
if (!fs.existsSync(compiledDir)) { | ||
console.log('made dir', compiledDir); | ||
fs.mkdirSync(compiledDir); | ||
} | ||
} | ||
|
||
export function getInputDirectoryFiles(inputDir: string): Array<string> { | ||
if (!fs.existsSync(inputDir)) { | ||
throw errors.dirNotFound; | ||
} else { | ||
const files = fs.readdirSync(inputDir, { recursive: true }); | ||
return files.filter((file) => { | ||
const maybeDir = path.join(inputDir, file); | ||
return !isDir(maybeDir); | ||
}); | ||
} | ||
} | ||
|
||
// takes in the compiled rules and writes them to a file at the top of the compiled directory | ||
export function writeCompiledCSS(filePath: string, compiledCSS: string): void { | ||
fs.writeFileSync(filePath, compiledCSS); | ||
} | ||
|
||
export function writeCompiledJS(path: string, code: string): void { | ||
makeDirExistRecursive(path); | ||
fs.writeFileSync(path, code, {}); | ||
} | ||
|
||
export function isDir(path: string): boolean { | ||
return fs.lstatSync(path).isDirectory(); | ||
} | ||
|
||
function makeDirExistRecursive(filePath: string): ?boolean { | ||
const dirName = path.dirname(filePath); | ||
if (fs.existsSync(dirName)) { | ||
return true; | ||
} | ||
makeDirExistRecursive(dirName); | ||
fs.mkdirSync(dirName); | ||
} |
Oops, something went wrong.