@itentialopensource/adapter-git 0.3.9 → 0.4.0

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.
@@ -1,146 +0,0 @@
1
- #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
3
-
4
- const path = require('path');
5
- const fs = require('fs-extra');
6
-
7
- async function createBundle(adapterOldDir) {
8
- // set directories
9
- const artifactDir = path.join(adapterOldDir, '../artifactTemp');
10
- const workflowsDir = path.join(adapterOldDir, 'workflows');
11
-
12
- // read adapter's package and set names
13
- const adapterPackage = fs.readJSONSync(path.join(adapterOldDir, 'package.json'));
14
- const originalName = adapterPackage.name.substring(adapterPackage.name.lastIndexOf('/') + 1);
15
- const shortenedName = originalName.replace('adapter-', '');
16
- const artifactName = originalName.replace('adapter', 'bundled-adapter');
17
-
18
- const adapterNewDir = path.join(artifactDir, 'bundles', 'adapters', originalName);
19
- fs.ensureDirSync(adapterNewDir);
20
-
21
- const ops = [];
22
-
23
- // copy old adapterDir to bundled hierarchy location
24
- ops.push(() => fs.copySync(adapterOldDir, adapterNewDir));
25
-
26
- // copy readme
27
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'README.md'), path.join(artifactDir, 'README.md')));
28
-
29
- // copy changelog
30
- if (fs.existsSync(path.join(adapterOldDir, 'CHANGELOG.md'))) {
31
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'CHANGELOG.md'), path.join(artifactDir, 'CHANGELOG.md')));
32
- }
33
-
34
- // copy license
35
- if (fs.existsSync(path.join(adapterOldDir, 'LICENSE'))) {
36
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'LICENSE'), path.join(artifactDir, 'LICENSE')));
37
- }
38
-
39
- // create package
40
- const artifactPackage = {
41
- name: artifactName,
42
- version: adapterPackage.version,
43
- description: `A bundled version of the ${originalName} to be used in adapter-artifacts for easy installation`,
44
- scripts: {
45
- test: 'echo "Error: no test specified" && exit 1',
46
- deploy: 'npm publish --registry=http://registry.npmjs.org'
47
- },
48
- keywords: [
49
- 'IAP',
50
- 'artifacts',
51
- 'Itential',
52
- 'Pronghorn',
53
- 'Adapter',
54
- 'Adapter-Artifacts',
55
- shortenedName
56
- ],
57
- author: 'Itential Artifacts',
58
- license: 'Apache-2.0',
59
- repository: adapterPackage.repository,
60
- private: false,
61
- devDependencies: {
62
- r2: '^2.0.1',
63
- ajv: '6.10.0',
64
- 'better-ajv-errors': '^0.6.1',
65
- 'fs-extra': '^7.0.1'
66
- }
67
- };
68
-
69
- ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'package.json'), artifactPackage, { spaces: 2 }));
70
-
71
- // create manifest
72
- const manifest = {
73
- bundleName: originalName,
74
- version: adapterPackage.version,
75
- fingerprint: 'Some verifiable token',
76
- createdEpoch: '1554836984020',
77
- artifacts: [
78
- {
79
- id: `${shortenedName}-adapter`,
80
- name: `${shortenedName}-adapter`,
81
- type: 'adapter',
82
- location: `/bundles/adapters/${originalName}`,
83
- description: artifactPackage.description,
84
- properties: {
85
- entryPoint: false
86
- }
87
- }
88
- ]
89
- };
90
-
91
- // add workflows into artifact
92
- if (fs.existsSync(workflowsDir)) {
93
- const workflowFileNames = fs.readdirSync(workflowsDir);
94
-
95
- // if folder isnt empty and only file is not readme
96
- if (workflowFileNames.length !== 0 && (!(workflowFileNames.length === 1 && workflowFileNames[0].split('.')[1] === 'md'))) {
97
- // add workflows to correct location in bundle
98
- ops.push(() => fs.copySync(workflowsDir, path.join(artifactDir, 'bundles', 'workflows')));
99
-
100
- // add workflows to manifest
101
- workflowFileNames.forEach((filename) => {
102
- const [filenameNoExt, ext] = filename.split('.');
103
- if (ext === 'json') {
104
- manifest.artifacts.push({
105
- id: `workflow-${filenameNoExt}`,
106
- name: filenameNoExt,
107
- type: 'workflow',
108
- location: `/bundles/workflows/${filename}`,
109
- description: 'Main entry point to artifact',
110
- properties: {
111
- entryPoint: false
112
- }
113
- });
114
- }
115
- });
116
- }
117
- }
118
-
119
- ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'manifest.json'), manifest, { spaces: 2 }));
120
-
121
- // Run the commands in parallel
122
- try {
123
- await Promise.all(ops.map(async (op) => op()));
124
- } catch (e) {
125
- throw new Error(e);
126
- }
127
-
128
- const pathObj = {
129
- bundlePath: artifactDir,
130
- bundledAdapterPath: path.join(artifactDir, 'bundles', 'adapters', originalName)
131
- };
132
- return pathObj;
133
- }
134
-
135
- async function artifactize(entryPathToAdapter) {
136
- const truePath = path.resolve(entryPathToAdapter);
137
- const packagePath = path.join(truePath, 'package');
138
- // remove adapter from package and move bundle in
139
- const pathObj = await createBundle(packagePath);
140
- const { bundlePath } = pathObj;
141
- fs.removeSync(packagePath);
142
- fs.moveSync(bundlePath, packagePath);
143
- return 'Bundle successfully created and old folder system removed';
144
- }
145
-
146
- module.exports = { createBundle, artifactize };
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
3
-
4
- const path = require('path');
5
- const { spawnSync } = require('child_process');
6
- const fs = require('fs-extra');
7
- const { createBundle } = require('./artifactize');
8
-
9
- const nodeEntryPath = path.resolve('.');
10
- createBundle(nodeEntryPath).then((pathObj) => {
11
- const { bundlePath, bundledAdapterPath } = pathObj;
12
- const npmIgnorePath = path.join(bundledAdapterPath, '.npmignore');
13
- const adapterPackagePath = path.join(bundledAdapterPath, 'package.json');
14
- const artifactPackagePath = path.join(bundlePath, 'package.json');
15
-
16
- // remove node_modules from .npmIgnore so that node_modules are included in the resulting tar from npm pack
17
- let npmIgnoreString;
18
- if (fs.existsSync(npmIgnorePath)) {
19
- npmIgnoreString = fs.readFileSync(npmIgnorePath, 'utf8');
20
- npmIgnoreString = npmIgnoreString.replace('node_modules', '');
21
- npmIgnoreString = npmIgnoreString.replace('\n\n', '\n');
22
- fs.writeFileSync(npmIgnorePath, npmIgnoreString);
23
- }
24
-
25
- // add files to package so that node_modules are included in the resulting tar from npm pack
26
- const adapterPackage = fs.readJSONSync(adapterPackagePath);
27
- adapterPackage.files = ['*'];
28
- fs.writeJSONSync(artifactPackagePath, adapterPackage, { spaces: 2 });
29
- const npmResult = spawnSync('npm', ['pack', '-q', bundlePath], { cwd: path.resolve(bundlePath, '..') });
30
- if (npmResult.status === 0) {
31
- fs.removeSync(bundlePath);
32
- console.log('Bundle folder removed');
33
- }
34
- console.log('Script successful');
35
- });