fabrique 0.2.0 → 0.2.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/.yarn/releases/yarn-4.6.0.cjs +934 -0
- package/.yarnrc.yml +2 -0
- package/README.md +2 -2
- package/package.json +7 -7
- package/src/actions/upgrade.js +1 -1
- package/templates/lib/.yarn/releases/yarn-4.6.0.cjs +934 -0
- package/templates/lib/.yarnrc.yml +2 -0
- package/templates/lib/CONTRIBUTING.md +7 -1
- package/templates/lib/fabrique/actions/build-and-publish.js +12 -0
- package/templates/lib/fabrique/actions/build.js +93 -58
- package/templates/lib/fabrique/actions/cli/build-and-publish.cli.js +14 -0
- package/templates/lib/fabrique/actions/cli/build.cli.js +14 -0
- package/templates/lib/fabrique/actions/cli/publish.cli.js +14 -0
- package/templates/lib/fabrique/actions/publish.js +61 -0
- package/templates/lib/fabrique/helpers/cmd.js +1 -0
- package/templates/lib/fabrique/helpers/explore-directory.js +30 -0
- package/templates/lib/package.json +8 -7
- package/templates/lib/yarn.lock +1734 -0
|
@@ -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:
|
|
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
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { cp,
|
|
1
|
+
import { cp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { isAbsolute, join } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
3
4
|
import { cmd } from '../helpers/cmd.js';
|
|
5
|
+
import { exploreDirectoryFiles } from '../helpers/explore-directory.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Builds the lib.
|
|
7
|
-
* @param {{
|
|
9
|
+
* @param {{ mode?: 'dev' | 'rc' | 'prod' }} options
|
|
8
10
|
* @return {Promise<void>}
|
|
9
11
|
*/
|
|
10
|
-
async function build({
|
|
12
|
+
export async function build({ mode = 'prod' } = {}) {
|
|
11
13
|
const rootPath = '.';
|
|
12
14
|
const sourcePath = './src';
|
|
13
15
|
const destinationPath = './dist';
|
|
@@ -22,7 +24,7 @@ async function build({ dev = false } = {}) {
|
|
|
22
24
|
]);
|
|
23
25
|
|
|
24
26
|
await buildPackageJsonFile(destinationPath, {
|
|
25
|
-
|
|
27
|
+
mode,
|
|
26
28
|
withProtected,
|
|
27
29
|
});
|
|
28
30
|
} catch (error) {
|
|
@@ -78,6 +80,10 @@ async function buildScss(sourcePath, destinationPath) {
|
|
|
78
80
|
await buildScssIndexFile(destinationPath);
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
function generateExportEsmLine(path) {
|
|
84
|
+
return `export * from './${path.replaceAll('\\', '/').slice(0, -3)}.js';\n`;
|
|
85
|
+
}
|
|
86
|
+
|
|
81
87
|
/**
|
|
82
88
|
* Builds the typescript index file used to export all public APIs.
|
|
83
89
|
*
|
|
@@ -87,25 +93,26 @@ async function buildScss(sourcePath, destinationPath) {
|
|
|
87
93
|
async function buildTypescriptIndexFile(cwd = process.cwd()) {
|
|
88
94
|
console.log('Building typescript index file...');
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
let content = '';
|
|
97
|
+
|
|
98
|
+
for await (const path of exploreDirectoryFiles(cwd, {
|
|
99
|
+
relativeTo: cwd,
|
|
100
|
+
pick: (path, { isFile }) => {
|
|
101
|
+
if (isFile) {
|
|
102
|
+
return (
|
|
103
|
+
path.endsWith('.ts') &&
|
|
104
|
+
!path.endsWith('.spec.ts') &&
|
|
105
|
+
!path.endsWith('.test.ts') &&
|
|
106
|
+
!path.endsWith('.private.ts') &&
|
|
107
|
+
!path.endsWith('.protected.ts')
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
return !path.endsWith('.private') && !path.endsWith('.protected');
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
})) {
|
|
114
|
+
content += generateExportEsmLine(path);
|
|
115
|
+
}
|
|
109
116
|
|
|
110
117
|
if (content === '') {
|
|
111
118
|
throw new Error('Nothing exported.');
|
|
@@ -126,22 +133,22 @@ async function buildTypescriptIndexFile(cwd = process.cwd()) {
|
|
|
126
133
|
async function buildTypescriptProtectedIndexFile(cwd = process.cwd()) {
|
|
127
134
|
console.log('Building typescript protected index file...');
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
let content = '';
|
|
137
|
+
|
|
138
|
+
for await (const path of exploreDirectoryFiles(cwd, {
|
|
139
|
+
relativeTo: cwd,
|
|
140
|
+
pick: (path, { isFile }) => {
|
|
141
|
+
if (isFile) {
|
|
142
|
+
return (
|
|
143
|
+
path.endsWith('.protected.ts') || (path.endsWith('.ts') && path.includes('.protected/'))
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
return !path.endsWith('.private');
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
})) {
|
|
150
|
+
content += generateExportEsmLine(path);
|
|
151
|
+
}
|
|
145
152
|
|
|
146
153
|
if (content === '') {
|
|
147
154
|
return null;
|
|
@@ -175,13 +182,26 @@ async function compileTypescript(cwd = process.cwd()) {
|
|
|
175
182
|
async function copyTypescriptFiles(sourcePath, destinationPath) {
|
|
176
183
|
console.log('Copying typescript files...');
|
|
177
184
|
|
|
178
|
-
for await (const path of
|
|
185
|
+
for await (const path of exploreDirectoryFiles(sourcePath, {
|
|
186
|
+
relativeTo: sourcePath,
|
|
187
|
+
pick: (path, { isFile }) => {
|
|
188
|
+
if (isFile) {
|
|
189
|
+
return path.endsWith('.ts') && !path.endsWith('.spec.ts') && !path.endsWith('.test.ts');
|
|
190
|
+
} else {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
})) {
|
|
179
195
|
await cp(join(sourcePath, path), join(destinationPath, path));
|
|
180
196
|
}
|
|
181
197
|
}
|
|
182
198
|
|
|
199
|
+
function generateExportScssLine(path) {
|
|
200
|
+
return `@forward './${path.slice(0, -5)}';\n`;
|
|
201
|
+
}
|
|
202
|
+
|
|
183
203
|
/**
|
|
184
|
-
* Builds the
|
|
204
|
+
* Builds the scss index file used to export all public styles.
|
|
185
205
|
*
|
|
186
206
|
* @param {string} cwd
|
|
187
207
|
* @return {Promise<void>}
|
|
@@ -189,12 +209,24 @@ async function copyTypescriptFiles(sourcePath, destinationPath) {
|
|
|
189
209
|
async function buildScssIndexFile(cwd = process.cwd()) {
|
|
190
210
|
console.log('Building scss index file...');
|
|
191
211
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
})
|
|
197
|
-
|
|
212
|
+
let content = '';
|
|
213
|
+
|
|
214
|
+
for await (const path of exploreDirectoryFiles(cwd, {
|
|
215
|
+
relativeTo: cwd,
|
|
216
|
+
pick: (path, { isFile }) => {
|
|
217
|
+
if (isFile) {
|
|
218
|
+
return (
|
|
219
|
+
path.endsWith('.scss') &&
|
|
220
|
+
!path.endsWith('.protected.scss') &&
|
|
221
|
+
!path.endsWith('.private.scss')
|
|
222
|
+
);
|
|
223
|
+
} else {
|
|
224
|
+
return !path.endsWith('.private') && !path.endsWith('.protected');
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
})) {
|
|
228
|
+
content += generateExportScssLine(path);
|
|
229
|
+
}
|
|
198
230
|
|
|
199
231
|
if (content === '') {
|
|
200
232
|
console.log('=> No scss file to export.');
|
|
@@ -214,7 +246,16 @@ async function buildScssIndexFile(cwd = process.cwd()) {
|
|
|
214
246
|
async function copyScssFiles(sourcePath, destinationPath) {
|
|
215
247
|
console.log('Copying scss files...');
|
|
216
248
|
|
|
217
|
-
for await (const path of
|
|
249
|
+
for await (const path of exploreDirectoryFiles(sourcePath, {
|
|
250
|
+
relativeTo: sourcePath,
|
|
251
|
+
pick: (path, { isFile }) => {
|
|
252
|
+
if (isFile) {
|
|
253
|
+
return path.endsWith('.scss');
|
|
254
|
+
} else {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
})) {
|
|
218
259
|
// await cp(join(sourcePath, path), join(destinationPath, path));
|
|
219
260
|
await writeFile(
|
|
220
261
|
join(destinationPath, path),
|
|
@@ -304,12 +345,12 @@ async function removeTypescriptIndexFile(indexFilePath) {
|
|
|
304
345
|
* Generates the package.json to publish.
|
|
305
346
|
*
|
|
306
347
|
* @param {string} destinationPath
|
|
307
|
-
* @param {{ cwd?: string;
|
|
348
|
+
* @param {{ cwd?: string; mode?: 'dev' | 'rc' | 'prod', withProtected?: boolean }} options
|
|
308
349
|
* @return {Promise<void>}
|
|
309
350
|
*/
|
|
310
351
|
async function buildPackageJsonFile(
|
|
311
352
|
destinationPath,
|
|
312
|
-
{ cwd = process.cwd(),
|
|
353
|
+
{ cwd = process.cwd(), mode = 'prod', withProtected = false } = {},
|
|
313
354
|
) {
|
|
314
355
|
console.log('Building package.json...');
|
|
315
356
|
|
|
@@ -322,8 +363,8 @@ async function buildPackageJsonFile(
|
|
|
322
363
|
|
|
323
364
|
const indexTypesPath = './index.d.ts';
|
|
324
365
|
|
|
325
|
-
if (
|
|
326
|
-
pkg.version +=
|
|
366
|
+
if (mode !== 'prod') {
|
|
367
|
+
pkg.version += `-${mode}.${Date.now()}`;
|
|
327
368
|
}
|
|
328
369
|
|
|
329
370
|
Object.assign(pkg, {
|
|
@@ -347,9 +388,3 @@ async function buildPackageJsonFile(
|
|
|
347
388
|
|
|
348
389
|
await writeFile(join(destinationPath, fileName), JSON.stringify(pkg, null, 2));
|
|
349
390
|
}
|
|
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,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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { opendir } from 'node:fs/promises';
|
|
2
|
+
import { join, relative, resolve } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Runs "command" into the terminal.
|
|
7
|
+
* @param {string} path
|
|
8
|
+
* @param {{relativeTo?: string; pick?: (path: string, type: { isFile: boolean; isDirectory: boolean; }) => boolean; }?} options
|
|
9
|
+
* @return {Generator<string>}
|
|
10
|
+
*/
|
|
11
|
+
export async function* exploreDirectoryFiles(path, options) {
|
|
12
|
+
const dir = await opendir(resolve(process.cwd(), path));
|
|
13
|
+
|
|
14
|
+
for await (const dirent of dir) {
|
|
15
|
+
const path = join(dirent.parentPath, dirent.name);
|
|
16
|
+
const relativePath =
|
|
17
|
+
options?.relativeTo === undefined ? path : relative(options.relativeTo, path);
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
options?.pick(relativePath, { isFile: dirent.isFile(), isDirectory: dirent.isDirectory() }) ??
|
|
21
|
+
true
|
|
22
|
+
) {
|
|
23
|
+
if (dirent.isFile()) {
|
|
24
|
+
yield relativePath;
|
|
25
|
+
} else if (dirent.isDirectory()) {
|
|
26
|
+
yield* exploreDirectoryFiles(path, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -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
|
|
12
|
-
"fb:dev": "node fabrique/actions/build.js --dev
|
|
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.
|
|
25
|
+
"prettier": "^3.4.2",
|
|
25
26
|
"prettier-plugin-organize-imports": "^4.1.0",
|
|
26
|
-
"typescript": "^5.
|
|
27
|
-
"vitest": "^2.1.
|
|
27
|
+
"typescript": "^5.7.2",
|
|
28
|
+
"vitest": "^2.1.8"
|
|
28
29
|
},
|
|
29
|
-
"packageManager": "yarn@4.
|
|
30
|
+
"packageManager": "yarn@4.6.0"
|
|
30
31
|
}
|