@mondaydotcomorg/z2h-cli 0.24.1 → 0.24.2
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/dist/commands/create-workspace.d.ts.map +1 -1
- package/dist/commands/create-workspace.js +23 -25
- package/dist/esm/commands/create-workspace.d.ts.map +1 -1
- package/dist/esm/commands/create-workspace.mjs +26 -28
- package/package.json +1 -1
- package/src/commands/__tests__/create-workspace.test.ts +25 -4
- package/src/commands/create-workspace.ts +32 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../src/commands/create-workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../src/commands/create-workspace.ts"],"names":[],"mappings":"AAaA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAuC5D"}
|
|
@@ -13,37 +13,35 @@ const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
|
13
13
|
|
|
14
14
|
const path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
15
|
|
|
16
|
+
async function isPopulated(dir) {
|
|
17
|
+
return (await fs.pathExists(dir)) && (await fs.readdir(dir)).length > 0;
|
|
18
|
+
}
|
|
16
19
|
async function createWorkspaceCommand() {
|
|
17
20
|
const home = util_workspace.getWorkspaceHome();
|
|
18
21
|
const templatesDir = util_templates.getTemplatesDir();
|
|
19
22
|
const wsTemplatesDir = path__default.default.join(templatesDir, 'workspace');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
await fs.ensureDir(home);
|
|
24
|
+
const scaffolded = await util_workspace.isZ2hWorkspace(home);
|
|
25
|
+
if (!scaffolded) {
|
|
26
|
+
util_logger.info(`setting up your Z2H workspace`);
|
|
27
|
+
const pkgRaw = await promises.readFile(path__default.default.join(wsTemplatesDir, 'package.json.tmpl'), 'utf8');
|
|
28
|
+
await Promise.all([
|
|
29
|
+
fs.writeFile(path__default.default.join(home, 'package.json'), pkgRaw),
|
|
30
|
+
fs.copy(path__default.default.join(wsTemplatesDir, 'gitignore'), path__default.default.join(home, '.gitignore')),
|
|
31
|
+
fs.writeFile(path__default.default.join(home, '.yarnrc.yml'), util_npm_brokerConfig.workspaceYarnrcContents()),
|
|
32
|
+
fs.copy(path__default.default.join(wsTemplatesDir, 'nx.json'), path__default.default.join(home, 'nx.json')),
|
|
33
|
+
fs.copy(path__default.default.join(wsTemplatesDir, 'yarnlock'), path__default.default.join(home, 'yarn.lock')),
|
|
34
|
+
fs.copy(path__default.default.join(wsTemplatesDir, 'nvmrc'), path__default.default.join(home, '.nvmrc')),
|
|
35
|
+
fs.writeFile(path__default.default.join(home, '.npmrc'), util_npm_brokerConfig.workspaceNpmrcContents()),
|
|
36
|
+
fs.copy(path__default.default.join(wsTemplatesDir, 'README.md'), path__default.default.join(home, 'README.md')),
|
|
37
|
+
fs.copy(path__default.default.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'), path__default.default.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')),
|
|
38
|
+
]);
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const hasWorkspaceNodeModules = await isPopulated(path__default.default.join(home, 'node_modules'));
|
|
41
|
+
if (!scaffolded || !hasWorkspaceNodeModules) {
|
|
42
|
+
util_logger.info(`installing workspace dependencies — this may take a minute`);
|
|
43
|
+
await util_npm_install.runYarnInstall({ cwd: home });
|
|
32
44
|
}
|
|
33
|
-
const pkgRaw = await promises.readFile(path__default.default.join(wsTemplatesDir, 'package.json.tmpl'), 'utf8');
|
|
34
|
-
await Promise.all([
|
|
35
|
-
fs.writeFile(path__default.default.join(home, 'package.json'), pkgRaw),
|
|
36
|
-
fs.copy(path__default.default.join(wsTemplatesDir, 'gitignore'), path__default.default.join(home, '.gitignore')),
|
|
37
|
-
fs.writeFile(path__default.default.join(home, '.yarnrc.yml'), util_npm_brokerConfig.workspaceYarnrcContents()),
|
|
38
|
-
fs.copy(path__default.default.join(wsTemplatesDir, 'nx.json'), path__default.default.join(home, 'nx.json')),
|
|
39
|
-
fs.copy(path__default.default.join(wsTemplatesDir, 'yarnlock'), path__default.default.join(home, 'yarn.lock')),
|
|
40
|
-
fs.copy(path__default.default.join(wsTemplatesDir, 'nvmrc'), path__default.default.join(home, '.nvmrc')),
|
|
41
|
-
fs.writeFile(path__default.default.join(home, '.npmrc'), util_npm_brokerConfig.workspaceNpmrcContents()),
|
|
42
|
-
fs.copy(path__default.default.join(wsTemplatesDir, 'README.md'), path__default.default.join(home, 'README.md')),
|
|
43
|
-
fs.copy(path__default.default.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'), path__default.default.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')),
|
|
44
|
-
]);
|
|
45
|
-
util_logger.info(`setting up your Z2H workspace — this may take a minute...`);
|
|
46
|
-
await util_npm_install.runYarnInstall({ cwd: home });
|
|
47
45
|
util_logger.output(`Your workspace is ready! 🚀 Apps will live at ${home}`, {
|
|
48
46
|
ok: true,
|
|
49
47
|
workspace: home,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../src/commands/create-workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../src/commands/create-workspace.ts"],"names":[],"mappings":"AAaA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAuC5D"}
|
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getWorkspaceHome } from '../util/workspace.mjs';
|
|
3
|
+
import { ensureDir, writeFile, copy, pathExists, readdir } from 'fs-extra';
|
|
4
|
+
import { info, output } from '../util/logger.mjs';
|
|
5
|
+
import { getWorkspaceHome, isZ2hWorkspace } from '../util/workspace.mjs';
|
|
6
6
|
import { getTemplatesDir } from '../util/templates.mjs';
|
|
7
7
|
import { runYarnInstall } from '../util/npm/install.mjs';
|
|
8
8
|
import { workspaceYarnrcContents, workspaceNpmrcContents } from '../util/npm/broker-config.mjs';
|
|
9
9
|
|
|
10
|
+
async function isPopulated(dir) {
|
|
11
|
+
return (await pathExists(dir)) && (await readdir(dir)).length > 0;
|
|
12
|
+
}
|
|
10
13
|
async function createWorkspaceCommand() {
|
|
11
14
|
const home = getWorkspaceHome();
|
|
12
15
|
const templatesDir = getTemplatesDir();
|
|
13
16
|
const wsTemplatesDir = path.join(templatesDir, 'workspace');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
await ensureDir(home);
|
|
18
|
+
const scaffolded = await isZ2hWorkspace(home);
|
|
19
|
+
if (!scaffolded) {
|
|
20
|
+
info(`setting up your Z2H workspace`);
|
|
21
|
+
const pkgRaw = await readFile(path.join(wsTemplatesDir, 'package.json.tmpl'), 'utf8');
|
|
22
|
+
await Promise.all([
|
|
23
|
+
writeFile(path.join(home, 'package.json'), pkgRaw),
|
|
24
|
+
copy(path.join(wsTemplatesDir, 'gitignore'), path.join(home, '.gitignore')),
|
|
25
|
+
writeFile(path.join(home, '.yarnrc.yml'), workspaceYarnrcContents()),
|
|
26
|
+
copy(path.join(wsTemplatesDir, 'nx.json'), path.join(home, 'nx.json')),
|
|
27
|
+
copy(path.join(wsTemplatesDir, 'yarnlock'), path.join(home, 'yarn.lock')),
|
|
28
|
+
copy(path.join(wsTemplatesDir, 'nvmrc'), path.join(home, '.nvmrc')),
|
|
29
|
+
writeFile(path.join(home, '.npmrc'), workspaceNpmrcContents()),
|
|
30
|
+
copy(path.join(wsTemplatesDir, 'README.md'), path.join(home, 'README.md')),
|
|
31
|
+
copy(path.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'), path.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')),
|
|
32
|
+
]);
|
|
23
33
|
}
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
const hasWorkspaceNodeModules = await isPopulated(path.join(home, 'node_modules'));
|
|
35
|
+
if (!scaffolded || !hasWorkspaceNodeModules) {
|
|
36
|
+
info(`installing workspace dependencies — this may take a minute`);
|
|
37
|
+
await runYarnInstall({ cwd: home });
|
|
26
38
|
}
|
|
27
|
-
const pkgRaw = await readFile(path.join(wsTemplatesDir, 'package.json.tmpl'), 'utf8');
|
|
28
|
-
await Promise.all([
|
|
29
|
-
writeFile(path.join(home, 'package.json'), pkgRaw),
|
|
30
|
-
copy(path.join(wsTemplatesDir, 'gitignore'), path.join(home, '.gitignore')),
|
|
31
|
-
writeFile(path.join(home, '.yarnrc.yml'), workspaceYarnrcContents()),
|
|
32
|
-
copy(path.join(wsTemplatesDir, 'nx.json'), path.join(home, 'nx.json')),
|
|
33
|
-
copy(path.join(wsTemplatesDir, 'yarnlock'), path.join(home, 'yarn.lock')),
|
|
34
|
-
copy(path.join(wsTemplatesDir, 'nvmrc'), path.join(home, '.nvmrc')),
|
|
35
|
-
writeFile(path.join(home, '.npmrc'), workspaceNpmrcContents()),
|
|
36
|
-
copy(path.join(wsTemplatesDir, 'README.md'), path.join(home, 'README.md')),
|
|
37
|
-
copy(path.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'), path.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')),
|
|
38
|
-
]);
|
|
39
|
-
info(`setting up your Z2H workspace — this may take a minute...`);
|
|
40
|
-
await runYarnInstall({ cwd: home });
|
|
41
39
|
output(`Your workspace is ready! 🚀 Apps will live at ${home}`, {
|
|
42
40
|
ok: true,
|
|
43
41
|
workspace: home,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
-
import { mkdtemp, rm,
|
|
3
|
+
import { mkdtemp, rm, outputJson, readJson, ensureDir, pathExists } from 'fs-extra';
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
6
|
import { runYarnInstall } from '../../util/npm/install';
|
|
@@ -51,14 +51,35 @@ describe('create-workspace', () => {
|
|
|
51
51
|
expect(runYarnInstall).toHaveBeenCalledWith(expect.objectContaining({ cwd: tmp }));
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it('
|
|
54
|
+
it('scaffolds and installs even if the target dir has unrelated files (e.g. a mounted empty node_modules)', async () => {
|
|
55
55
|
await ensureDir(tmp);
|
|
56
|
-
await
|
|
56
|
+
await ensureDir(path.join(tmp, 'node_modules'));
|
|
57
|
+
|
|
58
|
+
await createWorkspaceCommand();
|
|
59
|
+
|
|
60
|
+
expect(await pathExists(path.join(tmp, 'package.json'))).toBe(true);
|
|
61
|
+
expect(runYarnInstall).toHaveBeenCalledWith(expect.objectContaining({ cwd: tmp }));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('skips install if package.json exists and node_modules is populated', async () => {
|
|
65
|
+
await createWorkspaceCommand();
|
|
66
|
+
vi.mocked(runYarnInstall).mockClear();
|
|
67
|
+
await outputJson(path.join(tmp, 'node_modules', 'some-dep', 'package.json'), { name: 'some-dep' });
|
|
68
|
+
|
|
69
|
+
await createWorkspaceCommand();
|
|
57
70
|
|
|
58
|
-
await expect(createWorkspaceCommand()).resolves.toBeUndefined();
|
|
59
71
|
expect(runYarnInstall).not.toHaveBeenCalled();
|
|
60
72
|
});
|
|
61
73
|
|
|
74
|
+
it('reinstalls if package.json exists but node_modules is empty (e.g. wiped by an ephemeral mount)', async () => {
|
|
75
|
+
await createWorkspaceCommand();
|
|
76
|
+
vi.mocked(runYarnInstall).mockClear();
|
|
77
|
+
|
|
78
|
+
await createWorkspaceCommand();
|
|
79
|
+
|
|
80
|
+
expect(runYarnInstall).toHaveBeenCalledWith(expect.objectContaining({ cwd: tmp }));
|
|
81
|
+
});
|
|
82
|
+
|
|
62
83
|
it('does not include z2h-cli in workspace devDeps (managed globally)', async () => {
|
|
63
84
|
await createWorkspaceCommand();
|
|
64
85
|
|
|
@@ -2,48 +2,49 @@ import path from 'node:path';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { ensureDir, writeFile, pathExists, readdir, copy } from 'fs-extra';
|
|
4
4
|
import { info, output } from '../util/logger';
|
|
5
|
-
import { getWorkspaceHome } from '../util/workspace';
|
|
5
|
+
import { getWorkspaceHome, isZ2hWorkspace } from '../util/workspace';
|
|
6
6
|
import { getTemplatesDir } from '../util/templates';
|
|
7
7
|
import { runYarnInstall } from '../util/npm/install';
|
|
8
8
|
import { workspaceNpmrcContents, workspaceYarnrcContents } from '../util/npm/broker-config';
|
|
9
9
|
|
|
10
|
+
async function isPopulated(dir: string): Promise<boolean> {
|
|
11
|
+
return (await pathExists(dir)) && (await readdir(dir)).length > 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
export async function createWorkspaceCommand(): Promise<void> {
|
|
11
15
|
const home = getWorkspaceHome();
|
|
12
16
|
const templatesDir = getTemplatesDir();
|
|
13
17
|
const wsTemplatesDir = path.join(templatesDir, 'workspace');
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
await ensureDir(home);
|
|
20
|
+
|
|
21
|
+
const scaffolded = await isZ2hWorkspace(home);
|
|
22
|
+
|
|
23
|
+
if (!scaffolded) {
|
|
24
|
+
info(`setting up your Z2H workspace`);
|
|
25
|
+
const pkgRaw = await readFile(path.join(wsTemplatesDir, 'package.json.tmpl'), 'utf8');
|
|
26
|
+
|
|
27
|
+
await Promise.all([
|
|
28
|
+
writeFile(path.join(home, 'package.json'), pkgRaw),
|
|
29
|
+
copy(path.join(wsTemplatesDir, 'gitignore'), path.join(home, '.gitignore')),
|
|
30
|
+
writeFile(path.join(home, '.yarnrc.yml'), workspaceYarnrcContents()),
|
|
31
|
+
copy(path.join(wsTemplatesDir, 'nx.json'), path.join(home, 'nx.json')),
|
|
32
|
+
copy(path.join(wsTemplatesDir, 'yarnlock'), path.join(home, 'yarn.lock')),
|
|
33
|
+
copy(path.join(wsTemplatesDir, 'nvmrc'), path.join(home, '.nvmrc')),
|
|
34
|
+
writeFile(path.join(home, '.npmrc'), workspaceNpmrcContents()),
|
|
35
|
+
copy(path.join(wsTemplatesDir, 'README.md'), path.join(home, 'README.md')),
|
|
36
|
+
copy(
|
|
37
|
+
path.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'),
|
|
38
|
+
path.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')
|
|
39
|
+
),
|
|
40
|
+
]);
|
|
26
41
|
}
|
|
27
42
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
writeFile(path.join(home, '.yarnrc.yml'), workspaceYarnrcContents()),
|
|
34
|
-
copy(path.join(wsTemplatesDir, 'nx.json'), path.join(home, 'nx.json')),
|
|
35
|
-
copy(path.join(wsTemplatesDir, 'yarnlock'), path.join(home, 'yarn.lock')),
|
|
36
|
-
copy(path.join(wsTemplatesDir, 'nvmrc'), path.join(home, '.nvmrc')),
|
|
37
|
-
writeFile(path.join(home, '.npmrc'), workspaceNpmrcContents()),
|
|
38
|
-
copy(path.join(wsTemplatesDir, 'README.md'), path.join(home, 'README.md')),
|
|
39
|
-
copy(
|
|
40
|
-
path.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'),
|
|
41
|
-
path.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')
|
|
42
|
-
),
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
info(`setting up your Z2H workspace — this may take a minute...`);
|
|
46
|
-
await runYarnInstall({ cwd: home });
|
|
43
|
+
const hasWorkspaceNodeModules = await isPopulated(path.join(home, 'node_modules'));
|
|
44
|
+
if (!scaffolded || !hasWorkspaceNodeModules) {
|
|
45
|
+
info(`installing workspace dependencies — this may take a minute`);
|
|
46
|
+
await runYarnInstall({ cwd: home });
|
|
47
|
+
}
|
|
47
48
|
|
|
48
49
|
output(`Your workspace is ready! 🚀 Apps will live at ${home}`, {
|
|
49
50
|
ok: true,
|