sdadfadas

Форк
0
/
release-if-necessary.js 
62 строки · 2.3 Кб
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
const { execSync } = require('child_process');
21
const axios = require('axios');
22
const { name, version } = require('./package.json');
23

24
function log(...args) {
25
  console.log('[embedded-sdk-release]', ...args);
26
}
27

28
function logError(...args) {
29
  console.error('[embedded-sdk-release]', ...args);
30
}
31

32
(async () => {
33
  log(`checking if ${name}@${version} needs releasing`);
34

35
  const packageUrl = `https://registry.npmjs.org/${name}/${version}`;
36
  // npm commands output a bunch of garbage in the edge cases,
37
  // and require sending semi-validated strings to the command line,
38
  // so let's just use good old http.
39
  const { status } = await axios.get(packageUrl, {
40
    validateStatus: (status) => true // we literally just want the status so any status is valid
41
  });
42

43
  if (status === 200) {
44
    log('version already exists on npm, exiting');
45
  } else if (status === 404) {
46
    log('release required, building');
47
    try {
48
      execSync('npm run build', { stdio: 'pipe' });
49
      log('build successful, publishing')
50
      execSync('npm publish --access public', { stdio: 'pipe' });
51
      log(`published ${version} to npm`);
52
    } catch (err) {
53
      console.error(String(err.stdout));
54
      logError('Encountered an error, details should be above');
55
      process.exitCode = 1;
56
    }
57
  } else {
58
    logError(`ERROR: Received unexpected http status code ${status} from GET ${packageUrl}
59
The embedded sdk release script might need to be fixed, or maybe you just need to try again later.`);
60
    process.exitCode = 1;
61
  }
62
})();
63

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.