@mlaursen/cli 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # @mlaursen/copy-scss-files
1
+ # @mlaursen/cli
2
2
 
3
3
  A small util to copy scss files for publishing.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install -D @mlaursen/cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The cli is setup to work with my general setup so defaults to finding all
14
+ `.scss` files in the `src` directory and copies them to a `dist` directory
15
+ maintaining folder structure.
16
+
17
+ My normal setup is:
18
+
19
+ ```diff
20
+ "scripts": {
21
+ "clean-dist": "rm -rf dist",
22
+ "clean-cache": "rm -rf .turbo node_modules",
23
+ "clean": "concurrently 'pnpm clean-dist' 'pnpm clean-cache'",
24
+ "build-esm": "swc -d ./dist --strip-leading-paths src",
25
+ "build-esm-watch": "pnpm build-esm --watch",
26
+ "build-types": "tsc -P tsconfig.types.json",
27
+ "build-types-watch": "pnpm build-types --watch",
28
+ - "build": "concurrently 'pnpm build-esm' 'pnpm build-types'",
29
+ + "build-scss": "mlaursen-cli copy-scss-files",
30
+ + "build-scss-watch": "mlaursen-cli copy-scss-files --watch",
31
+ + "build": "concurrently 'pnpm build-esm' 'pnpm build-types' 'pnpm build-scss'",
32
+ },
33
+ ```
34
+
35
+ If files need to also be copied to the root so they can be used before the main
36
+ import:
37
+
38
+ ```sh
39
+ mlaursen-cli copy-scss-files -r "_file1.scss" -r "_file2.scss"
40
+ mlaursen-cli copy-scss-files -r "_file1.scss" -r "_file2.scss" --watch
41
+ ```
42
+
43
+ Help and other info can be printed as needed:
44
+
45
+ ```sh
46
+ npx mlaursen-cli -h
47
+
48
+ npx mlaursen-cli copy-scss-files -h
49
+ ```
package/dist/cli.mjs CHANGED
@@ -1,12 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import { copyScssFiles } from '@mlaursen/copy-scss-files';
2
+ import { enableLogger, copyScssFiles } from '@mlaursen/copy-scss-files';
3
3
  import { Command } from 'commander';
4
+ import { basename, join } from 'node:path';
4
5
 
5
6
  const program = new Command("@mlaursen/cli");
