propagate-cli 1.10.12 → 1.11.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.
@@ -8,7 +8,7 @@ export function migrateConfigurationToVersion_1_9(configuration) {
8
8
 
9
9
  let { shellCommands } = configuration;
10
10
 
11
- const install = DEFAULT_INSTALL_SHELL_COMMANDS; ///
11
+ const install = DEFAULT_INSTALL_SHELL_COMMANDS;
12
12
 
13
13
  shellCommands = Object.assign(shellCommands, {
14
14
  install
@@ -3,13 +3,14 @@
3
3
  import { versionUtilities, configurationUtilities } from "necessary";
4
4
 
5
5
  import { PROPAGATE } from "./constants";
6
- import { createConfiguration } from "./configuration/version_1_10";
6
+ import { createConfiguration } from "./configuration/version_1_11";
7
7
  import { migrateConfigurationToVersion_1_3 } from "./configuration/version_1_3";
8
8
  import { migrateConfigurationToVersion_1_7 } from "./configuration/version_1_7";
9
9
  import { migrateConfigurationToVersion_1_9 } from "./configuration/version_1_9";
10
10
  import { migrateConfigurationToVersion_1_10 } from "./configuration/version_1_10";
11
+ import { migrateConfigurationToVersion_1_11 } from "./configuration/version_1_11";
11
12
  import { CONFIGURATION_FILE_DOES_NOT_EXIST_MESSAGE } from "./messages";
12
- import { VERSION_1_0, VERSION_1_3, VERSION_1_7, VERSION_1_9, VERSION_1_10 } from "./versions";
13
+ import { VERSION_1_0, VERSION_1_3, VERSION_1_7, VERSION_1_9, VERSION_1_10, VERSION_1_11 } from "./versions";
13
14
 
14
15
  const { rc } = configurationUtilities,
15
16
  { migrate } = versionUtilities,
@@ -99,9 +100,10 @@ export function migrateConfigurationFile() {
99
100
  [ VERSION_1_0 ]: migrateConfigurationToVersion_1_3,
100
101
  [ VERSION_1_3 ]: migrateConfigurationToVersion_1_7,
101
102
  [ VERSION_1_7 ] :migrateConfigurationToVersion_1_9,
102
- [ VERSION_1_9 ] :migrateConfigurationToVersion_1_10
103
+ [ VERSION_1_9 ] :migrateConfigurationToVersion_1_10,
104
+ [ VERSION_1_10 ] :migrateConfigurationToVersion_1_11
103
105
  },
104
- latestVersion = VERSION_1_10;
106
+ latestVersion = VERSION_1_11;
105
107
 
106
108
  json = migrate(json, migrationMap, latestVersion);
107
109
 
package/src/constants.js CHANGED
@@ -7,4 +7,7 @@ export const EMPTY_STRING = "";
7
7
  export const PACKAGE_JSON = "package.json";
8
8
  export const DEPENDENCIES = "dependencies";
9
9
  export const PROPAGATE_CLI = "Propagate-CLI";
10
+ export const REPEATED_DELAY = 3000;
11
+ export const PROMPT_ATTEMPTS = Infinity;
10
12
  export const DEV_DEPENDENCIES = "devDependencies";
13
+ export const REPEATED_ATTEMPTS = 10;
package/src/defaults.js CHANGED
@@ -7,6 +7,7 @@ export const DEFAULT_DRY_RUN = false;
7
7
  export const DEFAULT_QUIETLY = false;
8
8
  export const DEFAULT_DIRECTORY_NAME = ".";
9
9
  export const DEFAULT_GIT_SHELL_COMMANDS = "git add .; git commit -m \"Propagated.\"; git push";
10
+ export const DEFAULT_POLL_SHELL_COMMANDS = "npm view ${dependency} version";
10
11
  export const DEFAULT_BUILD_SHELL_COMMANDS = "npm run build";
11
12
  export const DEFAULT_INSTALL_SHELL_COMMANDS = "npm install";
12
13
  export const DEFAULT_PUBLISH_SHELL_COMMANDS = "npm publish";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ export const POLL_YES_NO_DESCRIPTION = "Poll? (y)es (n)o: ";
3
4
  export const BUILD_YES_NO_DESCRIPTION = "Build? (y)es (n)o: ";
4
5
  export const FAILED_SCRIPT_DESCRIPTION = "The script has failed. Would you like to try again? (y)es (n)o: ";
5
6
  export const DIRECTORY_PATH_DESCRIPTION = "Directory path: ";
@@ -9,6 +10,7 @@ export const FORCED_DEPENDENT_DESCRIPTION = "Forced dependent sub-directory name
9
10
  export const FORCED_DEPENDENCY_DESCRIPTION = "Forced dependency sub-directory name: ";
10
11
  export const IGNORED_DEPENDENCY_DESCRIPTION = "Ignored dependency sub-directory name: ";
11
12
  export const GIT_SHELL_COMMANDS_DESCRIPTION = "Git shell command(s) (leave blank for default): ";
13
+ export const POLL_SHELL_COMMANDS_DESCRIPTION = "Poll shell command(s) (leave blank for default): ";
12
14
  export const SAVE_UPDATES_YES_NO_DESCRIPTION = "Save updates? (y)es (n)o: ";
13
15
  export const ADD_COMMIT_PUSH_GIT_DESCRIPTION = "Add, commit and push with Git? (y)es (n)o: ";
14
16
  export const BUILD_SHELL_COMMANDS_DESCRIPTION = "Build shell commands() (leave blank for default): ";
package/src/diff.js CHANGED
@@ -67,6 +67,8 @@ export default class Diff {
67
67
 
68
68
  git(quietly, callback) { this.release.git(quietly, callback); }
69
69
 
70
+ poll(names, quietly, callback) { this.release.poll(names, quietly, callback); }
71
+
70
72
  install(quietly, callback) { this.release.install(quietly, callback); }
71
73
 
72
74
  build(quietly, callback) { this.release.build(quietly, callback); }
package/src/messages.js CHANGED
@@ -12,11 +12,12 @@ export const INVALID_FORCED_DEPENDENCY_NAME_MESSAGE = "The dependency name must
12
12
  export const INVALID_IGNORED_DEPENDENCY_NAME_MESSAGE = "The dependency name must be non-empty.";
13
13
  export const INVALID_IGNORED_DEPENDENCY_NUMBER_MESSAGE = "The ignored dependency number should match one of the numbers given above.";
14
14
  export const INVALID_FORCED_DEPENDENCY_RELATION_NUMBER_MESSAGE = "The forced dependency relation number should match one of the numbers given above.";
15
- export const FAILED_GIT_MESSAGE = "The Git script failed.";
15
+ export const FAILED_GIT_MESSAGE = "Git failed.";
16
+ export const FAILED_POLL_MESSAGE = "The polling failed.";
16
17
  export const FAILED_SAVE_MESSAGE = "The 'package.json' file could not be saved.";
17
- export const FAILED_BUILD_MESSAGE = "The build script failed.";
18
- export const FAILED_INSTALL_MESSAGE = "The install script failed.";
19
- export const FAILED_PUBLISH_MESSAGE = "The publish script failed.";
18
+ export const FAILED_BUILD_MESSAGE = "The build failed.";
19
+ export const FAILED_INSTALL_MESSAGE = "The install failed.";
20
+ export const FAILED_PUBLISH_MESSAGE = "The publish failed.";
20
21
  export const FAILED_PROPAGATE_MESSAGE = "Failed to propagate the package.";
21
22
  export const FAILED_INITIALISE_MESSAGE = "Failed to create a configuration file because one is already present.";
22
23
  export const FAILED_ADD_DIRECTORY_MESSAGE = "Failed to add a directory.";
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ import { shellUtilities } from "necessary";
4
+
5
+ import { YES } from "../../constants";
6
+ import { validateAnswer } from "../../utilities/validate";
7
+ import { isAnswerAffirmative } from "../../utilities/prompt";
8
+ import { POLL_YES_NO_DESCRIPTION } from "../../descriptions";
9
+ import { consoleLogUnpublishedDiffs } from "../../utilities/console";
10
+ import { FAILED_POLL_MESSAGE, INVALID_ANSWER_MESSAGE } from "../../messages";
11
+
12
+ const { prompt } = shellUtilities;
13
+
14
+ export default function pollPromptOperation(proceed, abort, context) {
15
+ const { yes, diff, diffs, quietly, releaseMap } = context,
16
+ names = releaseMap.getNames(),
17
+ answer = yes ?
18
+ YES :
19
+ null,
20
+ attempts = Infinity,
21
+ description = POLL_YES_NO_DESCRIPTION,
22
+ errorMessage = INVALID_ANSWER_MESSAGE,
23
+ validationFunction = validateAnswer, ///
24
+ options = {
25
+ answer,
26
+ attempts,
27
+ description,
28
+ errorMessage,
29
+ validationFunction
30
+ };
31
+
32
+ prompt(options, (answer) => {
33
+ const valid = (answer !== null);
34
+
35
+ if (valid) {
36
+ const affirmative = isAnswerAffirmative(answer);
37
+
38
+ if (!affirmative) {
39
+ proceed();
40
+
41
+ return;
42
+ }
43
+
44
+ diff.poll(names, quietly, (success) => {
45
+ if (!success) {
46
+ consoleLogUnpublishedDiffs(diff, diffs);
47
+
48
+ console.log(FAILED_POLL_MESSAGE);
49
+
50
+ abort();
51
+
52
+ return;
53
+ }
54
+
55
+ proceed();
56
+ });
57
+
58
+ return;
59
+ }
60
+
61
+ consoleLogUnpublishedDiffs(diff, diffs);
62
+
63
+ console.log(FAILED_POLL_MESSAGE);
64
+
65
+ abort();
66
+ });
67
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ import { shellUtilities } from "necessary";
4
+
5
+ import { EMPTY_STRING } from "../../constants";
6
+ import { validateShellCommands } from "../../utilities/validate";
7
+ import { DEFAULT_POLL_SHELL_COMMANDS } from "../../defaults";
8
+ import { POLL_SHELL_COMMANDS_DESCRIPTION } from "../../descriptions";
9
+
10
+ const { prompt } = shellUtilities;
11
+
12
+ export default function setPollShellCommandsPromptOperation(proceed, abort, context) {
13
+ const { shellCommands } = context,
14
+ { poll } = shellCommands,
15
+ pollShellCommands = poll, ///
16
+ attempts = Infinity,
17
+ description = POLL_SHELL_COMMANDS_DESCRIPTION,
18
+ initialAnswer = pollShellCommands, ///
19
+ validationFunction = validateShellCommands, ///
20
+ options = {
21
+ attempts,
22
+ description,
23
+ initialAnswer,
24
+ validationFunction
25
+ };
26
+
27
+ prompt(options, (answer) => {
28
+ const pollShellCommands = answer, ///
29
+ poll = (pollShellCommands !== EMPTY_STRING) ?
30
+ pollShellCommands :
31
+ DEFAULT_POLL_SHELL_COMMANDS;
32
+
33
+ Object.assign(shellCommands, {
34
+ poll
35
+ });
36
+
37
+ proceed();
38
+ });
39
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import gitPromptOperation from "../operation/prompt/git";
4
+ import pollPromptOperation from "../operation/prompt/poll";
4
5
  import savePromptOperation from "../operation/prompt/save";
5
6
  import buildPromptOperation from "../operation/prompt/build";
6
7
  import installPromptOperation from "../operation/prompt/install";
@@ -29,12 +30,13 @@ export default function saveAndApplyDiffOperation(diff, proceed, abort, context)
29
30
  });
30
31
 
31
32
  const operations = [
32
- savePromptOperation,
33
- installPromptOperation,
34
- buildPromptOperation,
35
- gitPromptOperation,
36
- publishPromptOperation
37
- ];
33
+ savePromptOperation,
34
+ pollPromptOperation,
35
+ installPromptOperation,
36
+ buildPromptOperation,
37
+ gitPromptOperation,
38
+ publishPromptOperation
39
+ ];
38
40
 
39
41
  console.log(EMPTY_STRING);
40
42
 
package/src/release.js CHANGED
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ import { arrayUtilities, templateUtilities, asynchronousUtilities } from "necessary"
4
+
3
5
  import Version from "./version";
4
6
 
5
- import { execute } from "./utilities/shell";
7
+ import { EMPTY_STRING } from "./constants";
6
8
  import { readPackageJSONFile } from "./utilities/packageJSON";
9
+ import { executePromptly, executeRepeatedly } from "./utilities/shell";
7
10
  import { retrieveShellCommands, retrieveIgnoredBuilds, retrieveIgnoredPublishes } from "./configuration";
8
11
 
12
+ const { eventually } = asynchronousUtilities,
13
+ { parseContent } = templateUtilities,
14
+ { prune, filter } = arrayUtilities;
15
+
9
16
  export default class Release {
10
17
  constructor(name, version, dependencyMap, devDependencyMap, subDirectoryPath) {
11
18
  this.name = name;
@@ -59,17 +66,101 @@ export default class Release {
59
66
  return devDependencyNames;
60
67
  }
61
68
 
69
+ getDependencies(names) {
70
+ const dependencyNames = this.getDependencyNames(),
71
+ devDependencyNames = this.getDevDependencyNames();
72
+
73
+ filter(dependencyNames, (dependencyName) => {
74
+ const namesIncludeDependencyName = names.includes(dependencyName);
75
+
76
+ if (namesIncludeDependencyName) {
77
+ return true;
78
+ }
79
+ });
80
+
81
+ filter(devDependencyNames, (devDependencyName) => {
82
+ const namesIncludeDevDependencyName = names.includes(devDependencyName);
83
+
84
+ if (namesIncludeDevDependencyName) {
85
+ return true;
86
+ }
87
+ });
88
+
89
+ names = [
90
+ ...dependencyNames,
91
+ ...devDependencyNames
92
+ ];
93
+
94
+ const dependencies = names.map((name) => {
95
+ let version = this.dependencyMap[name] || this.devDependencyMap[name];
96
+
97
+ version = version.replace(/[\^~]/g, EMPTY_STRING);
98
+
99
+ const propagatedDependency = `${name}@${version}`;
100
+
101
+ return propagatedDependency;
102
+ });
103
+
104
+ return dependencies;
105
+ }
106
+
62
107
  git(quietly, callback) {
63
108
  let shellCommands = retrieveShellCommands();
64
109
 
65
110
  const { git } = shellCommands,
66
- gitShellCommands = git;
111
+ gitShellCommands = git;
67
112
 
68
113
  shellCommands = gitShellCommands; ///
69
114
 
70
115
  this.executeShellCommands(shellCommands, quietly, callback);
71
116
  }
72
117
 
118
+ poll(names, quietly, callback) {
119
+ const dependencies = this.getDependencies(names),
120
+ dependenciesLength = dependencies.length;
121
+
122
+ if (dependenciesLength === 0) {
123
+ const success = true;
124
+
125
+ callback(success);
126
+
127
+ return;
128
+ }
129
+
130
+ (dependenciesLength === 1) ?
131
+ console.log(`Polling for the dependency:`) :
132
+ console.log(`Polling for the dependenies:`);
133
+
134
+ const operations = dependencies.map((dependency) => {
135
+ return (next, done, context, index) => {
136
+ const shellCommands = shellCommandsFromDependency(dependency);
137
+
138
+ console.log(` - ${dependency} `);
139
+
140
+ executeRepeatedly(shellCommands, quietly, (success) => {
141
+ if (success) {
142
+ const polledDependency = dependency; ///
143
+
144
+ prune(dependencies, (dependency) => {
145
+ if (dependency !== polledDependency) {
146
+ return true;
147
+ }
148
+ });
149
+ }
150
+
151
+ next();
152
+ });
153
+ };
154
+ });
155
+
156
+ eventually(operations, () => {
157
+ const dependenciesLength = dependencies.length,
158
+ success = (dependenciesLength === 0);
159
+
160
+ callback(success);
161
+ });
162
+ }
163
+
73
164
  install(quietly, callback) {
74
165
  let shellCommands = retrieveShellCommands();
75
166
 
@@ -88,7 +179,7 @@ export default class Release {
88
179
  buildIgnored = subDirectoryPathsIncludesSubDirectoryPath; ///
89
180
 
90
181
  if (buildIgnored) {
91
- console.log(`Ignoring the '${this.name}' build.`);
182
+ console.log(`Ignoring the '${this.subDirectoryPath}' build.`);
92
183
 
93
184
  const success = true;
94
185
 
@@ -140,7 +231,7 @@ export default class Release {
140
231
 
141
232
  process.chdir(this.subDirectoryPath);
142
233
 
143
- execute(shellCommands, quietly, (success) => {
234
+ executePromptly(shellCommands, quietly, (success) => {
144
235
  process.chdir(currentWorkingDirectoryPath);
145
236
 
146
237
  callback(success);
@@ -212,3 +303,17 @@ function updateSemver(name, versionString, map) {
212
303
 
213
304
  return success;
214
305
  }
306
+
307
+ function shellCommandsFromDependency(dependency) {
308
+ let shellCommands = retrieveShellCommands();
309
+
310
+ const { poll } = shellCommands,
311
+ pollShellCommands = poll, ///
312
+ args = {
313
+ dependency
314
+ };
315
+
316
+ shellCommands = parseContent(pollShellCommands, args);
317
+
318
+ return shellCommands;
319
+ }
@@ -2,17 +2,19 @@
2
2
 
3
3
  import childProcess from "child_process";
4
4
 
5
- import { encodings, shellUtilities } from "necessary";
5
+ import { encodings, shellUtilities, asynchronousUtilities } from "necessary";
6
6
 
7
7
  import { validateAnswer } from "../utilities/validate";
8
8
  import { isAnswerAffirmative } from "../utilities/prompt";
9
9
  import { INVALID_ANSWER_MESSAGE } from "../messages";
10
10
  import { FAILED_SCRIPT_DESCRIPTION } from "../descriptions";
11
+ import { REPEATED_DELAY, PROMPT_ATTEMPTS, REPEATED_ATTEMPTS } from "../constants";
11
12
 
12
13
  const { prompt } = shellUtilities,
14
+ { whilst } = asynchronousUtilities,
13
15
  { UTF_8_ENCODING } = encodings;
14
16
 
15
- export function execute(shellCommands, quietly, callback) {
17
+ export function executePromptly(shellCommands, quietly, callback) {
16
18
  const success = execSync(shellCommands, quietly);
17
19
 
18
20
  if (success) {
@@ -21,7 +23,7 @@ export function execute(shellCommands, quietly, callback) {
21
23
  return;
22
24
  }
23
25
 
24
- const attempts = Infinity,
26
+ const attempts = PROMPT_ATTEMPTS,
25
27
  description = FAILED_SCRIPT_DESCRIPTION,
26
28
  errorMessage = INVALID_ANSWER_MESSAGE,
27
29
  validationFunction = validateAnswer, ///
@@ -51,6 +53,36 @@ export function execute(shellCommands, quietly, callback) {
51
53
  });
52
54
  }
53
55
 
56
+ export function executeRepeatedly(shellCommands, quietly, callback) {
57
+ let success = false;
58
+
59
+ const delay = REPEATED_DELAY,
60
+ attempts = REPEATED_ATTEMPTS,
61
+ operation = (next, done, context, index) => {
62
+ if (index === attempts) {
63
+ done();
64
+
65
+ return;
66
+ }
67
+
68
+ execAsync(shellCommands, quietly, (error, output) => {
69
+ if (!error) {
70
+ success = true;
71
+
72
+ done();
73
+
74
+ return;
75
+ }
76
+
77
+ setTimeout(next, delay);
78
+ });
79
+ };
80
+
81
+ whilst(operation, () => {
82
+ callback(success);
83
+ });
84
+ }
85
+
54
86
  function execSync(shellCommands, quietly) {
55
87
  let success;
56
88
 
@@ -72,3 +104,22 @@ function execSync(shellCommands, quietly) {
72
104
 
73
105
  return success;
74
106
  }
107
+
108
+ function execAsync(shellCommands, quietly, callback) {
109
+ const encoding = UTF_8_ENCODING, ///
110
+ options = {
111
+ encoding
112
+ };
113
+
114
+ childProcess.exec(shellCommands, options, (error, stdout, stderr) => {
115
+ const output = error ?
116
+ stderr :
117
+ stdout;
118
+
119
+ if (!quietly) {
120
+ process.stdout.write(output);
121
+ }
122
+
123
+ callback(error, output)
124
+ });
125
+ }
package/src/versions.js CHANGED
@@ -5,3 +5,4 @@ export const VERSION_1_3 = "1.3";
5
5
  export const VERSION_1_7 = "1.7";
6
6
  export const VERSION_1_9 = "1.9";
7
7
  export const VERSION_1_10 = "1.10";
8
+ export const VERSION_1_11 = "1.11";