fabrique 0.2.0-beta-1 → 0.2.4

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.
@@ -4,3 +4,5 @@ npmRegistryServer: "http://localhost:4873"
4
4
 
5
5
  unsafeHttpWhitelist:
6
6
  - localhost
7
+
8
+ yarnPath: .yarn/releases/yarn-4.6.0.cjs
@@ -4,7 +4,7 @@ This projet is open to everyone. Feel free to test the library, share it, improv
4
4
 
5
5
  ### Getting started
6
6
 
7
- The library requires [Node.js](https://nodejs.org/en) `22+` and `yarn`.
7
+ The library requires [Node.js](https://nodejs.org/en) `22+` and [yarn](https://yarnpkg.com/).
8
8
 
9
9
  First, we have to switch to the correct version of node:
10
10
 
@@ -12,7 +12,7 @@ First, we have to switch to the correct version of node:
12
12
  nvm use
13
13
  ```
14
14
 
15
- If you don't have `nvm`, you may manually install and use Node.js 22+.
15
+ If you don't have [nvm](https://github.com/nvm-sh/nvm), you may manually install and use Node.js 22+.
16
16
 
17
17
  Then, we have to use the proper package manager (here `yarn`):
18
18
 
@@ -35,6 +35,12 @@ yarn install
35
35
  ### Commands
36
36
 
37
37
  - `fb:build`: builds the library.
38
+ - converts the typescript files into javascript files, copies the scss files, and assembles all the assets to create a package ready to be published.
38
39
  - `fb:format`: formats the code using `prettier`.
39
40
  - `fb:test`: runs the tests using `vitest`.
40
- - `fb:dev`: builds the lib in `dev` mode, and publishes it on a local `verdaccio`.
41
+ - `fb:prod`: builds the lib in `prod` mode.
42
+ - builds and publishes the lib on npm as a _prod_ version.
43
+ - `fb:dev`: builds the lib in `dev` .
44
+ - builds and publishes the lib on a local `verdaccio` with a `dev` tag.
45
+ - `fb:rc`: builds the lib in `rc` mode, and publishes it on a local `verdaccio`.
46
+ - builds and publishes the lib on npm with a `rc` tag.
@@ -0,0 +1,12 @@
1
+ import { build } from './build.js';
2
+ import { publish } from './publish.js';
3
+
4
+ /**
5
+ * Builds the lib.
6
+ * @param {{ mode?: 'dev' | 'rc' | 'prod' }} options
7
+ * @return {Promise<void>}
8
+ */
9
+ export async function buildAndPublish(options) {
10
+ await build(options);
11
+ await publish(options);
12
+ }
@@ -4,10 +4,10 @@ import { cmd } from '../helpers/cmd.js';
4
4
 
5
5
  /**
6
6
  * Builds the lib.
7
- * @param {{ cwd?: string; dev?: boolean }} options
7
+ * @param {{ mode?: 'dev' | 'rc' | 'prod' }} options
8
8
  * @return {Promise<void>}
9
9
  */
10
- async function build({ dev = false } = {}) {
10
+ export async function build({ mode = 'prod' } = {}) {
11
11
  const rootPath = '.';
12
12
  const sourcePath = './src';
13
13
  const destinationPath = './dist';
@@ -22,7 +22,7 @@ async function build({ dev = false } = {}) {
22
22
  ]);
23
23
 
24
24
  await buildPackageJsonFile(destinationPath, {
25
- dev,
25
+ mode,
26
26
  withProtected,
27
27
  });
28
28
  } catch (error) {
@@ -103,7 +103,7 @@ async function buildTypescriptIndexFile(cwd = process.cwd()) {
103
103
  )
104
104
  )
105
105
  .map((path) => {
106
- return `export * from './${path.slice(0, -3)}.js';`;
106
+ return `export * from './${path.replaceAll('\\', '/').slice(0, -3)}.js';`;
107
107
  })
108
108
  .join('\n');
109
109
 
@@ -139,7 +139,7 @@ async function buildTypescriptProtectedIndexFile(cwd = process.cwd()) {
139
139
  )
140
140
  )
141
141
  .map((path) => {
142
- return `export * from './${path.slice(0, -3)}.js';`;
142
+ return `export * from './${path.replaceAll('\\', '/').slice(0, -3)}.js';`;
143
143
  })
144
144
  .join('\n');
145
145
 
@@ -304,12 +304,12 @@ async function removeTypescriptIndexFile(indexFilePath) {
304
304
  * Generates the package.json to publish.
305
305
  *
306
306
  * @param {string} destinationPath
307
- * @param {{ cwd?: string; dev?: boolean, withProtected?: boolean }} options
307
+ * @param {{ cwd?: string; mode?: 'dev' | 'rc' | 'prod', withProtected?: boolean }} options
308
308
  * @return {Promise<void>}
309
309
  */
310
310
  async function buildPackageJsonFile(
311
311
  destinationPath,
312
- { cwd = process.cwd(), dev = false, withProtected = false } = {},
312
+ { cwd = process.cwd(), mode = 'prod', withProtected = false } = {},
313
313
  ) {
314
314
  console.log('Building package.json...');
315
315
 
@@ -322,8 +322,8 @@ async function buildPackageJsonFile(
322
322
 
323
323
  const indexTypesPath = './index.d.ts';
324
324
 
325
- if (dev) {
326
- pkg.version += `-dev.${Date.now()}`;
325
+ if (mode !== 'prod') {
326
+ pkg.version += `-${mode}.${Date.now()}`;
327
327
  }
328
328
 
329
329
  Object.assign(pkg, {
@@ -347,9 +347,3 @@ async function buildPackageJsonFile(
347
347
 
348
348
  await writeFile(join(destinationPath, fileName), JSON.stringify(pkg, null, 2));
349
349
  }
350
-
351
- /*-----------------------------------*/
352
-
353
- const [dev = false] = process.argv.slice(2);
354
-
355
- build({ dev });
@@ -0,0 +1,14 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { buildAndPublish } from '../build-and-publish.js';
3
+
4
+ const { values } = parseArgs({
5
+ options: {
6
+ mode: {
7
+ type: 'string',
8
+ short: 'm',
9
+ default: 'prod',
10
+ },
11
+ },
12
+ });
13
+
14
+ buildAndPublish(values);
@@ -0,0 +1,14 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { build } from '../build.js';
3
+
4
+ const { values } = parseArgs({
5
+ options: {
6
+ mode: {
7
+ type: 'string',
8
+ short: 'm',
9
+ default: 'prod',
10
+ },
11
+ },
12
+ });
13
+
14
+ build(values);
@@ -0,0 +1,14 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { publish } from '../publish.js';
3
+
4
+ const { values } = parseArgs({
5
+ options: {
6
+ mode: {
7
+ type: 'string',
8
+ short: 'm',
9
+ default: 'prod',
10
+ },
11
+ },
12
+ });
13
+
14
+ publish(values);
@@ -0,0 +1,61 @@
1
+ import { join } from 'node:path';
2
+ import { cmd } from '../helpers/cmd.js';
3
+
4
+ /**
5
+ * Published the lib.
6
+ * @param {{ mode?: 'dev' | 'rc' | 'prod'; }} options
7
+ * @return {Promise<void>}
8
+ */
9
+ export async function publish({ mode = 'prod' } = {}) {
10
+ const packagePath = './dist';
11
+
12
+ console.log('Publishing library...');
13
+
14
+ /**
15
+ * @type {{
16
+ * quiet?: boolean;
17
+ * registry?: string;
18
+ * access?: 'public';
19
+ * tag?: string;
20
+ * }}
21
+ */
22
+ const options = {};
23
+
24
+ /**
25
+ * @type {string[]}
26
+ */
27
+ const args = ['publish'];
28
+
29
+ if (mode === 'dev') {
30
+ options.quiet = true;
31
+ options.registry = 'http://localhost:4873';
32
+ options.tag = 'dev';
33
+ } else {
34
+ options.registry = 'https://registry.npmjs.org';
35
+ options.access = 'public';
36
+
37
+ if (mode === 'rc') {
38
+ options.tag = 'rc';
39
+ }
40
+ }
41
+
42
+ if (options.quiet) {
43
+ args.push('--quiet');
44
+ }
45
+
46
+ if (options.registry) {
47
+ args.push('--registry', options.registry);
48
+ }
49
+
50
+ if (options.access) {
51
+ args.push('--access', options.access);
52
+ }
53
+
54
+ if (options.tag) {
55
+ args.push('--tag', options.tag);
56
+ }
57
+
58
+ await cmd('npm', args, { cwd: join(process.cwd(), packagePath) });
59
+
60
+ console.log('Library published with success !');
61
+ }
@@ -12,6 +12,7 @@ export async function cmd(command, args = [], options) {
12
12
 
13
13
  const childProcess = spawn(command, args, {
14
14
  cwd: process.cwd(),
15
+ shell: process.platform === 'win32',
15
16
  detached: false,
16
17
  stdio: 'inherit',
17
18
  ...options,
@@ -4,12 +4,13 @@
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "scripts": {
7
- "fb:build": "node fabrique/actions/build.js",
7
+ "fb:build": "node fabrique/actions/cli/build.cli.js",
8
8
  "fb:format": "prettier --write --ignore-unknown --config ./.prettierrc \"src/**/*.{js,jsx,ts,tsx,html,css,scss}\"",
9
9
  "fb:test": "vitest",
10
10
  "fb:test:coverage": "vitest run --coverage",
11
- "fb:prod": "node fabrique/actions/build.js && cd dist && npm publish --access public --registry https://registry.npmjs.org",
12
- "fb:dev": "node fabrique/actions/build.js --dev && cd dist && npm publish --quiet --registry http://localhost:4873"
11
+ "fb:prod": "node fabrique/actions/cli/build-and-publish.cli.js --mode prod",
12
+ "fb:dev": "node fabrique/actions/cli/build-and-publish.cli.js --mode dev",
13
+ "fb:rc": "node fabrique/actions/cli/build-and-publish.cli.js --mode rc"
13
14
  },
14
15
  "description": "{{description}}",
15
16
  "keywords": [],
@@ -21,10 +22,10 @@
21
22
  "url": "{{giturl}}"
22
23
  },
23
24
  "devDependencies": {
24
- "prettier": "^3.3.3",
25
+ "prettier": "^3.4.2",
25
26
  "prettier-plugin-organize-imports": "^4.1.0",
26
- "typescript": "^5.6.3",
27
- "vitest": "^2.1.4"
27
+ "typescript": "^5.7.2",
28
+ "vitest": "^2.1.8"
28
29
  },
29
- "packageManager": "yarn@4.5.1"
30
+ "packageManager": "yarn@4.6.0"
30
31
  }