@remvst/asset-catalog 1.0.3 → 1.0.5

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,2 +1,10 @@
1
1
  # asset-catalog
2
2
 
3
+ Utilities to generate asset catalogs for Webpack.
4
+
5
+ ## Test
6
+
7
+ ```sh
8
+ mkdir -p testOut
9
+ npm t
10
+ ```
@@ -95,7 +95,7 @@ async function main() {
95
95
  let totalFileSize = 0;
96
96
  for (const soundFile of files) {
97
97
  const importName = (0, utils_1.sanitize)(soundFile);
98
- imports.push(`import ${importName} from '${(0, path_1.relative)((0, path_1.dirname)(argv.outFile), soundFile)}';`);
98
+ imports.push(`import ${importName} from '${(0, path_1.relative)((0, path_1.dirname)(argv.outFile), soundFile).replace(/\\/g, '/')}';`);
99
99
  func += ` ${importName},\n`;
100
100
  const stats = await fs_1.promises.stat(soundFile);
101
101
  totalFileSize += stats.size;
package/lib/utils.js CHANGED
@@ -38,7 +38,7 @@ function categoryPath(assetDir, png) {
38
38
  const dir = (0, path_1.dirname)(png);
39
39
  const trimmedDir = (0, path_1.relative)(assetDir, dir);
40
40
  return trimmedDir
41
- .split('/')
41
+ .split(/[\/\\]/g)
42
42
  .map(component => lowerCamelize(component))
43
43
  .filter(component => component.length > 0);
44
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/asset-catalog",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "generate-image-catalog": "./lib/generate-image-catalog.js",
@@ -70,16 +70,16 @@ async function generatedCreateCatalogFunction(assetDir: string, tree: Tree): Pro
70
70
  async function main() {
71
71
  const argv = await yargs(hideBin(process.argv))
72
72
  .options({
73
- 'outFile': {
74
- type: 'string',
75
- default: '.',
76
- alias: 'o',
73
+ 'outFile': {
74
+ type: 'string',
75
+ default: '.',
76
+ alias: 'o',
77
77
  describe: 'Directory to generate the files into',
78
78
  },
79
- 'assetDir': {
80
- type: 'string',
81
- default: './package.json',
82
- alias: 'a',
79
+ 'assetDir': {
80
+ type: 'string',
81
+ default: './package.json',
82
+ alias: 'a',
83
83
  describe: 'package.json file to use for the version',
84
84
  }
85
85
  })
@@ -9,31 +9,31 @@ import { dirname, extname, basename, relative } from 'path';
9
9
  async function main() {
10
10
  const argv = await yargs(hideBin(process.argv))
11
11
  .options({
12
- 'outFile': {
13
- type: 'string',
14
- default: '.',
15
- alias: 'o',
12
+ 'outFile': {
13
+ type: 'string',
14
+ default: '.',
15
+ alias: 'o',
16
16
  describe: 'Directory to generate the files into',
17
17
  },
18
- 'assetDir': {
19
- type: 'string',
20
- default: './package.json',
21
- alias: 'a',
18
+ 'assetDir': {
19
+ type: 'string',
20
+ default: './package.json',
21
+ alias: 'a',
22
22
  describe: 'package.json file to use for the version',
23
23
  },
24
- 'wav': {
25
- type: 'boolean',
26
- default: false,
24
+ 'wav': {
25
+ type: 'boolean',
26
+ default: false,
27
27
  describe: 'Include .wav files',
28
28
  },
29
- 'ogg': {
30
- type: 'boolean',
31
- default: true,
29
+ 'ogg': {
30
+ type: 'boolean',
31
+ default: true,
32
32
  describe: 'Include .ogg files',
33
33
  },
34
- 'mp3': {
35
- type: 'boolean',
36
- default: true,
34
+ 'mp3': {
35
+ type: 'boolean',
36
+ default: true,
37
37
  describe: 'Include .mp3 files',
38
38
  },
39
39
  })
@@ -103,7 +103,7 @@ async function main() {
103
103
  let totalFileSize = 0;
104
104
  for (const soundFile of files) {
105
105
  const importName = sanitize(soundFile);
106
- imports.push(`import ${importName} from '${relative(dirname(argv.outFile), soundFile)}';`);
106
+ imports.push(`import ${importName} from '${relative(dirname(argv.outFile), soundFile).replace(/\\/g, '/')}';`);
107
107
  func += ` ${importName},\n`;
108
108
  const stats = await fs.stat(soundFile);
109
109
  totalFileSize += stats.size;
package/src/utils.ts CHANGED
@@ -22,7 +22,7 @@ export async function allFiles(path: string): Promise<string[]> {
22
22
  }
23
23
 
24
24
  export function sanitize(string: string): string {
25
- return string.replace(/[^a-zA-Z0-9]/g, '_');
25
+ return string.replace(/[^a-zA-Z0-9]/g, '_');
26
26
  }
27
27
 
28
28
  export function camelize(str: string) {
@@ -34,12 +34,11 @@ export function lowerCamelize(str: string): string {
34
34
  return camelized.slice(0, 1).toLowerCase() + camelized.slice(1);
35
35
  }
36
36
 
37
-
38
37
  export function categoryPath(assetDir: string, png: string): string[] {
39
38
  const dir = dirname(png);
40
39
  const trimmedDir = relative(assetDir, dir);
41
40
  return trimmedDir
42
- .split('/')
41
+ .split(/[\/\\]/g)
43
42
  .map(component => lowerCamelize(component))
44
43
  .filter(component => component.length > 0);
45
44
  }
Binary file
Binary file
package/testData/fire.png DELETED
Binary file
Binary file
Binary file