-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.js
107 lines (93 loc) · 2.83 KB
/
publish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const simpleGit = require("simple-git/promise");
const shell = require("shelljs");
const fs = require("fs");
const rimraf = require("rimraf");
const path = require("path");
const { fullVersion } = require("./versions");
const { ignorePackages } = require("./packageList");
const assert = require("assert");
const editJsonFile = require("edit-json-file");
const newdepList = require("./dependenciesList");
const {
gitClonedPath,
cssnanoPath,
cssnanoRepoLink,
nightlyRepo,
registry,
version
} = require("./config");
shell.config.fatal = true;
const ignore = new Set(ignorePackages);
module.exports = async function run(registryUrl = registry) {
const git = simpleGit(gitClonedPath);
if (fs.existsSync(cssnanoPath)) {
await rimraf.sync(cssnanoPath);
}
await git.clone(cssnanoRepoLink);
await shell.cd("cssnano");
assert.strictEqual(
/**
* TODO: remove this when this script is being hosted and change it to
* shell.ls().length, 15
*/
![15, 16].includes(shell.ls().length),
false,
"Something wrong with the project root folder's count. Please re-check" +
" got " +
shell.ls().length +
" projects instead of 15"
);
const packagesList = shell.ls("packages/");
const packagePath = cssnanoPath + "/packages";
packagesList.forEach(pkg => {
if (ignore.has(pkg)) {
rimraf.sync(path.resolve(packagePath, pkg));
}
});
assert.strictEqual(
shell.ls("packages/").length + ignorePackages.length,
42,
"Something wrong while deleting ignored + deprecated package. Expected 42 but got " +
parseInt(shell.ls("packages/").length + ignorePackages.length)
);
try {
shell.exec("yarn install");
shell.exec("yarn test:only");
shell.exec("npx lerna link");
shell.exec("yarn build:packages");
} catch (error) {
throw new Error(error);
}
/**
* Publish script here,
*/
packagesList.forEach(async pkg => {
if (ignore.has(pkg)) {
rimraf.sync(path.resolve(packagePath, pkg));
return;
}
const pkgPath = cssnanoPath + "/packages/" + pkg;
if (fs.existsSync(pkgPath + "/dist")) {
shell.cd(pkgPath);
let packageJson = editJsonFile(`${pkgPath}/package.json`);
packageJson.set("scripts.prepublish", "");
packageJson.set("scripts.prebuild", "");
packageJson.set("version", `${version}-nightly.${fullVersion}`);
// packageJson.set("publishConfig.registry", registryUrl);
if (newdepList[pkg]) {
packageJson.set("dependencies", {
...packageJson.get("dependencies"),
...newdepList[pkg]
});
}
packageJson.save();
shell.cp("-R", __dirname + "/.npmrc", pkgPath);
try {
console.log("publishing ", pkg);
shell.exec("npm publish --tag nightly");
} catch (error) {
throw new Error(error);
}
}
});
};