6
- program.command("copy-scss-files").argument("[pattern]", "An optional scss file pattern").option("--src <src>", "An optional src directory", "src").option("-o, --out <dir>", "An optional dist directory", "dist").option("-w, --watch", "Watch mode", false).action((pattern, options)=>{
7
+ program.command("copy-scss-files").argument("[pattern]", "An optional scss file pattern").option("--src <src>", "An optional src directory", "src").option("-o, --out <dir>", "An optional dist directory", "dist").option("-w, --watch", "Watch mode", false).option("-v, --verbose", "Verbose logging mode", false).option("-r, --copy-to-root <fileName>", "Also copy this file to the root directory", (value, previous)=>{
8
+ previous.add(value);
9
+ return previous;
10
+ }, new Set()).action((pattern, options)=>{
11
+ const { copyToRoot, verbose, ...copyOptions } = options;
12
+ if (verbose) {
13
+ enableLogger();
14
+ }
7
15
  return copyScssFiles({
8
- ...options,
9
- pattern
16
+ ...copyOptions,
17
+ pattern,
18
+ getDistPaths: (path, renameDist)=>{
19
+ const paths = [
20
+ renameDist(path)
21
+ ];
22
+ if (copyToRoot.size > 0) {
23
+ const name = basename(path);
24
+ if (copyToRoot.has(name)) {
25
+ paths.push(renameDist(join(options.src, name)));
26
+ }
27
+ }
28
+ return paths;
29
+ }
10
30
  });
11
31
  });
12
32
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mlaursen/cli",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.1.0",
5
5
  "description": "A small util to copy SCSS files for publishing.",
6
6
  "bin": {
7
7
  "mlaursen-cli": "./dist/cli.mjs"
@@ -9,27 +9,27 @@
9
9
  "dependencies": {
10
10
  "chokidar": "^5.0.0",
11
11
  "glob": "^13.0.0",
12
- "@mlaursen/copy-scss-files": "0.0.1"
12
+ "@mlaursen/copy-scss-files": "0.1.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@rollup/plugin-node-resolve": "^16.0.3",
16
- "@trivago/prettier-plugin-sort-imports": "^6.0.0",
17
- "@types/node": "^24.10.1",
16
+ "@trivago/prettier-plugin-sort-imports": "^6.0.2",
17
+ "@types/node": "^25.0.9",
18
18
  "commander": "^14.0.2",
19
19
  "concurrently": "^9.2.1",
20
- "eslint": "^9.39.1",
21
- "prettier": "^3.7.4",
22
- "rollup": "^4.53.3",
20
+ "eslint": "^9.39.2",
21
+ "prettier": "^3.8.0",
22
+ "rollup": "^4.55.2",
23
23
  "rollup-plugin-swc3": "^0.12.1",
24
24
  "typescript": "^5.9.3",
25
- "@mlaursen/eslint-config": "10.1.0"
25
+ "@mlaursen/eslint-config": "12.0.2"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
30
  "volta": {
31
- "node": "24.11.0",
32
- "pnpm": "10.20.0"
31
+ "node": "24.12.0",
32
+ "pnpm": "10.26.1"
33
33
  },
34
34
  "scripts": {
35
35
  "clean-dist": "rm -rf dist types",
package/src/cli.ts CHANGED
@@ -1,5 +1,17 @@
1
- import { copyScssFiles } from "@mlaursen/copy-scss-files";
1
+ import {
2
+ type CopyScssFilesOptions,
3
+ copyScssFiles,
4
+ enableLogger,
5
+ } from "@mlaursen/copy-scss-files";
2
6
  import { Command } from "commander";
7
+ import { basename, join } from "node:path";
8
+
9
+ interface ProgramCopyScssFilesOptions extends Required<
10
+ Omit<CopyScssFilesOptions, "getDistPaths" | "pattern">
11
+ > {
12
+ copyToRoot: Set<string>;
13
+ verbose: boolean;
14
+ }
3
15
 
4
16
  const program = new Command("@mlaursen/cli");
5
17
  program
@@ -8,10 +20,36 @@ program
8
20
  .option("--src <src>", "An optional src directory", "src")
9
21
  .option("-o, --out <dir>", "An optional dist directory", "dist")
10
22
  .option("-w, --watch", "Watch mode", false)
11
- .action((pattern, options) => {
23
+ .option("-v, --verbose", "Verbose logging mode", false)
24
+ .option<Set<string>>(
25
+ "-r, --copy-to-root <fileName>",
26
+ "Also copy this file to the root directory",
27
+ (value, previous) => {
28
+ previous.add(value);
29
+ return previous;
30
+ },
31
+ new Set()
32
+ )
33
+ .action((pattern: string, options: ProgramCopyScssFilesOptions) => {
34
+ const { copyToRoot, verbose, ...copyOptions } = options;
35
+ if (verbose) {
36
+ enableLogger();
37
+ }
38
+
12
39
  return copyScssFiles({
13
- ...options,
40
+ ...copyOptions,
14
41
  pattern,
42
+ getDistPaths: (path, renameDist) => {
43
+ const paths = [renameDist(path)];
44
+ if (copyToRoot.size > 0) {
45
+ const name = basename(path);
46
+ if (copyToRoot.has(name)) {
47
+ paths.push(renameDist(join(options.src, name)));
48
+ }
49
+ }
50
+
51
+ return paths;
52
+ },
15
53
  });
16
54
  });
17
55