New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

css-codemod

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-codemod - npm Package Compare versions

Comparing version 0.0.0-pr.3.1.9fed646 to 0.0.0-pr.4.1.40e7bbc

src/load-transform.ts

58

dist/cli.js
#!/usr/bin/env node
// src/cli.ts
console.log("hello world.");
var import_cac = require("cac");
var import_fs = require("fs");
var import_path = require("path");
// src/load-transform.ts
var import_bundle_require = require("bundle-require");
var MINIMUM_EXAMPLE_TRANSFORM = `
import { Transform } from "css-codemod";
export const transform: Transform = (file, api) => {};
`;
var validateTransform = (transform) => {
if (typeof transform === "function") {
return transform;
} else {
console.error(`Transform file must export a valid transform. For example:
${MINIMUM_EXAMPLE_TRANSFORM}`);
process.exit(1);
}
};
var loadTransform = async (filepath) => {
try {
const { mod } = await (0, import_bundle_require.bundleRequire)({ filepath });
const transform = validateTransform(mod.transform || mod.default);
return transform;
} catch (err) {
console.error(`An error occurred loading the transform file. Verify "${filepath}" exists.`);
process.exit(1);
}
};
// src/process-transform.ts
var processTransform = async (options) => {
console.log(options);
const transform = await loadTransform(options.transform);
transform();
};
// src/cli.ts
var PACKAGE_PATH = (0, import_path.join)(__dirname, "../package.json");
var PACKAGE_JSON = JSON.parse((0, import_fs.readFileSync)(PACKAGE_PATH, "utf8"));
var NAME = PACKAGE_JSON.name;
var VERSION = PACKAGE_JSON.version;
var run = async () => {
const cli = (0, import_cac.cac)(`${NAME}`);
cli.command("[files]", "File path to transform. Glob patterns are supported.").example(`${NAME} ./a.css`).example(`${NAME} ./src/a.css`).example(`${NAME} ./src/**/*.css`).example(`${NAME} ./**/*.css`).option("-t, --transform <transform>", "Path to the transform file", {
default: "./transform.ts"
}).action(async (files, flags) => {
const { transform } = flags;
await processTransform({ files, transform });
});
cli.help();
cli.version(VERSION);
cli.parse(process.argv, { run: false });
await cli.runMatchedCommand();
};
run();

10

package.json
{
"version": "0.0.0-pr.3.1.9fed646",
"version": "0.0.0-pr.4.1.40e7bbc",
"license": "MIT",

@@ -26,3 +26,4 @@ "name": "css-codemod",

"analyze": "size-limit --why",
"clean": "rimraf dist"
"clean": "rimraf dist",
"css-codemod": "yarn build && ./dist/cli.js"
},

@@ -52,2 +53,3 @@ "husky": {

"@size-limit/preset-small-lib": "^7.0.5",
"@types/node": "^17.0.13",
"dripip": "^0.10.0",

@@ -63,4 +65,8 @@ "husky": "^7.0.4",

"dependencies": {
"bundle-require": "^3.0.2",
"cac": "^6.7.12",
"esbuild": "^0.14.14",
"glob": "^7.2.0",
"postcss": "^8.4.5"
}
}

@@ -5,18 +5,71 @@ # :snake: css-codemod

## Install
## Usage
TODO
There are two ways to use css-codemod.
## Usage
First, using [npx](https://www.npmjs.com/package/npx) to execute the transform without need to explicitly install `css-codemod`.
TODO
```bash
npx css-codemod ./src/**/*.css -t ./transform.ts
```
### CLI
Second, install `css-codemod` as a dependency and execute with your package manager of choice.
TODO
```bash
# Install and execute css-codemod with npm
npm i -D css-codemod
./node_modules/.bin/css-codemod ./src/**/*.css -t ./transform.ts
### API
# Or, install and execute css-codemod with yarn
yarn add -D css-codemod
yarn css-codemod ./src/**/*.css -t ./transform.ts
```
TODO
## Transform
The transform file defines the transformations to define. The transform can be written in either JavaScript or TypeScript.
```ts
// transform.ts
// Import the `Transform` type to provide type-safety when
// using and creating a transform function.
import { Transform } from 'css-codemod';
// Define a named `transform` export.
// Note: it's important the function is named `transform` because that's
// what the tool expects.
export const transform: Transform = (file, api) => {
// Implement the transform.
};
```
## CLI
```bash
Usage:
$ css-codemod [files]
Commands:
[files] File path to transform. Glob patterns are supported.
For more info, run any command with the `--help` flag:
$ css-codemod --help
Options:
-t, --transform <transform> Path to the transform file (default: ./transform.ts)
-h, --help Display this message
-v, --version Display version number
Examples:
css-codemod ./a.css
css-codemod ./src/a.css
css-codemod ./src/**/*.css
css-codemod ./**/*.css
```
## API
TODO(Document transform function API)
### PostCSS

@@ -23,0 +76,0 @@

#!/usr/bin/env node
console.log('hello world.');
import { cac } from 'cac';
import { readFileSync } from 'fs';
import { join } from 'path';
import { processTransform } from './process-transform';
const PACKAGE_PATH = join(__dirname, '../package.json');
const PACKAGE_JSON = JSON.parse(readFileSync(PACKAGE_PATH, 'utf8'));
const NAME = PACKAGE_JSON.name;
const VERSION = PACKAGE_JSON.version;
const run = async () => {
const cli = cac(`${NAME}`);
cli
.command('[files]', 'File path to transform. Glob patterns are supported.')
.example(`${NAME} ./a.css`)
.example(`${NAME} ./src/a.css`)
.example(`${NAME} ./src/**/*.css`)
.example(`${NAME} ./**/*.css`)
.option('-t, --transform <transform>', 'Path to the transform file', {
default: './transform.ts',
})
.action(async (files: string[], flags) => {
const { transform } = flags;
await processTransform({ files, transform });
});
cli.help();
cli.version(VERSION);
cli.parse(process.argv, { run: false });
await cli.runMatchedCommand();
};
run();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc