Skip to content

Commit d7ff9ce

Browse files
authored
Merge pull request #113 from DataDog/yoann/dev-mode
[dx] Add dev mode
2 parents 811f453 + e4a63d0 commit d7ff9ce

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"build:all": "yarn loop run build",
2222
"clean:all": "yarn loop run clean",
2323
"cli": "yarn workspace @dd/tools cli",
24+
"dev": "yarn cli prepare-link && yarn watch:all; yarn cli prepare-link --revert",
2425
"format": "yarn lint --fix",
2526
"lint": "eslint ./packages/**/*.{ts,js} --quiet",
2627
"loop": "yarn workspaces foreach -Apti --include \"@datadog/*\" --exclude \"@datadog/build-plugins\"",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
import { Command, Option } from 'clipanion';
6+
import fs from 'fs';
7+
import path from 'path';
8+
9+
class PrepareLink extends Command {
10+
static paths = [['prepare-link']];
11+
12+
static usage = Command.Usage({
13+
category: `Contribution`,
14+
description: `Prepare our published packages to be linked from another project.`,
15+
details: `
16+
This command will change the package.json values of "exports" so they can be used from another project.
17+
18+
This is necessary to be sure that the outside project loads the built files and not the dev files.
19+
`,
20+
examples: [
21+
[`Prepare for link`, `$0 prepare-link`],
22+
[`Revert change`, `$0 prepare-link --revert`],
23+
],
24+
});
25+
26+
revert = Option.Boolean('--revert', {
27+
description: 'Revert the changes.',
28+
});
29+
30+
async execute() {
31+
const { getWorkspaces, green, red } = await import('@dd/tools/helpers');
32+
const { ROOT } = await import('@dd/tools/constants');
33+
34+
const workspaces = await getWorkspaces();
35+
36+
// Only get the published packages.
37+
const publishedPackages = workspaces.filter((workspace) =>
38+
workspace.name.match(/^@datadog\/.*-plugin$/),
39+
);
40+
41+
try {
42+
for (const pkg of publishedPackages) {
43+
const pkgJsonPath = path.resolve(ROOT, pkg.location, 'package.json');
44+
const pkgJson = require(pkgJsonPath);
45+
if (this.revert) {
46+
pkgJson.exports = { '.': './src/index.ts' };
47+
} else {
48+
pkgJson.exports = pkgJson.publishConfig.exports;
49+
}
50+
51+
fs.writeFileSync(pkgJsonPath, `${JSON.stringify(pkgJson, null, 4)}\n`);
52+
}
53+
54+
console.log(
55+
green(
56+
`All packages have been ${this.revert ? 'restored from linking.' : 'prepared for linking.'}`,
57+
),
58+
);
59+
} catch (error: any) {
60+
console.error(red(error));
61+
}
62+
}
63+
}
64+
65+
export default [PrepareLink];

0 commit comments

Comments
 (0)